use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestParkAndRide method testCar.
public void testCar() throws Exception {
AStar aStar = new AStar();
// It is impossible to get from A to C in WALK mode,
RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
options.setRoutingContext(graph, A, C);
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(C, false);
assertNull(path);
// or CAR+WALK (no P+R).
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR));
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// So we Add a P+R at B.
ParkAndRideVertex PRB = new ParkAndRideVertex(graph, "P+R", "P+R.B", 0.001, 45.00001, new NonLocalizedString("P+R B"));
new ParkAndRideEdge(PRB);
new ParkAndRideLinkEdge(PRB, B);
new ParkAndRideLinkEdge(B, PRB);
// But it is still impossible to get from A to C by WALK only
// (AB is CAR only).
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// Or CAR only (BC is WALK only).
options = new RoutingRequest(new TraverseModeSet(TraverseMode.CAR));
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy false
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
options.parkAndRide = true;
// options.arriveBy
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy true
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
options.parkAndRide = true;
options.setArriveBy(true);
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(A, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy true interleavedBidiHeuristic
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
options.parkAndRide = true;
options.setArriveBy(true);
options.setRoutingContext(graph, A, C);
options.rctx.remainingWeightHeuristic = new EuclideanRemainingWeightHeuristic();
tree = aStar.getShortestPathTree(options);
path = tree.getPath(A, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy false interleavedBidiHeuristic
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
options.parkAndRide = true;
// options.arriveBy
options.setRoutingContext(graph, A, C);
options.rctx.remainingWeightHeuristic = new EuclideanRemainingWeightHeuristic();
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNotNull(path);
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestParkAndRide method testBike.
public void testBike() throws Exception {
AStar aStar = new AStar();
// Impossible to get from B to D in BIKE+WALK (no bike P+R).
RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE, TraverseMode.TRANSIT));
options.bikeParkAndRide = true;
options.freezeTraverseMode();
options.setRoutingContext(graph, B, D);
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(D, false);
assertNull(path);
// So we add a bike P+R at C.
BikePark bpc = new BikePark();
bpc.id = "bpc";
bpc.name = "Bike Park C";
bpc.x = 0.002;
bpc.y = 45.00001;
bpc.spacesAvailable = 1;
BikeParkVertex BPRC = new BikeParkVertex(graph, bpc);
new BikeParkEdge(BPRC);
new StreetBikeParkLink(BPRC, C);
new StreetBikeParkLink(C, BPRC);
// Still impossible from B to D by bike only (CD is WALK only).
options = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
options.setRoutingContext(graph, B, D);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(D, false);
assertNotNull(path);
State s = tree.getState(D);
assertFalse(s.isBikeParked());
// TODO backWalkingBike flag is broken
// assertTrue(s.isBackWalkingBike());
assertTrue(s.getBackMode() == TraverseMode.WALK);
// But we can go from B to D using bike P+R.
options = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE, TraverseMode.WALK, TraverseMode.TRANSIT));
options.bikeParkAndRide = true;
options.setRoutingContext(graph, B, D);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(D, false);
assertNotNull(path);
s = tree.getState(D);
assertTrue(s.isBikeParked());
assertFalse(s.isBackWalkingBike());
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TransmodelGraphQLPlanner method createRequest.
private RoutingRequest createRequest(DataFetchingEnvironment environment) throws ParameterException {
TransmodelRequestContext context = environment.getContext();
Router router = context.getRouter();
RoutingRequest request = router.defaultRoutingRequest.clone();
DataFetcherDecorator callWith = new DataFetcherDecorator(environment);
callWith.argument("locale", (String v) -> request.locale = Locale.forLanguageTag(v));
callWith.argument("from", (Map<String, Object> v) -> request.from = toGenericLocation(v));
callWith.argument("to", (Map<String, Object> v) -> request.to = toGenericLocation(v));
callWith.argument("dateTime", millisSinceEpoch -> request.setDateTime(Instant.ofEpochMilli((long) millisSinceEpoch)), Date::new);
callWith.argument("searchWindow", (Integer m) -> request.searchWindow = Duration.ofMinutes(m));
callWith.argument("pageCursor", request::setPageCursor);
callWith.argument("timetableView", (Boolean v) -> request.timetableView = v);
callWith.argument("wheelchair", request::setWheelchairAccessible);
callWith.argument("numTripPatterns", request::setNumItineraries);
callWith.argument("transitGeneralizedCostLimit", (DoubleFunction<Double> it) -> request.itineraryFilters.transitGeneralizedCostLimit = it);
// callWith.argument("maxTransferWalkDistance", request::setMaxTransferWalkDistance);
// callWith.argument("preTransitReluctance", (Double v) -> request.setPreTransitReluctance(v));
// callWith.argument("maxPreTransitWalkDistance", (Double v) -> request.setMaxPreTransitWalkDistance(v));
callWith.argument("walkBoardCost", request::setWalkBoardCost);
callWith.argument("walkReluctance", request::setNonTransitReluctance);
callWith.argument("waitReluctance", request::setWaitReluctance);
callWith.argument("walkBoardCost", request::setWalkBoardCost);
// callWith.argument("walkOnStreetReluctance", request::setWalkOnStreetReluctance);
callWith.argument("waitReluctance", request::setWaitReluctance);
callWith.argument("waitAtBeginningFactor", request::setWaitAtBeginningFactor);
callWith.argument("walkSpeed", (Double v) -> request.walkSpeed = v);
callWith.argument("bikeSpeed", (Double v) -> request.bikeSpeed = v);
callWith.argument("bikeSwitchTime", (Integer v) -> request.bikeSwitchTime = v);
callWith.argument("bikeSwitchCost", (Integer v) -> request.bikeSwitchCost = v);
// callWith.argument("transitDistanceReluctance", (Double v) -> request.transitDistanceReluctance = v);
BicycleOptimizeType bicycleOptimizeType = environment.getArgument("bicycleOptimisationMethod");
if (bicycleOptimizeType == BicycleOptimizeType.TRIANGLE) {
// Arguments: [ safety, slope, time ]
final double[] args = new double[3];
callWith.argument("triangleFactors.safety", (Double v) -> args[0] = v);
callWith.argument("triangleFactors.slope", (Double v) -> args[1] = v);
callWith.argument("triangleFactors.time", (Double v) -> args[2] = v);
request.setTriangleNormalized(args[0], args[1], args[2]);
}
if (bicycleOptimizeType == BicycleOptimizeType.TRANSFERS) {
bicycleOptimizeType = BicycleOptimizeType.QUICK;
request.transferCost += 1800;
}
if (bicycleOptimizeType != null) {
request.bicycleOptimizeType = bicycleOptimizeType;
}
callWith.argument("arriveBy", request::setArriveBy);
request.showIntermediateStops = true;
callWith.argument("vias", (List<Map<String, Object>> v) -> request.intermediatePlaces = v.stream().map(this::toGenericLocation).collect(Collectors.toList()));
callWith.argument("preferred.authorities", (Collection<String> authorities) -> request.setPreferredAgencies(mapIDsToDomain(authorities)));
callWith.argument("unpreferred.authorities", (Collection<String> authorities) -> request.setUnpreferredAgencies(mapIDsToDomain(authorities)));
callWith.argument("whiteListed.authorities", (Collection<String> authorities) -> request.setWhiteListedAgencies(mapIDsToDomain(authorities)));
callWith.argument("banned.authorities", (Collection<String> authorities) -> request.setBannedAgencies(mapIDsToDomain(authorities)));
callWith.argument("preferred.otherThanPreferredLinesPenalty", request::setOtherThanPreferredRoutesPenalty);
callWith.argument("preferred.lines", (List<String> lines) -> request.setPreferredRoutes(mapIDsToDomain(lines)));
callWith.argument("unpreferred.lines", (List<String> lines) -> request.setUnpreferredRoutes(mapIDsToDomain(lines)));
callWith.argument("whiteListed.lines", (List<String> lines) -> request.setWhiteListedRoutes(mapIDsToDomain(lines)));
callWith.argument("banned.lines", (List<String> lines) -> request.setBannedRoutes(mapIDsToDomain(lines)));
callWith.argument("banned.serviceJourneys", (Collection<String> serviceJourneys) -> request.bannedTrips = toBannedTrips(serviceJourneys));
// callWith.argument("banned.quays", quays -> request.setBannedStops(mappingUtil.prepareListOfFeedScopedId((List<String>) quays)));
// callWith.argument("banned.quaysHard", quaysHard -> request.setBannedStopsHard(mappingUtil.prepareListOfFeedScopedId((List<String>) quaysHard)));
// callWith.argument("heuristicStepsPerMainStep", (Integer v) -> request.heuristicStepsPerMainStep = v);
// callWith.argument("compactLegsByReversedSearch", (Boolean v) -> { /* not used any more */ });
// callWith.argument("banFirstServiceJourneysFromReuseNo", (Integer v) -> request.banFirstTripsFromReuseNo = v);
callWith.argument("debugItineraryFilter", (Boolean v) -> request.itineraryFilters.debug = v);
callWith.argument("transferPenalty", (Integer v) -> request.transferCost = v);
// callWith.argument("useFlex", (Boolean v) -> request.useFlexService = v);
// callWith.argument("ignoreMinimumBookingPeriod", (Boolean v) -> request.ignoreDrtAdvanceBookMin = v);
RequestModes modes = getModes(environment, callWith);
if (modes != null) {
request.modes = modes;
}
ItineraryFiltersInputType.mapToRequest(environment, callWith, request.itineraryFilters);
if (request.vehicleRental && !GqlUtil.hasArgument(environment, "bikeSpeed")) {
// slower bike speed for bike sharing, based on empirical evidence from DC.
request.bikeSpeed = 4.3;
}
callWith.argument("minimumTransferTime", (Integer v) -> request.transferSlack = v);
callWith.argument("transferSlack", (Integer v) -> request.transferSlack = v);
callWith.argument("boardSlackDefault", (Integer v) -> request.boardSlack = v);
callWith.argument("boardSlackList", (Object v) -> request.boardSlackForMode = TransportModeSlack.mapToDomain(v));
callWith.argument("alightSlackDefault", (Integer v) -> request.alightSlack = v);
callWith.argument("alightSlackList", (Object v) -> request.alightSlackForMode = TransportModeSlack.mapToDomain(v));
callWith.argument("maximumTransfers", (Integer v) -> request.maxTransfers = v);
callWith.argument("useBikeRentalAvailabilityInformation", (Boolean v) -> request.useVehicleRentalAvailabilityInformation = v);
callWith.argument("ignoreRealtimeUpdates", (Boolean v) -> request.ignoreRealtimeUpdates = v);
callWith.argument("includePlannedCancellations", (Boolean v) -> request.includePlannedCancellations = v);
return request;
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class NearbyStopFinder method findNearbyStops.
/**
* Return all stops within a certain radius of the given vertex, using network distance along streets.
* Use the correct method depending on whether the graph has street data or not.
* If the origin vertex is a StopVertex, the result will include it; this characteristic is essential for
* associating the correct stop with each trip pattern in the vicinity.
*/
public List<NearbyStop> findNearbyStops(Vertex vertex, RoutingRequest routingRequest, boolean reverseDirection) {
if (useStreets) {
return findNearbyStopsViaStreets(Set.of(vertex), reverseDirection, true, routingRequest);
}
// It make sense for the directGraphFinder to use meters as a limit, so we convert first
double limitMeters = durationLimitInSeconds * new RoutingRequest(TraverseMode.WALK).walkSpeed;
Coordinate c0 = vertex.getCoordinate();
return directGraphFinder.findClosestStops(c0.y, c0.x, limitMeters);
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class AccessEgressRouter method streetSearch.
/**
* @param rr the current routing request
* @param fromTarget whether to route from or towards the point provided in the routing request
* (access or egress)
* @return Transfer objects by access/egress stop
*/
public static Collection<NearbyStop> streetSearch(RoutingRequest rr, StreetMode streetMode, boolean fromTarget) {
// TODO OTP2 This has to be done because we have not separated the main RoutingRequest from
// the subrequest for street searches. From/to vertices are already set based on the main
// request being arriveBy or not, but here we are actually setting arriveBy based on
// whether we are doing an access or egress search, regardless of the direction of the
// main request.
Set<Vertex> vertices = fromTarget ^ rr.arriveBy ? rr.rctx.toVertices : rr.rctx.fromVertices;
// A new RoutingRequest needs to be constructed, because findNearbyStopsViaStreets() resets
// the routingContext (rctx), which results in the created temporary edges being removed prematurely.
// findNearbyStopsViaStreets() will call cleanup() on the created routing request.
RoutingRequest nearbyRequest = rr.getStreetSearchRequest(streetMode);
NearbyStopFinder nearbyStopFinder = new NearbyStopFinder(rr.rctx.graph, rr.getMaxAccessEgressDurationSecondsForMode(streetMode), true);
List<NearbyStop> nearbyStopList = nearbyStopFinder.findNearbyStopsViaStreets(vertices, fromTarget, true, nearbyRequest);
LOG.debug("Found {} {} stops", nearbyStopList.size(), fromTarget ? "egress" : "access");
return nearbyStopList;
}
Aggregations