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));
}
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;
}
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));
}
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;
}
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);
}
}
Aggregations