Search in sources :

Example 31 with Route

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

the class JourneyWhiteListed method isTripTimeShortAcceptable.

private static boolean isTripTimeShortAcceptable(TripTimeShort tts, Collection<FeedScopedId> authorityIds, Collection<FeedScopedId> lineIds, RoutingService routingService) {
    Trip trip = routingService.getTripForId().get(tts.tripId);
    if (trip == null || trip.getRoute() == null) {
        return true;
    }
    Route route = trip.getRoute();
    boolean okForAuthority = authorityIds.contains(route.getAgency().getId());
    boolean okForLine = lineIds.contains(route.getId());
    return okForAuthority || okForLine;
}
Also used : Trip(org.opentripplanner.model.Trip) Route(org.opentripplanner.model.Route)

Example 32 with Route

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

the class IndexAPI method getRoutes.

/**
 * Return a list of all routes in the graph.
 */
// with repeated hasStop parameters, replaces old routesBetweenStops
@GET
@Path("/routes")
public List<ApiRouteShort> getRoutes(@QueryParam("hasStop") List<String> stopIds) {
    RoutingService routingService = createRoutingService();
    Collection<Route> routes = routingService.getAllRoutes();
    // Filter routes to include only those that pass through all given stops
    if (stopIds != null) {
        // Protective copy, we are going to calculate the intersection destructively
        routes = new ArrayList<>(routes);
        for (String stopId : stopIds) {
            Stop stop = getStop(routingService, stopId);
            Set<Route> routesHere = new HashSet<>();
            for (TripPattern pattern : routingService.getPatternsForStop(stop)) {
                routesHere.add(pattern.route);
            }
            routes.retainAll(routesHere);
        }
    }
    return RouteMapper.mapToApiShort(routes);
}
Also used : ApiStop(org.opentripplanner.api.model.ApiStop) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) LineString(org.locationtech.jts.geom.LineString) ApiRoute(org.opentripplanner.api.model.ApiRoute) Route(org.opentripplanner.model.Route) TripPattern(org.opentripplanner.model.TripPattern) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 33 with Route

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

the class NetexMapper method mapRoute.

private void mapRoute(NetexImportDataIndexReadOnlyView netexIndex) {
    RouteMapper routeMapper = new RouteMapper(idFactory, transitBuilder.getAgenciesById(), transitBuilder.getOperatorsById(), netexIndex, netexIndex.getTimeZone());
    for (Line line : netexIndex.getLineById().localValues()) {
        Route route = routeMapper.mapRoute(line);
        transitBuilder.getRoutes().add(route);
    }
}
Also used : Line(org.rutebanken.netex.model.Line) Route(org.opentripplanner.model.Route)

Example 34 with Route

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

the class DefaultFareServiceFactory method fillFareRules.

protected void fillFareRules(Collection<FareAttribute> fareAttributes, Collection<FareRule> fareRules, Map<FeedScopedId, FareRuleSet> fareRuleSet) {
    /*
         * Create an empty FareRuleSet for each FareAttribute, as some FareAttribute may have no
         * rules attached to them.
         */
    for (FareAttribute fare : fareAttributes) {
        FeedScopedId id = fare.getId();
        FareRuleSet fareRule = fareRuleSet.get(id);
        if (fareRule == null) {
            fareRule = new FareRuleSet(fare);
            fareRuleSet.put(id, fareRule);
        }
    }
    /*
         * For each fare rule, add it to the FareRuleSet of the fare.
         */
    for (FareRule rule : fareRules) {
        FareAttribute fare = rule.getFare();
        FeedScopedId id = fare.getId();
        FareRuleSet fareRule = fareRuleSet.get(id);
        if (fareRule == null) {
            // Should never happen by design
            LOG.error("Inexistant fare ID in fare rule: " + id);
            continue;
        }
        String contains = rule.getContainsId();
        if (contains != null) {
            fareRule.addContains(contains);
        }
        String origin = rule.getOriginId();
        String destination = rule.getDestinationId();
        if (origin != null || destination != null) {
            fareRule.addOriginDestination(origin, destination);
        }
        Route route = rule.getRoute();
        if (route != null) {
            FeedScopedId routeId = route.getId();
            fareRule.addRoute(routeId);
        }
    }
}
Also used : FareAttribute(org.opentripplanner.model.FareAttribute) FareRule(org.opentripplanner.model.FareRule) FeedScopedId(org.opentripplanner.model.FeedScopedId) FareRuleSet(org.opentripplanner.routing.core.FareRuleSet) Route(org.opentripplanner.model.Route)

