Search in sources :

Example 1 with RequestModes

use of org.opentripplanner.routing.api.request.RequestModes 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)

Example 2 with RequestModes

use of org.opentripplanner.routing.api.request.RequestModes in project OpenTripPlanner by opentripplanner.

the class RoutingRequestMapper method mapRoutingRequest.

public static RoutingRequest mapRoutingRequest(NodeAdapter c) {
    RoutingRequest dft = new RoutingRequest();
    if (c.isEmpty()) {
        return dft;
    }
    LOG.debug("Loading default routing parameters from JSON.");
    RoutingRequest request = new RoutingRequest();
    // Keep this alphabetically sorted so it is easy to check if a parameter is missing from the
    // mapping or duplicate exist.
    request.alightSlack = c.asInt("alightSlack", dft.alightSlack);
    request.alightSlackForMode = c.asEnumMap("alightSlackForMode", TraverseMode.class, NodeAdapter::asInt);
    request.bikeRental = c.asBoolean("allowBikeRental", dft.bikeRental);
    request.arriveBy = c.asBoolean("arriveBy", dft.arriveBy);
    request.bikeBoardCost = c.asInt("bikeBoardCost", dft.bikeBoardCost);
    request.bikeParkAndRide = c.asBoolean("bikeParkAndRide", dft.bikeParkAndRide);
    request.bikeParkTime = c.asInt("bikeParkTime", dft.bikeParkTime);
    request.bikeParkCost = c.asInt("bikeParkCost", dft.bikeParkCost);
    request.bikeRentalDropoffCost = c.asInt("bikeRentalDropoffCost", dft.bikeRentalDropoffCost);
    request.bikeRentalDropoffTime = c.asInt("bikeRentalDropoffTime", dft.bikeRentalDropoffTime);
    request.bikeRentalPickupCost = c.asInt("bikeRentalPickupCost", dft.bikeRentalPickupCost);
    request.bikeRentalPickupTime = c.asInt("bikeRentalPickupTime", dft.bikeRentalPickupTime);
    request.bikeSpeed = c.asDouble("bikeSpeed", dft.bikeSpeed);
    request.bikeTriangleSafetyFactor = c.asDouble("bikeTriangleSafetyFactor", dft.bikeTriangleSafetyFactor);
    request.bikeTriangleSlopeFactor = c.asDouble("bikeTriangleSlopeFactor", dft.bikeTriangleSlopeFactor);
    request.bikeTriangleTimeFactor = c.asDouble("bikeTriangleTimeFactor", dft.bikeTriangleTimeFactor);
    request.bikeSwitchTime = c.asInt("bikeSwitchTime", dft.bikeSwitchTime);
    request.bikeSwitchCost = c.asInt("bikeSwitchCost", dft.bikeSwitchCost);
    request.boardSlack = c.asInt("boardSlack", dft.boardSlack);
    request.boardSlackForMode = c.asEnumMap("boardSlackForMode", TraverseMode.class, NodeAdapter::asInt);
    request.debugItineraryFilter = c.asBoolean("debugItineraryFilter", dft.debugItineraryFilter);
    request.carAccelerationSpeed = c.asDouble("carAccelerationSpeed", dft.carAccelerationSpeed);
    request.carDecelerationSpeed = c.asDouble("carDecelerationSpeed", dft.carDecelerationSpeed);
    request.carDropoffTime = c.asInt("carDropoffTime", dft.carDropoffTime);
    request.carSpeed = c.asDouble("carSpeed", dft.carSpeed);
    request.debugItineraryFilter = c.asBoolean("debugItineraryFilter", dft.debugItineraryFilter);
    request.groupBySimilarityKeepOne = c.asDouble("groupBySimilarityKeepOne", dft.groupBySimilarityKeepOne);
    request.groupBySimilarityKeepNumOfItineraries = c.asDouble("groupBySimilarityKeepNumOfItineraries", dft.groupBySimilarityKeepNumOfItineraries);
    request.disableAlertFiltering = c.asBoolean("disableAlertFiltering", dft.disableAlertFiltering);
    request.disableRemainingWeightHeuristic = c.asBoolean("disableRemainingWeightHeuristic", dft.disableRemainingWeightHeuristic);
    request.driveOnRight = c.asBoolean("driveOnRight", dft.driveOnRight);
    request.elevatorBoardCost = c.asInt("elevatorBoardCost", dft.elevatorBoardCost);
    request.elevatorBoardTime = c.asInt("elevatorBoardTime", dft.elevatorBoardTime);
    request.elevatorHopCost = c.asInt("elevatorHopCost", dft.elevatorHopCost);
    request.elevatorHopTime = c.asInt("elevatorHopTime", dft.elevatorHopTime);
    request.geoidElevation = c.asBoolean("geoidElevation", dft.geoidElevation);
    request.ignoreRealtimeUpdates = c.asBoolean("ignoreRealtimeUpdates", dft.ignoreRealtimeUpdates);
    request.carPickup = c.asBoolean("kissAndRide", dft.carPickup);
    request.locale = c.asLocale("locale", dft.locale);
    request.maxHours = c.asDouble("maxHours", dft.maxHours);
    request.maxPreTransitTime = c.asInt("maxPreTransitTime", dft.maxPreTransitTime);
    request.maxTransferWalkDistance = c.asDouble("maxTransferWalkDistance", dft.maxTransferWalkDistance);
    // 'maxTransfers' is configured in the Raptor tuning parameters, not here
    request.maxWalkDistance = c.asDouble("maxWalkDistance", dft.maxWalkDistance);
    request.maxWeight = c.asDouble("maxWeight", dft.maxWeight);
    // ADA max wheelchair ramp slope is a good default.
    request.maxWheelchairSlope = c.asDouble("maxWheelchairSlope", dft.maxWheelchairSlope);
    request.modes = new RequestModes(StreetMode.WALK, StreetMode.WALK, StreetMode.WALK, new HashSet<>(// TODO Map default modes from config
    Arrays.asList(TransitMode.values())));
    request.nonpreferredTransferCost = c.asInt("nonpreferredTransferPenalty", dft.nonpreferredTransferCost);
    request.numItineraries = c.asInt("numItineraries", dft.numItineraries);
    request.onlyTransitTrips = c.asBoolean("onlyTransitTrips", dft.onlyTransitTrips);
    request.optimize = c.asEnum("optimize", dft.optimize);
    request.otherThanPreferredRoutesPenalty = c.asInt("otherThanPreferredRoutesPenalty", dft.otherThanPreferredRoutesPenalty);
    request.parkAndRide = c.asBoolean("parkAndRide", dft.parkAndRide);
    request.pathComparator = c.asText("pathComparator", dft.pathComparator);
    request.showIntermediateStops = c.asBoolean("showIntermediateStops", dft.showIntermediateStops);
    request.stairsReluctance = c.asDouble("stairsReluctance", dft.stairsReluctance);
    request.startingTransitTripId = c.asFeedScopedId("startingTransitTripId", dft.startingTransitTripId);
    request.transferCost = c.asInt("transferPenalty", dft.transferCost);
    request.transferSlack = c.asInt("transferSlack", dft.transferSlack);
    request.transitGeneralizedCostLimit = c.asLinearFunction("transitGeneralizedCostLimit", dft.transitGeneralizedCostLimit);
    request.turnReluctance = c.asDouble("turnReluctance", dft.turnReluctance);
    request.useBikeRentalAvailabilityInformation = c.asBoolean("useBikeRentalAvailabilityInformation", dft.useBikeRentalAvailabilityInformation);
    request.useRequestedDateTimeInMaxHours = c.asBoolean("useRequestedDateTimeInMaxHours", dft.useRequestedDateTimeInMaxHours);
    request.useUnpreferredRoutesPenalty = c.asInt("useUnpreferredRoutesPenalty", dft.useUnpreferredRoutesPenalty);
    request.waitAtBeginningFactor = c.asDouble("waitAtBeginningFactor", dft.waitAtBeginningFactor);
    request.waitReluctance = c.asDouble("waitReluctance", dft.waitReluctance);
    request.walkBoardCost = c.asInt("walkBoardCost", dft.walkBoardCost);
    request.walkReluctance = c.asDouble("walkReluctance", dft.walkReluctance);
    request.walkSpeed = c.asDouble("walkSpeed", dft.walkSpeed);
    request.walkingBike = c.asBoolean("walkingBike", dft.walkingBike);
    request.wheelchairAccessible = c.asBoolean("wheelchairAccessible", dft.wheelchairAccessible);
    request.worstTime = c.asLong("worstTime", dft.worstTime);
    return request;
}
Also used : RequestModes(org.opentripplanner.routing.api.request.RequestModes) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseMode(org.opentripplanner.routing.core.TraverseMode) HashSet(java.util.HashSet)

