/** * Finds all egress paths from to coordinate to end stop and adds routers to egressRouter * * @param request * @param egressRouter */ private void findEgressPaths(ProfileRequest request, Map<LegMode, StreetRouter> egressRouter) { // For egress // TODO: this must be reverse search for (LegMode mode : request.egressModes) { StreetRouter streetRouter = new StreetRouter(transportNetwork.streetLayer); streetRouter.transitStopSearch = true; streetRouter.dominanceVariable = StreetRouter.State.RoutingVariable.DURATION_SECONDS; if (egressUnsupportedModes.contains(mode)) { continue; } // TODO: add support for bike sharing streetRouter.streetMode = StreetMode.valueOf(mode.toString()); streetRouter.profileRequest = request; streetRouter.timeLimitSeconds = request.getTimeLimit(mode); if (streetRouter.setOrigin(request.toLat, request.toLon)) { streetRouter.route(); TIntIntMap stops = streetRouter.getReachedStops(); egressRouter.put(mode, streetRouter); LOG.info("Added {} edgres stops for mode {}", stops.size(), mode); } else { LOG.warn( "MODE:{}, Edge near the origin coordinate wasn't found. Routing didn't start!", mode); } } }
/** * Finds direct paths between from and to coordinates in request and adds them to option * * @param request * @param option */ private void findDirectPaths(ProfileRequest request, ProfileOption option) { // For direct modes for (LegMode mode : request.directModes) { StreetRouter streetRouter = new StreetRouter(transportNetwork.streetLayer); StreetPath streetPath; streetRouter.profileRequest = request; if (mode == LegMode.BICYCLE_RENT) { if (!transportNetwork.streetLayer.bikeSharing) { LOG.warn("Bike sharing trip requested but no bike sharing stations in the streetlayer"); continue; } streetRouter = findBikeRentalPath(request, streetRouter, true); if (streetRouter != null) { StreetRouter.State lastState = streetRouter.getState(request.toLat, request.toLon); if (lastState != null) { streetPath = new StreetPath(lastState, streetRouter, LegMode.BICYCLE_RENT, transportNetwork); } else { LOG.warn( "MODE:{}, Edge near the destination coordinate wasn't found. Routing didn't start!", mode); continue; } } else { LOG.warn("Not found path from cycle to end"); continue; } } else { streetRouter.streetMode = StreetMode.valueOf(mode.toString()); streetRouter.timeLimitSeconds = request.streetTime * 60; if (streetRouter.setOrigin(request.fromLat, request.fromLon)) { if (!streetRouter.setDestination(request.toLat, request.toLon)) { LOG.warn("Direct mode {} destination wasn't found!", mode); continue; } streetRouter.route(); StreetRouter.State lastState = streetRouter.getState(streetRouter.getDestinationSplit()); if (lastState == null) { LOG.warn("Direct mode {} last state wasn't found", mode); continue; } streetPath = new StreetPath(lastState, transportNetwork); } else { LOG.warn("Direct mode {} origin wasn't found!", mode); continue; } } StreetSegment streetSegment = new StreetSegment(streetPath, mode, transportNetwork.streetLayer); option.addDirect(streetSegment, request.getFromTimeDateZD()); } }
/** * Finds access paths from from coordinate in request and adds all routers with paths to * accessRouter map * * @param request * @param accessRouter */ private void findAccessPaths(ProfileRequest request, Map<LegMode, StreetRouter> accessRouter) { // Routes all access modes for (LegMode mode : request.accessModes) { StreetRouter streetRouter = new StreetRouter(transportNetwork.streetLayer); streetRouter.profileRequest = request; if (mode == LegMode.CAR_PARK) { streetRouter = findParkRidePath(request, streetRouter); if (streetRouter != null) { accessRouter.put(LegMode.CAR_PARK, streetRouter); } else { LOG.warn( "MODE:{}, Edge near the origin coordinate wasn't found. Routing didn't start!", mode); } } else if (mode == LegMode.BICYCLE_RENT) { if (!transportNetwork.streetLayer.bikeSharing) { LOG.warn("Bike sharing trip requested but no bike sharing stations in the streetlayer"); continue; } streetRouter = findBikeRentalPath(request, streetRouter, false); if (streetRouter != null) { accessRouter.put(LegMode.BICYCLE_RENT, streetRouter); } else { LOG.warn("Not found path from cycle to end"); } } else { streetRouter.streetMode = StreetMode.valueOf(mode.toString()); // Gets correct maxCar/Bike/Walk time in seconds for access leg based on mode since it // depends on the mode streetRouter.timeLimitSeconds = request.getTimeLimit(mode); streetRouter.transitStopSearch = true; streetRouter.dominanceVariable = StreetRouter.State.RoutingVariable.DURATION_SECONDS; if (streetRouter.setOrigin(request.fromLat, request.fromLon)) { streetRouter.route(); // Searching for access paths accessRouter.put(mode, streetRouter); } else { LOG.warn( "MODE:{}, Edge near the origin coordinate wasn't found. Routing didn't start!", mode); } } } }
/** * Uses 2 streetSearches to get P+R path * * <p>First CAR search from fromLat/fromLon to all car parks. Then from those found places WALK * search. * * <p>Result is then used as access part. Since P+R in direct mode is useless. * * @param request profileRequest from which from/to destination is used * @param streetRouter where profileRequest was already set * @return null if path isn't found */ private StreetRouter findParkRidePath(ProfileRequest request, StreetRouter streetRouter) { streetRouter.streetMode = StreetMode.CAR; streetRouter.timeLimitSeconds = request.maxCarTime * 60; streetRouter.flagSearch = VertexStore.VertexFlag.PARK_AND_RIDE; streetRouter.dominanceVariable = StreetRouter.State.RoutingVariable.DURATION_SECONDS; if (streetRouter.setOrigin(request.fromLat, request.fromLon)) { streetRouter.route(); TIntObjectMap<StreetRouter.State> carParks = streetRouter.getReachedVertices(VertexStore.VertexFlag.PARK_AND_RIDE); LOG.info("CAR PARK: Found {} car parks", carParks.size()); StreetRouter walking = new StreetRouter(transportNetwork.streetLayer); walking.streetMode = StreetMode.WALK; walking.profileRequest = request; walking.timeLimitSeconds = request.maxCarTime * 60; walking.transitStopSearch = true; walking.setOrigin(carParks, CAR_PARK_DROPOFF_TIME_S, CAR_PARK_DROPOFF_COST, LegMode.CAR_PARK); walking.dominanceVariable = StreetRouter.State.RoutingVariable.DURATION_SECONDS; walking.route(); walking.previousRouter = streetRouter; return walking; } else { return null; } }
/** * Uses 3 streetSearches to first search from fromLat/fromLon to all the bike renting places in * WALK mode. Then from all found bike renting places to other bike renting places with BIKE and * then just routing from those found bike renting places in WALK mode. * * <p>This can then be used as streetRouter for access paths or as a direct search for specific * destination * * <p>Last streetRouter (WALK from bike rentals) is returned * * @param request profileRequest from which from/to destination is used * @param streetRouter where profileRequest was already set * @param direct * @return null if path isn't found */ private StreetRouter findBikeRentalPath( ProfileRequest request, StreetRouter streetRouter, boolean direct) { streetRouter.streetMode = StreetMode.WALK; // TODO add time and distance limits to routing, not just weight. streetRouter.timeLimitSeconds = request.maxWalkTime * 60; if (!direct) { streetRouter.dominanceVariable = StreetRouter.State.RoutingVariable.DURATION_SECONDS; } streetRouter.flagSearch = VertexStore.VertexFlag.BIKE_SHARING; if (streetRouter.setOrigin(request.fromLat, request.fromLon)) { // if we can't find destination we can stop search before even trying if (direct && !streetRouter.setDestination(request.toLat, request.toLon)) { return null; } Split destinationSplit = streetRouter.getDestinationSplit(); // reset destinationSplit since we need it at the last part of routing streetRouter.setDestination(null); streetRouter.route(); // This finds all the nearest bicycle rent stations when walking TIntObjectMap<StreetRouter.State> bikeStations = streetRouter.getReachedVertices(VertexStore.VertexFlag.BIKE_SHARING); LOG.info( "BIKE RENT: Found {} bike stations which are {} minutes away", bikeStations.size(), streetRouter.timeLimitSeconds / 60); /*LOG.info("Start to bike share:"); bikeStations.forEachEntry((idx, state) -> { LOG.info(" {} ({}m)", idx, state.distance); return true; });*/ // This finds best cycling path from best start bicycle station to end bicycle station StreetRouter bicycle = new StreetRouter(transportNetwork.streetLayer); bicycle.previousRouter = streetRouter; bicycle.streetMode = StreetMode.BICYCLE; bicycle.profileRequest = request; bicycle.flagSearch = streetRouter.flagSearch; bicycle.maxVertices = Integer.MAX_VALUE; // Longer bike part if this is direct search if (direct) { bicycle.timeLimitSeconds = request.streetTime * 60; } else { bicycle.timeLimitSeconds = request.maxBikeTime * 60; bicycle.dominanceVariable = StreetRouter.State.RoutingVariable.DURATION_SECONDS; } bicycle.setOrigin( bikeStations, BIKE_RENTAL_PICKUP_TIME_S, BIKE_RENTAL_PICKUP_COST, LegMode.BICYCLE_RENT); bicycle.setDestination(destinationSplit); bicycle.route(); TIntObjectMap<StreetRouter.State> cycledStations = bicycle.getReachedVertices(VertexStore.VertexFlag.BIKE_SHARING); LOG.info( "BIKE RENT: Found {} cycled stations which are {} minutes away", cycledStations.size(), bicycle.timeLimitSeconds / 60); /*LOG.info("Bike share to bike share:"); cycledStations.retainEntries((idx, state) -> { if (bikeStations.containsKey(idx)) { LOG.warn(" MM:{} ({}m)", idx, state.distance/1000); return false; } else { LOG.info(" {} ({}m)", idx, state.distance / 1000); return true; } });*/ // This searches for walking path from end bicycle station to end point StreetRouter end = new StreetRouter(transportNetwork.streetLayer); end.streetMode = StreetMode.WALK; end.profileRequest = request; end.timeLimitSeconds = bicycle.timeLimitSeconds; if (!direct) { end.transitStopSearch = true; end.dominanceVariable = StreetRouter.State.RoutingVariable.DURATION_SECONDS; } end.setOrigin( cycledStations, BIKE_RENTAL_DROPOFF_TIME_S, BIKE_RENTAL_DROPOFF_COST, LegMode.BICYCLE_RENT); end.route(); end.previousRouter = bicycle; return end; } else { return null; } }