Example 35 with Route

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

the class TimetableSnapshotSource method handleAddedTrip.

/**
 * Handle GTFS-RT TripUpdate message containing an ADDED trip.
 *
 * @param graph graph to update
 * @param tripUpdate GTFS-RT TripUpdate message
 * @param stops the stops of each StopTimeUpdate in the TripUpdate message
 * @param feedId
 * @param serviceDate service date for added trip
 * @return true iff successful
 */
private boolean handleAddedTrip(final Graph graph, final TripUpdate tripUpdate, final List<Stop> stops, final String feedId, final ServiceDate serviceDate) {
    // Preconditions
    Preconditions.checkNotNull(stops);
    Preconditions.checkArgument(tripUpdate.getStopTimeUpdateCount() == stops.size(), "number of stop should match the number of stop time updates");
    // Check whether trip id has been used for previously ADDED trip message and cancel
    // previously created trip
    final String tripId = tripUpdate.getTrip().getTripId();
    cancelPreviouslyAddedTrip(new FeedScopedId(feedId, tripId), serviceDate);
    // 
    // Create added trip
    // 
    Route route = null;
    if (tripUpdate.getTrip().hasRouteId()) {
        // Try to find route
        route = getRouteForRouteId(feedId, tripUpdate.getTrip().getRouteId());
    }
    if (route == null) {
        // Create new Route
        route = new Route();
        // Use route id of trip descriptor if available
        if (tripUpdate.getTrip().hasRouteId()) {
            route.setId(new FeedScopedId(feedId, tripUpdate.getTrip().getRouteId()));
        } else {
            route.setId(new FeedScopedId(feedId, tripId));
        }
        // Create dummy agency for added trips
        Agency dummyAgency = new Agency(new FeedScopedId(feedId, "Dummy"), "Dummy", "Europe/Paris");
        route.setAgency(dummyAgency);
        // Guess the route type as it doesn't exist yet in the specifications
        // Bus. Used for short- and long-distance bus routes.
        route.setType(3);
        route.setMode(TransitMode.BUS);
        // Create route name
        route.setLongName(tripId);
    }
    // Create new Trip
    final Trip trip = new Trip();
    // TODO: which Agency ID to use? Currently use feed id.
    trip.setId(new FeedScopedId(feedId, tripUpdate.getTrip().getTripId()));
    trip.setRoute(route);
    // Find service ID running on this service date
    final Set<FeedScopedId> serviceIds = graph.getCalendarService().getServiceIdsOnDate(serviceDate);
    if (serviceIds.isEmpty()) {
        // No service id exists: return error for now
        LOG.warn("ADDED trip has service date for which no service id is available, skipping.");
        return false;
    } else {
        // Just use first service id of set
        trip.setServiceId(serviceIds.iterator().next());
    }
    final boolean success = addTripToGraphAndBuffer(feedId, graph, trip, tripUpdate, stops, serviceDate, RealTimeState.ADDED);
    return success;
}
Also used : Trip(org.opentripplanner.model.Trip) Agency(org.opentripplanner.model.Agency) FeedScopedId(org.opentripplanner.model.FeedScopedId) Route(org.opentripplanner.model.Route)

Aggregations

Route (org.opentripplanner.model.Route)36 FeedScopedId (org.opentripplanner.model.FeedScopedId)17 Trip (org.opentripplanner.model.Trip)16 TripPattern (org.opentripplanner.model.TripPattern)13 Test (org.junit.Test)11 Stop (org.opentripplanner.model.Stop)9 ArrayList (java.util.ArrayList)8 Agency (org.opentripplanner.model.Agency)7 HashSet (java.util.HashSet)6 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)6 RoutingService (org.opentripplanner.routing.RoutingService)6 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)6 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 ApiRoute (org.opentripplanner.api.model.ApiRoute)4 TransitAlert (org.opentripplanner.routing.alertpatch.TransitAlert)4 Collection (java.util.Collection)3 LineString (org.locationtech.jts.geom.LineString)3