Search in sources :

Example 1 with TransitMode

use of org.opentripplanner.model.TransitMode in project OpenTripPlanner by opentripplanner.

the class StreetGraphFinder method findClosestPlaces.

@Override
public List<PlaceAtDistance> findClosestPlaces(double lat, double lon, double radiusMeters, int maxResults, List<TransitMode> filterByModes, List<PlaceType> filterByPlaceTypes, List<FeedScopedId> filterByStops, List<FeedScopedId> filterByRoutes, List<String> filterByBikeRentalStations, List<String> filterByBikeParks, List<String> filterByCarParks, RoutingService routingService) {
    PlaceFinderTraverseVisitor visitor = new PlaceFinderTraverseVisitor(routingService, filterByModes, filterByPlaceTypes, filterByStops, filterByRoutes, filterByBikeRentalStations, maxResults);
    SearchTerminationStrategy terminationStrategy = visitor.getSearchTerminationStrategy();
    findClosestUsingStreets(lat, lon, radiusMeters, visitor, terminationStrategy);
    List<PlaceAtDistance> results = visitor.placesFound;
    results.sort(Comparator.comparingDouble(pad -> pad.distance));
    return results.subList(0, min(results.size(), maxResults));
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) SearchTerminationStrategy(org.opentripplanner.routing.algorithm.astar.strategies.SearchTerminationStrategy) RoutingService(org.opentripplanner.routing.RoutingService) GenericLocation(org.opentripplanner.model.GenericLocation) TrivialRemainingWeightHeuristic(org.opentripplanner.routing.algorithm.astar.strategies.TrivialRemainingWeightHeuristic) TraverseVisitor(org.opentripplanner.routing.algorithm.astar.TraverseVisitor) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction) List(java.util.List) Graph(org.opentripplanner.routing.graph.Graph) TraverseMode(org.opentripplanner.routing.core.TraverseMode) AStar(org.opentripplanner.routing.algorithm.astar.AStar) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Comparator(java.util.Comparator) TransitMode(org.opentripplanner.model.TransitMode) Integer.min(java.lang.Integer.min) SearchTerminationStrategy(org.opentripplanner.routing.algorithm.astar.strategies.SearchTerminationStrategy)

Example 2 with TransitMode

use of org.opentripplanner.model.TransitMode in project OpenTripPlanner by opentripplanner.

the class TravelOptionsMaker method makeOptions.

public static List<TravelOption> makeOptions(HashSet<TransitMode> transitModes, boolean hasBikeSharing, boolean hasBikeRide, boolean hasParkRide) {
    List<TravelOption> travelOptions = new ArrayList<>(16);
    // Adds Transit, and all the transit modes
    if (!transitModes.isEmpty()) {
        travelOptions.add(new TravelOption(String.join(",", TraverseMode.TRANSIT.toString(), TraverseMode.WALK.toString()), TraverseMode.TRANSIT.toString()));
        for (TransitMode transitMode : transitModes) {
            travelOptions.add(new TravelOption(String.join(",", transitMode.toString(), TraverseMode.WALK.toString()), transitMode.toString()));
        }
    }
    travelOptions.addAll(staticTravelOptions);
    if (hasBikeSharing) {
        travelOptions.add(new TravelOption(String.join(",", TraverseMode.WALK.toString(), "BICYCLE_RENT"), "BICYCLERENT"));
    }
    // If transit modes exists.
    if (!transitModes.isEmpty()) {
        // Adds bicycle transit mode
        travelOptions.add(new TravelOption(String.join(",", TraverseMode.TRANSIT.toString(), TraverseMode.BICYCLE.toString()), String.join("_", TraverseMode.TRANSIT.toString(), TraverseMode.BICYCLE.toString())));
        if (hasBikeSharing) {
            travelOptions.add(new TravelOption(String.join(",", TraverseMode.TRANSIT.toString(), TraverseMode.WALK.toString(), "BICYCLE_RENT"), "TRANSIT_BICYCLERENT"));
        }
        if (hasParkRide) {
            travelOptions.add(new TravelOption(String.join(",", "CAR_PARK", TraverseMode.WALK.toString(), TraverseMode.TRANSIT.toString()), "PARKRIDE"));
        }
        if (hasBikeRide) {
            travelOptions.add(new TravelOption(String.join(",", "BICYCLE_PARK", TraverseMode.WALK.toString(), TraverseMode.TRANSIT.toString()), "BIKERIDE"));
        }
        travelOptions.add(new TravelOption(String.join(",", TraverseMode.CAR.toString(), TraverseMode.WALK.toString(), TraverseMode.TRANSIT.toString()), "KISSRIDE"));
    }
    return travelOptions;
}
Also used : ArrayList(java.util.ArrayList) TransitMode(org.opentripplanner.model.TransitMode)

