Search in sources :

Example 11 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getTripsForRoute.

/**
 * Return all trips in any pattern on the given route.
 */
@GET
@Path("/routes/{routeId}/trips")
public List<ApiTripShort> getTripsForRoute(@PathParam("routeId") String routeId) {
    RoutingService routingService = createRoutingService();
    Route route = getRoute(routingService, routeId);
    List<Trip> trips = new ArrayList<>();
    Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(route);
    for (TripPattern pattern : patterns) {
        trips.addAll(pattern.getTrips());
    }
    return TripMapper.mapToApiShort(trips);
}
Also used : Trip(org.opentripplanner.model.Trip) ApiTrip(org.opentripplanner.api.model.ApiTrip) RoutingService(org.opentripplanner.routing.RoutingService) ArrayList(java.util.ArrayList) ApiRoute(org.opentripplanner.api.model.ApiRoute) Route(org.opentripplanner.model.Route) TripPattern(org.opentripplanner.model.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getRoutesForStop.

@GET
@Path("/stops/{stopId}/routes")
public List<ApiRouteShort> getRoutesForStop(@PathParam("stopId") String stopId) {
    RoutingService routingService = createRoutingService();
    Stop stop = getStop(routingService, stopId);
    return routingService.getPatternsForStop(stop).stream().map(it -> it.route).map(RouteMapper::mapToApiShort).collect(Collectors.toList());
}
Also used : ApiStop(org.opentripplanner.api.model.ApiStop) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class PlannerResource method plan.

// We inject info about the incoming request so we can include the incoming query
// parameters in the outgoing response. This is a TriMet requirement.
// Jersey uses @Context to inject internal types and @InjectParam or @Resource for DI objects.
@GET
@Produces(MediaType.APPLICATION_JSON)
public TripPlannerResponse plan(@Context UriInfo uriInfo, @Context Request grizzlyRequest) {
    /*
         * TODO: add Lang / Locale parameter, and thus get localized content (Messages & more...)
         * TODO: from/to inputs should be converted / geocoded / etc... here, and maybe send coords 
         *       or vertex ids to planner (or error back to user)
         * TODO: org.opentripplanner.routing.module.PathServiceImpl has COOORD parsing. Abstract that
         *       out so it's used here too...
         */
    // Create response object, containing a copy of all request parameters. Maybe they should be in the debug section of the response.
    TripPlannerResponse response = new TripPlannerResponse(uriInfo);
    RoutingRequest request = null;
    Router router = null;
    RoutingResponse res = null;
    try {
        /* Fill in request fields from query parameters via shared superclass method, catching any errors. */
        request = super.buildRequest();
        router = otpServer.getRouter();
        // Route
        RoutingService routingService = new RoutingService(router.graph);
        res = routingService.route(request, router);
        // Map to API
        TripPlanMapper tripPlanMapper = new TripPlanMapper(request.locale);
        response.setPlan(tripPlanMapper.mapTripPlan(res.getTripPlan()));
        response.setMetadata(TripSearchMetadataMapper.mapTripSearchMetadata(res.getMetadata()));
        if (!res.getRoutingErrors().isEmpty()) {
            // The api can only return one error message, so the first one is mapped
            response.setError(PlannerErrorMapper.mapMessage(res.getRoutingErrors().get(0)));
        }
        /* Populate up the elevation metadata */
        response.elevationMetadata = new ElevationMetadata();
        response.elevationMetadata.ellipsoidToGeoidDifference = router.graph.ellipsoidToGeoidDifference;
        response.elevationMetadata.geoidElevation = request.geoidElevation;
        response.debugOutput = res.getDebugAggregator().finishedRendering();
    } catch (Exception e) {
        LOG.error("System error", e);
        PlannerError error = new PlannerError();
        error.setMsg(Message.SYSTEM_ERROR);
        response.setError(error);
    }
    /* Log this request if such logging is enabled. */
    if (request != null && router != null && router.requestLogger != null) {
        StringBuilder sb = new StringBuilder();
        String clientIpAddress = grizzlyRequest.getRemoteAddr();
        // sb.append(LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
        sb.append(clientIpAddress);
        sb.append(' ');
        sb.append(request.arriveBy ? "ARRIVE" : "DEPART");
        sb.append(' ');
        sb.append(LocalDateTime.ofInstant(Instant.ofEpochSecond(request.dateTime), ZoneId.systemDefault()));
        sb.append(' ');
        sb.append(request.streetSubRequestModes.getAsStr());
        sb.append(' ');
        sb.append(request.from.lat);
        sb.append(' ');
        sb.append(request.from.lng);
        sb.append(' ');
        sb.append(request.to.lat);
        sb.append(' ');
        sb.append(request.to.lng);
        sb.append(' ');
        if (res != null) {
            for (Itinerary it : res.getTripPlan().itineraries) {
                sb.append(it.durationSeconds);
                sb.append(' ');
            }
        }
        router.requestLogger.info(sb.toString());
    }
    return response;
}
Also used : TripPlanMapper(org.opentripplanner.api.mapping.TripPlanMapper) RoutingService(org.opentripplanner.routing.RoutingService) Itinerary(org.opentripplanner.model.plan.Itinerary) Router(org.opentripplanner.standalone.server.Router) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) PlannerError(org.opentripplanner.api.model.error.PlannerError) RoutingResponse(org.opentripplanner.routing.api.response.RoutingResponse) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with RoutingService

