From 2d540f8cbd4d0de0c369226d9e27675851f6d7e9 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 11 Dec 2023 15:45:13 +0200 Subject: [PATCH] Remove support for using realtime availability in parking routing --- .../common/RequestToPreferencesMapper.java | 6 -- .../api/common/RoutingResource.java | 4 ++ .../org/opentripplanner/model/plan/Place.java | 8 +-- .../preference/VehicleParkingPreferences.java | 28 +-------- .../vehicle_parking/VehicleParking.java | 24 ++------ .../street/model/edge/VehicleParkingEdge.java | 20 ++----- .../VehicleParkingPreferencesTest.java | 9 --- .../model/edge/VehicleParkingEdgeTest.java | 59 +++---------------- 8 files changed, 23 insertions(+), 135 deletions(-) diff --git a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java index 6bcd9490d98..211c0a989cf 100644 --- a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java +++ b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java @@ -168,12 +168,6 @@ private TransitGeneralizedCostFilterParams mapTransitGeneralizedCostFilterParams } private void mapParking(VehicleParkingPreferences.Builder builder) { - setIfNotNull( - req.useVehicleParkingAvailabilityInformation, - useVehicleParkingAvailabilityInformation -> - builder.withIgnoreRealtimeAvailability(!useVehicleParkingAvailabilityInformation) - ); - builder.withRequiredVehicleParkingTags(req.requiredVehicleParkingTags); builder.withBannedVehicleParkingTags(req.bannedVehicleParkingTags); } diff --git a/src/main/java/org/opentripplanner/api/common/RoutingResource.java b/src/main/java/org/opentripplanner/api/common/RoutingResource.java index 143e99d2e93..34f162010bb 100644 --- a/src/main/java/org/opentripplanner/api/common/RoutingResource.java +++ b/src/main/java/org/opentripplanner/api/common/RoutingResource.java @@ -651,6 +651,10 @@ public abstract class RoutingResource { @QueryParam("geoidElevation") protected Boolean geoidElevation; + /** + * @deprecated Support has been removed. + */ + @Deprecated @QueryParam("useVehicleParkingAvailabilityInformation") protected Boolean useVehicleParkingAvailabilityInformation; diff --git a/src/main/java/org/opentripplanner/model/plan/Place.java b/src/main/java/org/opentripplanner/model/plan/Place.java index efdde16899a..fe3a9dee420 100644 --- a/src/main/java/org/opentripplanner/model/plan/Place.java +++ b/src/main/java/org/opentripplanner/model/plan/Place.java @@ -135,11 +135,9 @@ public static Place forVehicleParkingEntrance(VehicleParkingEntranceVertex verte traverseMode = TraverseMode.BICYCLE; } - var parkingPreferences = request.preferences().parking(traverseMode); - - boolean realTime = - !parkingPreferences.ignoreRealtimeAvailability() && - vertex.getVehicleParking().hasRealTimeDataForMode(traverseMode, request.wheelchair()); + boolean realTime = vertex + .getVehicleParking() + .hasRealTimeDataForMode(traverseMode, request.wheelchair()); return new Place( vertex.getName(), WgsCoordinate.creatOptionalCoordinate(vertex.getLat(), vertex.getLon()), diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index 166b5a25c85..c6e97e180a7 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -20,7 +20,6 @@ public final class VehicleParkingPreferences implements Serializable { public static final VehicleParkingPreferences DEFAULT = new VehicleParkingPreferences(); private final Cost unpreferredVehicleParkingTagCost; - private final boolean ignoreRealtimeAvailability; private final VehicleParkingFilter filter; private final VehicleParkingFilter preferred; private final Duration parkTime; @@ -29,7 +28,6 @@ public final class VehicleParkingPreferences implements Serializable { /** Create a new instance with default values. */ private VehicleParkingPreferences() { this.unpreferredVehicleParkingTagCost = Cost.costOfMinutes(5); - this.ignoreRealtimeAvailability = false; this.filter = VehicleParkingFilter.empty(); this.preferred = VehicleParkingFilter.empty(); this.parkTime = Duration.ofMinutes(1); @@ -38,7 +36,6 @@ private VehicleParkingPreferences() { private VehicleParkingPreferences(Builder builder) { this.unpreferredVehicleParkingTagCost = builder.unpreferredVehicleParkingTagCost; - this.ignoreRealtimeAvailability = builder.ignoreRealtimeAvailability; this.filter = new VehicleParkingFilter( builder.bannedVehicleParkingTags, @@ -64,13 +61,6 @@ public Cost unpreferredVehicleParkingTagCost() { return unpreferredVehicleParkingTagCost; } - /** - * Should availability information be used during routing. - */ - public boolean ignoreRealtimeAvailability() { - return ignoreRealtimeAvailability; - } - /** * Parking containing select filters must only be usable and parking containing with not filters * cannot be used. @@ -106,7 +96,6 @@ public boolean equals(Object o) { VehicleParkingPreferences that = (VehicleParkingPreferences) o; return ( Objects.equals(unpreferredVehicleParkingTagCost, that.unpreferredVehicleParkingTagCost) && - ignoreRealtimeAvailability == that.ignoreRealtimeAvailability && Objects.equals(filter, that.filter) && Objects.equals(preferred, that.preferred) && Objects.equals(parkCost, that.parkCost) && @@ -116,14 +105,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash( - unpreferredVehicleParkingTagCost, - ignoreRealtimeAvailability, - filter, - preferred, - parkCost, - parkTime - ); + return Objects.hash(unpreferredVehicleParkingTagCost, filter, preferred, parkCost, parkTime); } @Override @@ -135,7 +117,6 @@ public String toString() { unpreferredVehicleParkingTagCost, DEFAULT.unpreferredVehicleParkingTagCost ) - .addBoolIfTrue("ignoreRealtimeAvailability", ignoreRealtimeAvailability) .addObj("filter", filter, DEFAULT.filter) .addObj("preferred", preferred, DEFAULT.preferred) .addObj("parkCost", parkCost, DEFAULT.parkCost) @@ -147,7 +128,6 @@ public static class Builder { private final VehicleParkingPreferences original; private Cost unpreferredVehicleParkingTagCost; - private boolean ignoreRealtimeAvailability; private List bannedVehicleParkingTags; private List requiredVehicleParkingTags; private List preferredVehicleParkingTags; @@ -158,7 +138,6 @@ public static class Builder { private Builder(VehicleParkingPreferences original) { this.original = original; this.unpreferredVehicleParkingTagCost = original.unpreferredVehicleParkingTagCost; - this.ignoreRealtimeAvailability = original.ignoreRealtimeAvailability; this.bannedVehicleParkingTags = original.filter.not(); this.requiredVehicleParkingTags = original.filter.select(); this.preferredVehicleParkingTags = original.preferred.select(); @@ -172,11 +151,6 @@ public Builder withUnpreferredVehicleParkingTagCost(int cost) { return this; } - public Builder withIgnoreRealtimeAvailability(boolean ignoreRealtimeAvailability) { - this.ignoreRealtimeAvailability = ignoreRealtimeAvailability; - return this; - } - public Builder withBannedVehicleParkingTags(Set bannedVehicleParkingTags) { this.bannedVehicleParkingTags = List.of(new VehicleParkingSelect.TagsSelect(bannedVehicleParkingTags)); diff --git a/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java b/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java index b4a8eee17b3..e5b0fd083dc 100644 --- a/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java +++ b/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java @@ -215,31 +215,15 @@ public boolean hasRealTimeData() { return availability != null; } - public boolean hasSpacesAvailable( - TraverseMode traverseMode, - boolean wheelchairAccessible, - boolean ignoreRealtimeAvailability - ) { + public boolean hasSpacesAvailable(TraverseMode traverseMode, boolean wheelchairAccessible) { switch (traverseMode) { case BICYCLE: - if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.BICYCLE, false)) { - return availability.getBicycleSpaces() > 0; - } else { - return bicyclePlaces; - } + return bicyclePlaces; case CAR: if (wheelchairAccessible) { - if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.CAR, true)) { - return availability.getWheelchairAccessibleCarSpaces() > 0; - } else { - return wheelchairAccessibleCarPlaces; - } + return wheelchairAccessibleCarPlaces; } else { - if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.CAR, false)) { - return availability.getCarSpaces() > 0; - } else { - return carPlaces; - } + return carPlaces; } default: return false; diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index 6178541656f..be909c1dc4c 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -120,14 +120,7 @@ private State[] traverseUnPark( TraverseMode mode ) { final StreetSearchRequest request = s0.getRequest(); - var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); - if ( - !vehicleParking.hasSpacesAvailable( - mode, - request.wheelchair(), - parkingPreferences.ignoreRealtimeAvailability() - ) - ) { + if (!vehicleParking.hasSpacesAvailable(mode, request.wheelchair())) { return State.empty(); } @@ -136,6 +129,7 @@ private State[] traverseUnPark( s0e.incrementTimeInSeconds((int) parkingTime.toSeconds()); s0e.setVehicleParked(false, mode); + var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); addUnpreferredTagCost(parkingPreferences, s0e); return s0e.makeStateArray(); @@ -172,14 +166,7 @@ private State[] traversePark(State s0) { } private State[] traversePark(State s0, Cost parkingCost, Duration parkingTime) { - var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); - if ( - !vehicleParking.hasSpacesAvailable( - s0.currentMode(), - s0.getRequest().wheelchair(), - parkingPreferences.ignoreRealtimeAvailability() - ) - ) { + if (!vehicleParking.hasSpacesAvailable(s0.currentMode(), s0.getRequest().wheelchair())) { return State.empty(); } @@ -188,6 +175,7 @@ private State[] traversePark(State s0, Cost parkingCost, Duration parkingTime) { s0e.incrementTimeInSeconds((int) parkingTime.toSeconds()); s0e.setVehicleParked(true, TraverseMode.WALK); + var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); addUnpreferredTagCost(parkingPreferences, s0e); return s0e.makeStateArray(); diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index 0337f5eea3b..85ce30b8561 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -14,7 +14,6 @@ class VehicleParkingPreferencesTest { private static final Set PREFERRED_TAGS = Set.of("foo"); private static final Set NOT_PREFERRED_TAGS = Set.of("bar"); private static final int UNPREFERRED_COST = 360; - private static final boolean IGNORE_REALTIME = true; private static final Set REQUIRED_TAGS = Set.of("bar"); private static final Set BANNED_TAGS = Set.of("not"); private static final Cost PARKING_COST = Cost.costOfMinutes(4); @@ -39,11 +38,6 @@ void unpreferredCost() { assertEquals(UNPREFERRED_COST, subject.unpreferredVehicleParkingTagCost().toSeconds()); } - @Test - void useAvailabilityInformation() { - assertEquals(IGNORE_REALTIME, subject.ignoreRealtimeAvailability()); - } - @Test void parkCost() { assertEquals(PARKING_COST, subject.parkCost()); @@ -65,7 +59,6 @@ void testEqualsAndHashCode() { .withPreferredVehicleParkingTags(Set.of()) .withNotPreferredVehicleParkingTags(Set.of()) .withUnpreferredVehicleParkingTagCost(0) - .withIgnoreRealtimeAvailability(false) .withRequiredVehicleParkingTags(Set.of()) .withBannedVehicleParkingTags(Set.of()) .withParkCost(0) @@ -81,7 +74,6 @@ void testToString() { assertEquals( "VehicleParkingPreferences{" + "unpreferredVehicleParkingTagCost: $360, " + - "ignoreRealtimeAvailability, " + "filter: VehicleParkingFilter{not: [tags=[not]], select: [tags=[bar]]}, " + "preferred: VehicleParkingFilter{not: [tags=[bar]], select: [tags=[foo]]}, " + "parkCost: $240, " + @@ -100,7 +92,6 @@ private VehicleParkingPreferences createPreferences() { .withPreferredVehicleParkingTags(PREFERRED_TAGS) .withNotPreferredVehicleParkingTags(NOT_PREFERRED_TAGS) .withUnpreferredVehicleParkingTagCost(UNPREFERRED_COST) - .withIgnoreRealtimeAvailability(IGNORE_REALTIME) .withRequiredVehicleParkingTags(REQUIRED_TAGS) .withBannedVehicleParkingTags(BANNED_TAGS) .withParkCost(PARKING_COST.toSeconds()) diff --git a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java index 919f141a1be..7dad61fbd6b 100644 --- a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java +++ b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java @@ -45,8 +45,7 @@ public void realtimeAvailableCarPlacesTest() { StreetMode.CAR_TO_PARK, false, true, - VehicleParkingSpaces.builder().carSpaces(1).build(), - false + VehicleParkingSpaces.builder().carSpaces(1).build() ); var s1 = traverse(); @@ -56,28 +55,13 @@ public void realtimeAvailableCarPlacesTest() { @Test public void realtimeAvailableCarPlacesFallbackTest() { - initEdgeAndRequest(StreetMode.CAR_TO_PARK, false, true, null, false); + initEdgeAndRequest(StreetMode.CAR_TO_PARK, false, true, null); var s1 = traverse(); assertFalse(State.isEmpty(s1)); } - @Test - public void realtimeNotAvailableCarPlacesTest() { - initEdgeAndRequest( - StreetMode.CAR_TO_PARK, - false, - true, - VehicleParkingSpaces.builder().carSpaces(0).build(), - false - ); - - var s1 = traverse(); - - assertTrue(State.isEmpty(s1)); - } - @Test public void availableBicyclePlacesTest() { initEdgeAndRequest(StreetMode.BIKE_TO_PARK, true, false); @@ -102,8 +86,7 @@ public void realtimeAvailableBicyclePlacesTest() { StreetMode.BIKE_TO_PARK, true, false, - VehicleParkingSpaces.builder().bicycleSpaces(1).build(), - false + VehicleParkingSpaces.builder().bicycleSpaces(1).build() ); var s1 = traverse(); @@ -113,61 +96,33 @@ public void realtimeAvailableBicyclePlacesTest() { @Test public void realtimeAvailableBicyclePlacesFallbackTest() { - initEdgeAndRequest(StreetMode.BIKE_TO_PARK, true, false, null, false); + initEdgeAndRequest(StreetMode.BIKE_TO_PARK, true, false, null); var s1 = traverse(); assertFalse(State.isEmpty(s1)); } - @Test - public void realtimeNotAvailableBicyclePlacesTest() { - initEdgeAndRequest( - StreetMode.BIKE_TO_PARK, - true, - false, - VehicleParkingSpaces.builder().bicycleSpaces(0).build(), - false - ); - - var s1 = traverse(); - - assertTrue(State.isEmpty(s1)); - } - private void initEdgeAndRequest( StreetMode parkingMode, boolean bicyclePlaces, boolean carPlaces ) { - initEdgeAndRequest(parkingMode, bicyclePlaces, carPlaces, null, true); + initEdgeAndRequest(parkingMode, bicyclePlaces, carPlaces, null); } private void initEdgeAndRequest( StreetMode parkingMode, boolean bicyclePlaces, boolean carPlaces, - VehicleParkingSpaces availability, - boolean ignoreRealtime + VehicleParkingSpaces availability ) { var vehicleParking = createVehicleParking(bicyclePlaces, carPlaces, availability); this.vertex = new VehicleParkingEntranceVertex(vehicleParking.getEntrances().get(0)); vehicleParkingEdge = VehicleParkingEdge.createVehicleParkingEdge(vertex); - this.request = - StreetSearchRequest - .of() - .withMode(parkingMode) - .withPreferences(preferences -> { - preferences.withBike(bike -> - bike.withParking(parking -> parking.withIgnoreRealtimeAvailability(ignoreRealtime)) - ); - preferences.withCar(car -> - car.withParking(parking -> parking.withIgnoreRealtimeAvailability(ignoreRealtime)) - ); - }) - .build(); + this.request = StreetSearchRequest.of().withMode(parkingMode).build(); } private VehicleParking createVehicleParking(