Skip to content

Commit

Permalink
Remove support for using realtime availability in parking routing
Browse files Browse the repository at this point in the history
  • Loading branch information
optionsome committed Dec 11, 2023
1 parent 9569d93 commit 2d540f8
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,10 @@ public abstract class RoutingResource {
@QueryParam("geoidElevation")
protected Boolean geoidElevation;

/**
* @deprecated Support has been removed.
*/
@Deprecated
@QueryParam("useVehicleParkingAvailabilityInformation")
protected Boolean useVehicleParkingAvailabilityInformation;

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/opentripplanner/model/plan/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -38,7 +36,6 @@ private VehicleParkingPreferences() {

private VehicleParkingPreferences(Builder builder) {
this.unpreferredVehicleParkingTagCost = builder.unpreferredVehicleParkingTagCost;
this.ignoreRealtimeAvailability = builder.ignoreRealtimeAvailability;
this.filter =
new VehicleParkingFilter(
builder.bannedVehicleParkingTags,
Expand All @@ -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.
Expand Down Expand Up @@ -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) &&
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -147,7 +128,6 @@ public static class Builder {

private final VehicleParkingPreferences original;
private Cost unpreferredVehicleParkingTagCost;
private boolean ignoreRealtimeAvailability;
private List<VehicleParkingSelect> bannedVehicleParkingTags;
private List<VehicleParkingSelect> requiredVehicleParkingTags;
private List<VehicleParkingSelect> preferredVehicleParkingTags;
Expand All @@ -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();
Expand All @@ -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<String> bannedVehicleParkingTags) {
this.bannedVehicleParkingTags =
List.of(new VehicleParkingSelect.TagsSelect(bannedVehicleParkingTags));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class VehicleParkingPreferencesTest {
private static final Set<String> PREFERRED_TAGS = Set.of("foo");
private static final Set<String> NOT_PREFERRED_TAGS = Set.of("bar");
private static final int UNPREFERRED_COST = 360;
private static final boolean IGNORE_REALTIME = true;
private static final Set<String> REQUIRED_TAGS = Set.of("bar");
private static final Set<String> BANNED_TAGS = Set.of("not");
private static final Cost PARKING_COST = Cost.costOfMinutes(4);
Expand All @@ -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());
Expand All @@ -65,7 +59,6 @@ void testEqualsAndHashCode() {
.withPreferredVehicleParkingTags(Set.of())
.withNotPreferredVehicleParkingTags(Set.of())
.withUnpreferredVehicleParkingTagCost(0)
.withIgnoreRealtimeAvailability(false)
.withRequiredVehicleParkingTags(Set.of())
.withBannedVehicleParkingTags(Set.of())
.withParkCost(0)
Expand All @@ -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, " +
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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(
Expand Down

0 comments on commit 2d540f8

Please sign in to comment.