Search in sources :

Example 1 with BicycleOptimizeType

use of org.opentripplanner.routing.core.BicycleOptimizeType in project OpenTripPlanner by opentripplanner.

the class TransmodelGraphQLPlanner method createRequest.

private RoutingRequest createRequest(DataFetchingEnvironment environment) {
    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(new Date((long) millisSinceEpoch)), Date::new);
    callWith.argument("searchWindow", (Integer m) -> request.searchWindow = Duration.ofMinutes(m));
    callWith.argument("wheelchair", request::setWheelchairAccessible);
    callWith.argument("numTripPatterns", request::setNumItineraries);
    callWith.argument("transitGeneralizedCostLimit", (DoubleFunction<Double> it) -> request.transitGeneralizedCostLimit = it);
    callWith.argument("maximumWalkDistance", request::setMaxWalkDistance);
    // callWith.argument("maxTransferWalkDistance", request::setMaxTransferWalkDistance);
    callWith.argument("maxPreTransitTime", request::setMaxPreTransitTime);
    // 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::setWalkReluctance);
    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 optimize = environment.getArgument("optimize");
    if (optimize == BicycleOptimizeType.TRIANGLE) {
        try {
            RoutingRequest.assertTriangleParameters(request.bikeTriangleSafetyFactor, request.bikeTriangleTimeFactor, request.bikeTriangleSlopeFactor);
            callWith.argument("triangle.safetyFactor", request::setBikeTriangleSafetyFactor);
            callWith.argument("triangle.slopeFactor", request::setBikeTriangleSlopeFactor);
            callWith.argument("triangle.timeFactor", request::setBikeTriangleTimeFactor);
        } catch (ParameterException e) {
            throw new RuntimeException(e);
        }
    }
    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("allowBikeRental", (Boolean v) -> request.bikeRental = v);
    callWith.argument("debugItineraryFilter", (Boolean v) -> request.debugItineraryFilter = v);
    callWith.argument("transferPenalty", (Integer v) -> request.transferCost = v);
    if (optimize == BicycleOptimizeType.TRANSFERS) {
        optimize = BicycleOptimizeType.QUICK;
        request.transferCost += 1800;
    }
    if (optimize != null) {
        request.optimize = optimize;
    }
    if (GqlUtil.hasArgument(environment, "modes")) {
        ElementWrapper<StreetMode> accessMode = new ElementWrapper<>();
        ElementWrapper<StreetMode> egressMode = new ElementWrapper<>();
        ElementWrapper<StreetMode> directMode = new ElementWrapper<>();
        ElementWrapper<ArrayList<TransitMode>> transitModes = new ElementWrapper<>();
        callWith.argument("modes.accessMode", accessMode::set);
        callWith.argument("modes.egressMode", egressMode::set);
        callWith.argument("modes.directMode", directMode::set);
        callWith.argument("modes.transportMode", transitModes::set);
        if (transitModes.get() == null) {
            // Default to all transport modes if transport modes not specified
            transitModes.set(new ArrayList<>(Arrays.asList(TransitMode.values())));
        }
        request.modes = new RequestModes(accessMode.get(), egressMode.get(), directMode.get(), new HashSet<>(transitModes.get()));
    }
    if (request.bikeRental && !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);
    final long NOW_THRESHOLD_MILLIS = 15 * 60 * 60 * 1000;
    boolean tripPlannedForNow = Math.abs(request.getDateTime().getTime() - new Date().getTime()) < NOW_THRESHOLD_MILLIS;
    // TODO the same thing for GTFS-RT
    request.useBikeRentalAvailabilityInformation = (tripPlannedForNow);
    callWith.argument("ignoreRealtimeUpdates", (Boolean v) -> request.ignoreRealtimeUpdates = v);
    return request;
}
Also used : BicycleOptimizeType(org.opentripplanner.routing.core.BicycleOptimizeType) ArrayList(java.util.ArrayList) DataFetcherDecorator(org.opentripplanner.ext.transmodelapi.support.DataFetcherDecorator) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) ParameterException(org.opentripplanner.api.common.ParameterException) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) StreetMode(org.opentripplanner.routing.api.request.StreetMode) Router(org.opentripplanner.standalone.server.Router) Date(java.util.Date) DoubleFunction(java.util.function.DoubleFunction) RequestModes(org.opentripplanner.routing.api.request.RequestModes) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 DoubleFunction (java.util.function.DoubleFunction)1 ParameterException (org.opentripplanner.api.common.ParameterException)1 DataFetcherDecorator (org.opentripplanner.ext.transmodelapi.support.DataFetcherDecorator)1 RequestModes (org.opentripplanner.routing.api.request.RequestModes)1 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)1 StreetMode (org.opentripplanner.routing.api.request.StreetMode)1 BicycleOptimizeType (org.opentripplanner.routing.core.BicycleOptimizeType)1 Router (org.opentripplanner.standalone.server.Router)1