Search in sources :

Example 26 with Itinerary

use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.

the class GroupByTripIdAndDistanceTest method calculateTotalDistanceTest.

@Test
public void calculateTotalDistanceTest() {
    Itinerary i = newItinerary(A).bus(21, 1, 2, B).walk(2, C).bus(31, 5, 7, D).build();
    Leg l1 = i.legs.get(0);
    Leg l2 = i.legs.get(1);
    Leg l3 = i.legs.get(2);
    // 3 minutes on a bus
    double expectedDistanceRidingABus = BUS_SPEED * 3 * 60;
    // 2 minute walking
    double expectedDistanceWalking = WALK_SPEED * 2 * 60;
    // total
    double expectedDistance = expectedDistanceRidingABus + expectedDistanceWalking;
    assertEquals(expectedDistanceRidingABus, calculateTotalDistance(List.of(l1, l3)), 0.001);
    assertEquals(expectedDistanceWalking, calculateTotalDistance(List.of(l2)), 0.001);
    assertEquals(expectedDistance, calculateTotalDistance(List.of(l1, l2, l3)), 0.001);
}
Also used : Itinerary(org.opentripplanner.model.plan.Itinerary) TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Leg(org.opentripplanner.model.plan.Leg) Test(org.junit.Test)

Example 27 with Itinerary

use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.

the class TestIntermediatePlaces method handleRequest.

private void handleRequest(GenericLocation from, GenericLocation to, GenericLocation[] via, TraverseModeSet modes, boolean arriveBy) {
    RoutingRequest request = new RoutingRequest(modes);
    request.setDateTime("2016-04-20", "13:00", timeZone);
    request.setArriveBy(arriveBy);
    request.from = from;
    request.to = to;
    for (GenericLocation intermediateLocation : via) {
        request.addIntermediatePlace(intermediateLocation);
    }
    List<GraphPath> paths = graphPathFinder.graphPathFinderEntryPoint(request);
    assertNotNull(paths);
    assertFalse(paths.isEmpty());
    List<Itinerary> itineraries = GraphPathToItineraryMapper.mapItineraries(paths, request);
    TripPlan plan = TripPlanMapper.mapTripPlan(request, itineraries);
    assertLocationIsVeryCloseToPlace(from, plan.from);
    assertLocationIsVeryCloseToPlace(to, plan.to);
    assertTrue(1 <= plan.itineraries.size());
    for (Itinerary itinerary : plan.itineraries) {
        validateIntermediatePlacesVisited(itinerary, via);
        assertTrue(via.length < itinerary.legs.size());
        validateLegsTemporally(request, itinerary);
        validateLegsSpatially(plan, itinerary);
        if (modes.contains(TraverseMode.TRANSIT)) {
            assert itinerary.transitTimeSeconds > 0;
        }
    }
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) Itinerary(org.opentripplanner.model.plan.Itinerary) TripPlan(org.opentripplanner.model.plan.TripPlan) GenericLocation(org.opentripplanner.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest)

Example 28 with Itinerary

use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.

the class RoutingWorker method routeTransit.

private Collection<Itinerary> routeTransit(Router router) {
    request.setRoutingContext(router.graph);
    if (request.modes.transitModes.isEmpty()) {
        return Collections.emptyList();
    }
    if (!router.graph.transitFeedCovers(request.dateTime)) {
        throw new RoutingValidationException(List.of(new RoutingError(RoutingErrorCode.OUTSIDE_SERVICE_PERIOD, InputField.DATE_TIME)));
    }
    TransitLayer transitLayer = request.ignoreRealtimeUpdates ? router.graph.getTransitLayer() : router.graph.getRealtimeTransitLayer();
    RaptorRoutingRequestTransitData requestTransitDataProvider;
    requestTransitDataProvider = new RaptorRoutingRequestTransitData(transitLayer, request.getDateTime().toInstant(), ADDITIONAL_SEARCH_DAYS_BEFORE_TODAY, ADDITIONAL_SEARCH_DAYS_AFTER_TODAY, request.modes.transitModes, request.rctx.bannedRoutes, request.walkSpeed);
    this.debugAggregator.finishedPatternFiltering();
    // Prepare access/egress transfers
    Collection<AccessEgress> accessTransfers = AccessEgressRouter.streetSearch(request, false, 2000, transitLayer.getStopIndex());
    Collection<AccessEgress> egressTransfers = AccessEgressRouter.streetSearch(request, true, 2000, transitLayer.getStopIndex());
    verifyEgressAccess(accessTransfers, egressTransfers);
    this.debugAggregator.finishedAccessEgress();
    // Prepare transit search
    RaptorRequest<TripSchedule> raptorRequest = RaptorRequestMapper.mapRequest(request, requestTransitDataProvider.getStartOfTime(), accessTransfers, egressTransfers);
    // Route transit
    RaptorResponse<TripSchedule> transitResponse = raptorService.route(raptorRequest, requestTransitDataProvider);
    LOG.debug("Found {} transit itineraries", transitResponse.paths().size());
    LOG.debug("Transit search params used: {}", transitResponse.requestUsed().searchParams());
    this.debugAggregator.finishedRaptorSearch();
    // Create itineraries
    RaptorPathToItineraryMapper itineraryMapper = new RaptorPathToItineraryMapper(transitLayer, requestTransitDataProvider.getStartOfTime(), request);
    FareService fareService = request.getRoutingContext().graph.getService(FareService.class);
    List<Itinerary> itineraries = new ArrayList<>();
    for (Path<TripSchedule> path : transitResponse.paths()) {
        // Convert the Raptor/Astar paths to OTP API Itineraries
        Itinerary itinerary = itineraryMapper.createItinerary(path);
        // fare calculation. We derive the fares from the internal Path objects and add them to the itinerary.
        if (fareService != null) {
            itinerary.fare = fareService.getCost(path, transitLayer);
        }
        itineraries.add(itinerary);
    }
    checkIfTransitConnectionExists(transitResponse);
    // Filter itineraries away that depart after the latest-departure-time for depart after
    // search. These itineraries is a result of time-shifting the access leg and is needed for
    // the raptor to prune the results. These itineraries are often not ideal, but if they
    // pareto optimal for the "next" window, they will appear when a "next" search is performed.
    searchWindowUsedInSeconds = transitResponse.requestUsed().searchParams().searchWindowInSeconds();
    if (!request.arriveBy && searchWindowUsedInSeconds > 0) {
        filterOnLatestDepartureTime = Instant.ofEpochSecond(request.dateTime + searchWindowUsedInSeconds);
    }
    this.debugAggregator.finishedItineraryCreation();
    return itineraries;
}
Also used : RaptorPathToItineraryMapper(org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper) ArrayList(java.util.ArrayList) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) FareService(org.opentripplanner.routing.services.FareService) RoutingValidationException(org.opentripplanner.routing.error.RoutingValidationException) RoutingError(org.opentripplanner.routing.api.response.RoutingError) Itinerary(org.opentripplanner.model.plan.Itinerary) RaptorRoutingRequestTransitData(org.opentripplanner.routing.algorithm.raptor.transit.request.RaptorRoutingRequestTransitData) AccessEgress(org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress) TransitLayer(org.opentripplanner.routing.algorithm.raptor.transit.TransitLayer)