Example 3 with TransitMode

use of org.opentripplanner.model.TransitMode in project OpenTripPlanner by opentripplanner.

the class StopPlaceType method getTripTimesForStop.

public static Stream<TripTimeShort> getTripTimesForStop(Stop stop, Long startTimeSeconds, int timeRage, boolean omitNonBoarding, int numberOfDepartures, Integer departuresPerLineAndDestinationDisplay, Collection<FeedScopedId> authorityIdsWhiteListed, Collection<FeedScopedId> lineIdsWhiteListed, Collection<TransitMode> transitModes, DataFetchingEnvironment environment) {
    RoutingService routingService = GqlUtil.getRoutingService(environment);
    boolean limitOnDestinationDisplay = departuresPerLineAndDestinationDisplay != null && departuresPerLineAndDestinationDisplay > 0 && departuresPerLineAndDestinationDisplay < numberOfDepartures;
    int departuresPerTripPattern = limitOnDestinationDisplay ? departuresPerLineAndDestinationDisplay : numberOfDepartures;
    List<StopTimesInPattern> stopTimesInPatterns = routingService.stopTimesForStop(stop, startTimeSeconds, timeRage, departuresPerTripPattern, omitNonBoarding);
    // TODO OTP2 - Applying filters here is not correct - the `departuresPerTripPattern` is used
    // - to limit the result, and using filters after that point may result in
    // - loosing valid results.
    Stream<StopTimesInPattern> stopTimesStream = stopTimesInPatterns.stream();
    if (transitModes != null && !transitModes.isEmpty()) {
        stopTimesStream = stopTimesStream.filter(it -> transitModes.contains(it.pattern.getMode()));
    }
    Stream<TripTimeShort> tripTimesStream = stopTimesStream.flatMap(p -> p.times.stream());
    tripTimesStream = JourneyWhiteListed.whiteListAuthoritiesAndOrLines(tripTimesStream, authorityIdsWhiteListed, lineIdsWhiteListed, routingService);
    if (!limitOnDestinationDisplay) {
        return tripTimesStream;
    }
    // Group by line and destination display, limit departures per group and merge
    return tripTimesStream.collect(Collectors.groupingBy(t -> destinationDisplayPerLine(((TripTimeShort) t), routingService))).values().stream().flatMap(tripTimes -> tripTimes.stream().sorted(TripTimeShort.compareByDeparture()).distinct().limit(departuresPerLineAndDestinationDisplay));
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) RoutingService(org.opentripplanner.routing.RoutingService) Trip(org.opentripplanner.model.Trip) MultiModalStation(org.opentripplanner.model.MultiModalStation) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) TRANSPORT_MODE(org.opentripplanner.ext.transmodelapi.model.EnumTypes.TRANSPORT_MODE) HashSet(java.util.HashSet) Scalars(graphql.Scalars) TripTimeShort(org.opentripplanner.model.TripTimeShort) TransitMode(org.opentripplanner.model.TransitMode) GraphQLObjectType(graphql.schema.GraphQLObjectType) FeedScopedId(org.opentripplanner.model.FeedScopedId) Station(org.opentripplanner.model.Station) TRANSPORT_SUBMODE(org.opentripplanner.ext.transmodelapi.model.EnumTypes.TRANSPORT_SUBMODE) EnumTypes(org.opentripplanner.ext.transmodelapi.model.EnumTypes) GqlUtil(org.opentripplanner.ext.transmodelapi.support.GqlUtil) GraphQLNonNull(graphql.schema.GraphQLNonNull) Stop(org.opentripplanner.model.Stop) StopCollection(org.opentripplanner.model.StopCollection) Collection(java.util.Collection) Set(java.util.Set) GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLArgument(graphql.schema.GraphQLArgument) TransmodelTransportSubmode(org.opentripplanner.ext.transmodelapi.model.TransmodelTransportSubmode) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) Stream(java.util.stream.Stream) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) JourneyWhiteListed(org.opentripplanner.ext.transmodelapi.model.route.JourneyWhiteListed) TRUE(java.lang.Boolean.TRUE) TripTimeShort(org.opentripplanner.model.TripTimeShort) RoutingService(org.opentripplanner.routing.RoutingService) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern)

