Skip to content

Commit

Permalink
Merge pull request #5582 from HSLdevcom/route-request-refactor
Browse files Browse the repository at this point in the history
Restructure walk/bicycle/car preferences in router-config.json
  • Loading branch information
optionsome authored Jan 18, 2024
2 parents 88955a7 + ed51e52 commit c8a6b86
Show file tree
Hide file tree
Showing 57 changed files with 1,406 additions and 890 deletions.
450 changes: 295 additions & 155 deletions docs/RouteRequest.md

Large diffs are not rendered by default.

65 changes: 44 additions & 21 deletions docs/RouterConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,34 +451,59 @@ Used to group requests when monitoring OTP.
]
},
"routingDefaults" : {
"walkSpeed" : 1.3,
"bikeSpeed" : 5,
"carSpeed" : 40,
"numItineraries" : 12,
"transferPenalty" : 0,
"walkReluctance" : 4.0,
"bikeReluctance" : 5.0,
"bikeWalkingReluctance" : 10.0,
"bikeStairsReluctance" : 150.0,
"carReluctance" : 10.0,
"stairsReluctance" : 1.65,
"turnReluctance" : 1.0,
"elevatorBoardTime" : 90,
"elevatorBoardCost" : 90,
"elevatorHopTime" : 20,
"elevatorHopCost" : 20,
"escalatorReluctance" : 1.5,
"vehicleRental" : {
"pickupCost" : 120,
"dropOffTime" : 30,
"dropOffCost" : 30
"bicycle" : {
"speed" : 5,
"reluctance" : 5.0,
"boardCost" : 600,
"walk" : {
"reluctance" : 10.0,
"stairsReluctance" : 150.0
},
"rental" : {
"pickupCost" : 120,
"dropOffTime" : "30s",
"dropOffCost" : 30
},
"parking" : {
"time" : "1m",
"cost" : 120
},
"triangle" : {
"safety" : 0.4,
"flatness" : 0.3,
"time" : 0.3
}
},
"car" : {
"speed" : 40,
"reluctance" : 10,
"decelerationSpeed" : 2.9,
"accelerationSpeed" : 2.9,
"rental" : {
"pickupCost" : 120,
"dropOffTime" : "30s",
"dropOffCost" : 30
},
"parking" : {
"time" : "5m",
"cost" : 600
}
},
"walk" : {
"speed" : 1.3,
"reluctance" : 4.0,
"stairsReluctance" : 1.65,
"boardCost" : 600,
"escalatorReluctance" : 1.5
},
"bikeParkTime" : "1m",
"bikeParkCost" : 120,
"carDropoffTime" : 120,
"waitReluctance" : 1.0,
"walkBoardCost" : 600,
"bikeBoardCost" : 600,
"otherThanPreferredRoutesPenalty" : 300,
"transferSlack" : 120,
"boardSlackForMode" : {
Expand Down Expand Up @@ -515,8 +540,6 @@ Used to group requests when monitoring OTP.
"minBikeParkingDistance" : 300,
"debug" : "limit-to-search-window"
},
"carDecelerationSpeed" : 2.9,
"carAccelerationSpeed" : 2.9,
"ignoreRealtimeUpdates" : false,
"geoidElevation" : false,
"maxJourneyDuration" : "36h",
Expand Down
54 changes: 34 additions & 20 deletions docs/examples/entur/router-config.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
{
"configVersion" : "{{ Entur CI config build number inserted here }}",
"routingDefaults": {
"walkSpeed": 1.3,
"bikeSpeed": 5,
"carSpeed": 40,
"numItineraries": 12,
"transferPenalty": 0,
"walkReluctance": 4.0,
"bikeReluctance": 5.0,
"bikeWalkingReluctance": 10.0,
"carReluctance": 10.0,
"stairsReluctance": 1.65,
"turnReluctance": 1.0,
"elevatorBoardTime": 90,
"elevatorBoardCost": 90,
"elevatorHopTime": 20,
"elevatorHopCost": 20,
"vehicleRental": {
"pickupCost": 120,
"dropOffTime": 30,
"dropOffCost": 30
"bicycle": {
"speed": 5,
"reluctance": 5.0,
"boardCost": 600,
"walk": {
"reluctance": 10.0
},
"rental": {
"pickupCost": 120,
"dropOffTime": "30s",
"dropOffCost": 30
},
"parking": {
"time": "1m",
"cost": 120
}
},
"car": {
"speed": 40,
"reluctance": 4.0,
"decelerationSpeed": 2.9,
"accelerationSpeed": 2.9,
"rental": {
"pickupCost": 120,
"dropOffTime": "30s",
"dropOffCost": 30
}
},
"walk": {
"speed": 1.3,
"reluctance": 4.0,
"stairsReluctance": 1.65,
"boardCost": 600
},
"bikeParkTime": "1m",
"bikeParkCost": 120,
"carDropoffTime": 120,
"waitReluctance": 1.0,
"walkBoardCost": 600,
"bikeBoardCost": 600,
"otherThanPreferredRoutesPenalty": 300,
"transferSlack": 120,
// Default slack for any mode is 0 (zero)
Expand All @@ -41,15 +57,13 @@
},
"accessEgress": {
"maxDurationForMode": {
"BIKE_RENTAL": "20m"
"BIKE_RENTAL": "20m"
}
},
"itineraryFilters" : {
"transitGeneralizedCostLimit" : "1h + 2.5 x",
"bikeRentalDistanceRatio": 0.3
},
"carDecelerationSpeed": 2.9,
"carAccelerationSpeed": 2.9,
"ignoreRealtimeUpdates": false,
"geoidElevation": false,
"maxJourneyDuration": "36h",
Expand Down
24 changes: 17 additions & 7 deletions docs/examples/ibi/atlanta/router-config.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
{
"routingDefaults": {
"bikeTriangleSafetyFactor": 0.4,
"bikeTriangleSlopeFactor": 0.3,
"bikeTriangleTimeFactor": 0.3,
"bicycle": {
"triangle": {
"time": 0.3,
"flatness": 0.3,
"safety": 0.4
},
"rental": {
"pickupTime": "3m",
"pickupCost": 850
}
},
"car": {
"rental": {
"pickupTime": "3m",
"pickupCost": 850
}
},
"itineraryFilters": {
// only show non-transit (ie. walking) when it's at least as good as the transit option
"nonTransitGeneralizedCostLimit": "0 + 1.0 x",
// add IBI accessibility score between 0 and 1
"accessibilityScore": true
},
"vehicleRental": {
"pickupTime": 180,
"pickupCost": 850
},
// use stop and trip with unknown wheelchair accessibility during routing
"wheelchairAccessibility": {
"trip": {
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/ibi/portland/router-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"alightSlack": "0s",
"transferSlack": 180,
"waitReluctance": 0.9,
"walkReluctance": 1.75,
"stairsReluctance": 1.65,
"walk": {
"reluctance": 1.75,
"stairsReluctance": 1.65
},
"numItineraries": 3,
"geoidElevation": true,
"streetRoutingTimeout": "7s"
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/skanetrafiken/router-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
},
"transferSlack": 180,
"waitReluctance": 0.175,
"walkReluctance": 5,
"walk": {
"reluctance": 5
},
"maxDirectStreetDuration": "3700s"
},
"transit": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.opentripplanner.ext.restapi.mapping;

import org.opentripplanner.routing.core.BicycleOptimizeType;

/**
* Bicycle optimization types that are only meant to be used by the REST API. Related to {@link org.opentripplanner.routing.core.BicycleOptimizeType}
*/
public enum LegacyBicycleOptimizeType {
QUICK,
SAFE,
FLAT,
GREENWAYS,
TRIANGLE;

public static BicycleOptimizeType map(LegacyBicycleOptimizeType type) {
return switch (type) {
case QUICK -> BicycleOptimizeType.SHORTEST_DURATION;
case FLAT -> BicycleOptimizeType.FLAT_STREETS;
case SAFE -> BicycleOptimizeType.SAFE_STREETS;
case GREENWAYS -> BicycleOptimizeType.SAFEST_STREETS;
case TRIANGLE -> BicycleOptimizeType.TRIANGLE;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.validation.constraints.NotNull;
import java.util.function.Consumer;
import org.opentripplanner.ext.restapi.mapping.LegacyBicycleOptimizeType;
import org.opentripplanner.framework.lang.ObjectUtils;
import org.opentripplanner.routing.algorithm.filterchain.api.TransitGeneralizedCostFilterParams;
import org.opentripplanner.routing.api.request.framework.CostLinearFunction;
Expand All @@ -10,7 +11,6 @@
import org.opentripplanner.routing.api.request.preference.RoutingPreferences;
import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences;
import org.opentripplanner.routing.api.request.preference.VehicleRentalPreferences;
import org.opentripplanner.routing.core.BicycleOptimizeType;

class RequestToPreferencesMapper {

Expand Down Expand Up @@ -46,8 +46,8 @@ private void mapCar() {
setIfNotNull(req.carReluctance, car::withReluctance);
car.withParking(parking -> {
mapParking(parking);
setIfNotNull(req.carParkCost, parking::withParkCost);
setIfNotNull(req.carParkTime, parking::withParkTime);
setIfNotNull(req.carParkCost, parking::withCost);
setIfNotNull(req.carParkTime, parking::withTime);
});
car.withRental(this::mapRental);
});
Expand All @@ -67,13 +67,12 @@ private void mapBike() {
setIfNotNull(req.bikeSpeed, bike::withSpeed);
setIfNotNull(req.bikeReluctance, bike::withReluctance);
setIfNotNull(req.bikeBoardCost, bike::withBoardCost);
setIfNotNull(req.bikeWalkingSpeed, bike::withWalkingSpeed);
setIfNotNull(req.bikeWalkingReluctance, bike::withWalkingReluctance);
setIfNotNull(req.bikeSwitchTime, bike::withSwitchTime);
setIfNotNull(req.bikeSwitchCost, bike::withSwitchCost);
setIfNotNull(req.bikeOptimizeType, bike::withOptimizeType);
setIfNotNull(
req.bikeOptimizeType,
optimizeType -> bike.withOptimizeType(LegacyBicycleOptimizeType.map(optimizeType))
);

if (req.bikeOptimizeType == BicycleOptimizeType.TRIANGLE) {
if (req.bikeOptimizeType == LegacyBicycleOptimizeType.TRIANGLE) {
bike.withOptimizeTriangle(triangle -> {
setIfNotNull(req.triangleTimeFactor, triangle::withTime);
setIfNotNull(req.triangleSlopeFactor, triangle::withSlope);
Expand All @@ -83,10 +82,16 @@ private void mapBike() {

bike.withParking(parking -> {
mapParking(parking);
setIfNotNull(req.bikeParkCost, parking::withParkCost);
setIfNotNull(req.bikeParkTime, parking::withParkTime);
setIfNotNull(req.bikeParkCost, parking::withCost);
setIfNotNull(req.bikeParkTime, parking::withTime);
});
bike.withRental(this::mapRental);
bike.withWalking(walk -> {
setIfNotNull(req.bikeWalkingSpeed, walk::withSpeed);
setIfNotNull(req.bikeWalkingReluctance, walk::withReluctance);
setIfNotNull(req.bikeSwitchTime, walk::withHopTime);
setIfNotNull(req.bikeSwitchCost, walk::withHopCost);
});
});
}

Expand Down Expand Up @@ -143,7 +148,7 @@ private void mapRental(VehicleRentalPreferences.Builder rental) {

setIfNotNull(
req.keepingRentedBicycleAtDestinationCost,
rental::withArrivingInRentalVehicleAtDestinationCost
cost -> rental.withArrivingInRentalVehicleAtDestinationCost((int) Math.round(cost))
);
rental.withUseAvailabilityInformation(isPlannedForNow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.xml.datatype.XMLGregorianCalendar;
import org.opentripplanner.api.parameter.QualifiedModeSet;
import org.opentripplanner.ext.dataoverlay.api.DataOverlayParameters;
import org.opentripplanner.ext.restapi.mapping.LegacyBicycleOptimizeType;
import org.opentripplanner.framework.application.OTPFeature;
import org.opentripplanner.framework.lang.StringUtils;
import org.opentripplanner.framework.time.DurationUtils;
Expand All @@ -28,7 +29,6 @@
import org.opentripplanner.routing.api.request.preference.ItineraryFilterDebugProfile;
import org.opentripplanner.routing.api.request.request.filter.SelectRequest;
import org.opentripplanner.routing.api.request.request.filter.TransitFilterRequest;
import org.opentripplanner.routing.core.BicycleOptimizeType;
import org.opentripplanner.standalone.api.OtpServerRequestContext;
import org.opentripplanner.standalone.config.framework.file.ConfigFileLoader;
import org.opentripplanner.standalone.config.framework.json.NodeAdapter;
Expand Down Expand Up @@ -249,7 +249,7 @@ public abstract class RoutingResource {
*/
@Deprecated
@QueryParam("optimize")
protected BicycleOptimizeType bikeOptimizeType;
protected LegacyBicycleOptimizeType bikeOptimizeType;

/**
* The set of modes that a user is willing to use, with qualifiers stating whether vehicles should
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.opentripplanner.apis.gtfs.mapping;

import javax.annotation.Nonnull;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.routing.core.BicycleOptimizeType;

public final class OptimizationTypeMapper {

@Nonnull
public static BicycleOptimizeType map(GraphQLTypes.GraphQLOptimizeType optimizeType) {
return switch (optimizeType) {
case QUICK -> BicycleOptimizeType.SHORTEST_DURATION;
case FLAT -> BicycleOptimizeType.FLAT_STREETS;
case SAFE -> BicycleOptimizeType.SAFE_STREETS;
case GREENWAYS -> BicycleOptimizeType.SAFEST_STREETS;
case TRIANGLE -> BicycleOptimizeType.TRIANGLE;
};
}
}
Loading

0 comments on commit c8a6b86

Please sign in to comment.