use of org.opentripplanner.routing.RoutingService 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 15 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class GtfsRealtimeFuzzyTripMatcherTest method testMatch.

public void testMatch() throws Exception {
    String feedId = graph.getFeedIds().iterator().next();
    GtfsRealtimeFuzzyTripMatcher matcher = new GtfsRealtimeFuzzyTripMatcher(new RoutingService(graph));
    TripDescriptor trip1 = TripDescriptor.newBuilder().setRouteId("1").setDirectionId(0).setStartTime("06:47:00").setStartDate("20090915").build();
    assertEquals("10W1020", matcher.match(feedId, trip1).getTripId());
    trip1 = TripDescriptor.newBuilder().setRouteId("4").setDirectionId(0).setStartTime("00:02:00").setStartDate("20090915").build();
    assertEquals("40W1890", matcher.match(feedId, trip1).getTripId());
    // Test matching with "real time", when schedule uses time grater than 24:00
    trip1 = TripDescriptor.newBuilder().setRouteId("4").setDirectionId(0).setStartTime("12:00:00").setStartDate("20090915").build();
    // No departure at this time
    assertFalse(trip1.hasTripId());
    trip1 = TripDescriptor.newBuilder().setRouteId("1").setStartTime("06:47:00").setStartDate("20090915").build();
    // Missing direction id
    assertFalse(trip1.hasTripId());
}
Also used : TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) RoutingService(org.opentripplanner.routing.RoutingService)

Aggregations

RoutingService (org.opentripplanner.routing.RoutingService)32 GET (javax.ws.rs.GET)17 Path (javax.ws.rs.Path)16 Stop (org.opentripplanner.model.Stop)13 FeedScopedId (org.opentripplanner.model.FeedScopedId)12 TripPattern (org.opentripplanner.model.TripPattern)9 List (java.util.List)8 ApiStop (org.opentripplanner.api.model.ApiStop)8 Trip (org.opentripplanner.model.Trip)8 HashSet (java.util.HashSet)7 Collectors (java.util.stream.Collectors)7 Collection (java.util.Collection)5 Stream (java.util.stream.Stream)5 AlertMapper (org.opentripplanner.api.mapping.AlertMapper)5 Route (org.opentripplanner.model.Route)5 StopTimesInPattern (org.opentripplanner.model.StopTimesInPattern)5 TripTimeShort (org.opentripplanner.model.TripTimeShort)5 Relay (graphql.relay.Relay)4 ArrayList (java.util.ArrayList)4 Objects (java.util.Objects)4