Example 3 with RequestModes

use of org.opentripplanner.routing.api.request.RequestModes in project OpenTripPlanner by opentripplanner.

the class QualifiedModeSet method getRequestModes.

public RequestModes getRequestModes() {
    StreetMode accessMode = null;
    StreetMode egressMode = null;
    StreetMode directMode = null;
    Set<TransitMode> transitModes = new HashSet<>();
    // Set transit modes
    for (QualifiedMode qMode : qModes) {
        switch(qMode.mode) {
            case TRANSIT:
                transitModes.addAll(Arrays.asList(TransitMode.values()));
            case RAIL:
                transitModes.add(TransitMode.RAIL);
                break;
            case SUBWAY:
                transitModes.add(TransitMode.SUBWAY);
                break;
            case BUS:
                transitModes.add(TransitMode.BUS);
                break;
            case TRAM:
                transitModes.add(TransitMode.TRAM);
                break;
            case FERRY:
                transitModes.add(TransitMode.FERRY);
                break;
            case AIRPLANE:
                transitModes.add(TransitMode.AIRPLANE);
                break;
            case CABLE_CAR:
                transitModes.add(TransitMode.CABLE_CAR);
                break;
            case GONDOLA:
                transitModes.add(TransitMode.GONDOLA);
                break;
            case FUNICULAR:
                transitModes.add(TransitMode.FUNICULAR);
                break;
        }
    }
    // in this mapping.
    for (QualifiedMode qMode : qModes) {
        switch(qMode.mode) {
            case WALK:
                accessMode = StreetMode.WALK;
                egressMode = StreetMode.WALK;
                directMode = StreetMode.WALK;
                break;
            case BICYCLE:
                if (qMode.qualifiers.contains(Qualifier.RENT)) {
                    accessMode = StreetMode.BIKE_RENTAL;
                    egressMode = StreetMode.BIKE_RENTAL;
                    directMode = StreetMode.BIKE_RENTAL;
                } else if (qMode.qualifiers.contains(Qualifier.PARK)) {
                    accessMode = StreetMode.BIKE_TO_PARK;
                    egressMode = StreetMode.WALK;
                    directMode = StreetMode.BIKE_TO_PARK;
                } else {
                    accessMode = StreetMode.BIKE;
                    egressMode = StreetMode.BIKE;
                    directMode = StreetMode.BIKE;
                }
                break;
            case CAR:
                if (qMode.qualifiers.contains(Qualifier.RENT)) {
                    accessMode = StreetMode.CAR_RENTAL;
                    egressMode = StreetMode.CAR_RENTAL;
                    directMode = StreetMode.CAR_RENTAL;
                } else if (qMode.qualifiers.contains(Qualifier.PARK)) {
                    accessMode = StreetMode.CAR_TO_PARK;
                    egressMode = StreetMode.WALK;
                    directMode = StreetMode.CAR_TO_PARK;
                } else {
                    accessMode = StreetMode.WALK;
                    egressMode = StreetMode.WALK;
                    directMode = StreetMode.CAR;
                }
                break;
        }
    }
    RequestModes requestModes = new RequestModes(accessMode, egressMode, directMode, transitModes);
    return requestModes;
}
Also used : StreetMode(org.opentripplanner.routing.api.request.StreetMode) RequestModes(org.opentripplanner.routing.api.request.RequestModes) TransitMode(org.opentripplanner.model.TransitMode) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)3 RequestModes (org.opentripplanner.routing.api.request.RequestModes)3 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)2 StreetMode (org.opentripplanner.routing.api.request.StreetMode)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)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 TransitMode (org.opentripplanner.model.TransitMode)1 BicycleOptimizeType (org.opentripplanner.routing.core.BicycleOptimizeType)1 TraverseMode (org.opentripplanner.routing.core.TraverseMode)1 Router (org.opentripplanner.standalone.server.Router)1