Example 29 with Itinerary

use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.

the class GraphPathToItineraryMapper method mapItineraries.

/**
 * Generates a TripPlan from a set of paths
 */
public static List<Itinerary> mapItineraries(List<GraphPath> paths, RoutingRequest request) {
    List<Itinerary> itineraries = new LinkedList<>();
    for (GraphPath path : paths) {
        Itinerary itinerary = generateItinerary(path, request.locale);
        if (itinerary.legs.isEmpty()) {
            continue;
        }
        itinerary = adjustItinerary(request, itinerary);
        itineraries.add(itinerary);
    }
    return itineraries;
}
Also used : Itinerary(org.opentripplanner.model.plan.Itinerary) GraphPath(org.opentripplanner.routing.spt.GraphPath) LinkedList(java.util.LinkedList)

Example 30 with Itinerary

use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.

the class GraphPathToItineraryMapper method generateItinerary.

/**
 * Generate an itinerary from a {@link GraphPath}. This method first slices the list of states
 * at the leg boundaries. These smaller state arrays are then used to generate legs. Finally the
 * rest of the itinerary is generated based on the complete state array.
 *
 * @param path The graph path to base the itinerary on
 * @return The generated itinerary
 */
public static Itinerary generateItinerary(GraphPath path, Locale requestedLocale) {
    State[] states = new State[path.states.size()];
    State lastState = path.states.getLast();
    states = path.states.toArray(states);
    Edge[] edges = new Edge[path.edges.size()];
    edges = path.edges.toArray(edges);
    Graph graph = path.getRoutingContext().graph;
    State[][] legsStates = sliceStates(states);
    List<Leg> legs = new ArrayList<>();
    for (State[] legStates : legsStates) {
        legs.add(generateLeg(graph, legStates, requestedLocale));
    }
    addWalkSteps(graph, legs, legsStates, requestedLocale);
    boolean first = true;
    for (Leg leg : legs) {
        AlertToLegMapper.addAlertPatchesToLeg(graph, leg, first, requestedLocale);
        first = false;
    }
    setLegPathwayFlag(legs, legsStates);
    Itinerary itinerary = new Itinerary(legs);
    calculateElevations(itinerary, edges);
    itinerary.generalizedCost = (int) lastState.weight;
    return itinerary;
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) ArrayList(java.util.ArrayList) Itinerary(org.opentripplanner.model.plan.Itinerary) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) ElevatorAlightEdge(org.opentripplanner.routing.edgetype.ElevatorAlightEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) RentABikeOnEdge(org.opentripplanner.routing.edgetype.RentABikeOnEdge) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) RentABikeOffEdge(org.opentripplanner.routing.edgetype.RentABikeOffEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Leg(org.opentripplanner.model.plan.Leg)

Aggregations

Itinerary (org.opentripplanner.model.plan.Itinerary)36 Test (org.junit.Test)18 TestItineraryBuilder.newItinerary (org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary)18 ArrayList (java.util.ArrayList)8 Leg (org.opentripplanner.model.plan.Leg)8 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)7 GraphPath (org.opentripplanner.routing.spt.GraphPath)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Comparator (java.util.Comparator)3 RoutingService (org.opentripplanner.routing.RoutingService)3 Scalars (graphql.Scalars)2 DefaultConnection (graphql.relay.DefaultConnection)2 DefaultPageInfo (graphql.relay.DefaultPageInfo)2 Relay (graphql.relay.Relay)2 SimpleListConnection (graphql.relay.SimpleListConnection)2 GraphQLArgument (graphql.schema.GraphQLArgument)2 GraphQLEnumType (graphql.schema.GraphQLEnumType)2 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)2 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)2