Example 4 with TransitMode

use of org.opentripplanner.model.TransitMode 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)

Example 5 with TransitMode

use of org.opentripplanner.model.TransitMode in project OpenTripPlanner by opentripplanner.

the class AddTransitModelEntitiesToGraph method addStopsToGraphAndGenerateStopVertexes.

private void addStopsToGraphAndGenerateStopVertexes(Graph graph) {
    // Compute the set of modes for each stop based on all the TripPatterns it is part of
    Map<Stop, Set<TransitMode>> stopModeMap = new HashMap<>();
    for (TripPattern pattern : transitService.getTripPatterns()) {
        TransitMode mode = pattern.getMode();
        graph.addTransitMode(mode);
        for (Stop stop : pattern.getStops()) {
            Set<TransitMode> set = stopModeMap.computeIfAbsent(stop, s -> new HashSet<>());
            set.add(mode);
        }
    }
    // It is now possible for these vertices to not be connected to any edges.
    for (Stop stop : transitService.getAllStops()) {
        Set<TransitMode> modes = stopModeMap.get(stop);
        TransitStopVertex stopVertex = new TransitStopVertex(graph, stop, modes);
        if (modes != null && modes.contains(TransitMode.SUBWAY)) {
            stopVertex.setStreetToStopTime(subwayAccessTime);
        }
        // Add stops to internal index for Pathways to be created from this map
        stationElementNodes.put(stop, stopVertex);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Stop(org.opentripplanner.model.Stop) HashMap(java.util.HashMap) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) TransitMode(org.opentripplanner.model.TransitMode) TripPattern(org.opentripplanner.model.TripPattern)

Aggregations

TransitMode (org.opentripplanner.model.TransitMode)5 HashSet (java.util.HashSet)3 List (java.util.List)2 Set (java.util.Set)2 FeedScopedId (org.opentripplanner.model.FeedScopedId)2 Stop (org.opentripplanner.model.Stop)2 RoutingService (org.opentripplanner.routing.RoutingService)2 Scalars (graphql.Scalars)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 GraphQLArgument (graphql.schema.GraphQLArgument)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 GraphQLInterfaceType (graphql.schema.GraphQLInterfaceType)1 GraphQLList (graphql.schema.GraphQLList)1 GraphQLNonNull (graphql.schema.GraphQLNonNull)1 GraphQLObjectType (graphql.schema.GraphQLObjectType)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 GraphQLTypeReference (graphql.schema.GraphQLTypeReference)1 TRUE (java.lang.Boolean.TRUE)1 Integer.min (java.lang.Integer.min)1 ArrayList (java.util.ArrayList)1