Search in sources :

Example 16 with Itinerary

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

the class GtfsTest method plan.

public Leg[] plan(long dateTime, String fromVertex, String toVertex, String onTripId, boolean wheelchairAccessible, boolean preferLeastTransfers, TraverseMode preferredMode, String excludedRoute, String excludedStop, int legCount) {
    final TraverseMode mode = preferredMode != null ? preferredMode : TraverseMode.TRANSIT;
    RoutingRequest routingRequest = new RoutingRequest();
    routingRequest.setNumItineraries(1);
    routingRequest.setArriveBy(dateTime < 0);
    routingRequest.dateTime = Math.abs(dateTime);
    if (fromVertex != null && !fromVertex.isEmpty()) {
        routingRequest.from = LocationStringParser.getGenericLocation(null, feedId.getId() + ":" + fromVertex);
    }
    if (toVertex != null && !toVertex.isEmpty()) {
        routingRequest.to = LocationStringParser.getGenericLocation(null, feedId.getId() + ":" + toVertex);
    }
    if (onTripId != null && !onTripId.isEmpty()) {
        routingRequest.startingTransitTripId = (new FeedScopedId(feedId.getId(), onTripId));
    }
    routingRequest.setRoutingContext(graph);
    routingRequest.setWheelchairAccessible(wheelchairAccessible);
    routingRequest.transferCost = (preferLeastTransfers ? 300 : 0);
    routingRequest.setStreetSubRequestModes(new TraverseModeSet(TraverseMode.WALK, mode));
    // TODO route matcher still using underscores because it's quite nonstandard and should be eliminated from the 1.0 release rather than reworked
    if (excludedRoute != null && !excludedRoute.isEmpty()) {
        routingRequest.setBannedRoutesFromSting(feedId.getId() + "__" + excludedRoute);
    }
    if (excludedStop != null && !excludedStop.isEmpty()) {
        throw new UnsupportedOperationException("Stop banning is not yet implemented in OTP2");
    }
    routingRequest.setOtherThanPreferredRoutesPenalty(0);
    // The walk board cost is set low because it interferes with test 2c1.
    // As long as boarding has a very low cost, waiting should not be "better" than riding
    // since this makes interlining _worse_ than alighting and re-boarding the same line.
    // TODO rethink whether it makes sense to weight waiting to board _less_ than 1.
    routingRequest.setWaitReluctance(1);
    routingRequest.setWalkBoardCost(30);
    List<GraphPath> paths = new GraphPathFinder(router).getPaths(routingRequest);
    List<Itinerary> itineraries = GraphPathToItineraryMapper.mapItineraries(paths, routingRequest);
    // Stored in instance field for use in individual tests
    itinerary = itineraries.get(0);
    assertEquals(legCount, itinerary.legs.size());
    return itinerary.legs.toArray(new Leg[legCount]);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) Itinerary(org.opentripplanner.model.plan.Itinerary) FeedScopedId(org.opentripplanner.model.FeedScopedId) TraverseMode(org.opentripplanner.routing.core.TraverseMode) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder)

Example 17 with Itinerary

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

the class ItineraryFilterChainTest method testFilterChainWithMaxItinerariesFilterSet.

@Test
public void testFilterChainWithMaxItinerariesFilterSet() {
    // Given:
    ItineraryFilter chain;
    Itinerary i1 = newItinerary(A).bus(21, 5, 10, E).build();
    Itinerary i2 = newItinerary(A).bus(31, 7, 12, E).build();
    Itinerary i3 = newItinerary(A).bus(41, 9, 14, E).build();
    // Given a default chain with 'numOfItineraries=2'
    chain = createBuilder(false, false, 2).build();
    assertEquals(List.of(i1, i2), chain.filter(List.of(i1, i2, i3)));
    // Given a default chain with 'numOfItineraries=1'
    chain = createBuilder(false, false, 1).build();
    assertEquals(List.of(i1), chain.filter(List.of(i1, i2, i3)));
    // Given a chain with 'numOfItineraries=1' and 'arriveBy=true'
    chain = createBuilder(true, false, 1).build();
    assertEquals(List.of(i3), chain.filter(List.of(i1, i2, i3)));
}
Also used : Itinerary(org.opentripplanner.model.plan.Itinerary) TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Test(org.junit.Test)

Example 18 with Itinerary

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

the class RemoveTransitIfStreetOnlyIsBetterFilterTest method filterAwayNothingIfNoWalking.

@Test
public void filterAwayNothingIfNoWalking() {
    // Given:
    Itinerary i1 = newItinerary(A).bus(21, 6, 7, E).build();
    Itinerary i2 = newItinerary(A).rail(110, 6, 9, E).build();
    // When:
    List<Itinerary> result = new RemoveTransitIfStreetOnlyIsBetterFilter().filter(List.of(i1, i2));
    // Then:
    assertEquals(toStr(List.of(i1, i2)), toStr(result));
}
Also used : TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Itinerary(org.opentripplanner.model.plan.Itinerary) Test(org.junit.Test)

Example 19 with Itinerary

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

the class TransitGeneralizedCostFilterTest method filter.

@Test
public void filter() {
    // Walk all the way, not touched by the filter even if cost(7200) is higher than transit limit.
    Itinerary i1 = newItinerary(A, 6).walk(60, E).build();
    // Optimal bus ride. Cost: 120 + 3 * 60 = 300  => Limit: 1200
    Itinerary i2 = newItinerary(A).bus(21, 6, 9, E).build();
    // Within cost limit. Cost: 120 + 18 * 60 = 1200
    Itinerary i3 = newItinerary(A).bus(31, 7, 25, E).build();
    // Outside cost limit. Cost: 120 + 19 * 60 = 1260
    Itinerary i4 = newItinerary(A).bus(41, 8, 27, E).build();
    var all = List.of(i1, i2, i3, i4);
    // Expect - i4 to be dropped
    assertEquals(toStr(List.of(i1, i2, i3)), toStr(subject.filter(all)));
}
Also used : TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Itinerary(org.opentripplanner.model.plan.Itinerary) Test(org.junit.Test)

Example 20 with Itinerary

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

the class GroupByFilterTest method aSimpleTestGrpupByMatchingTripIdsNoMerge.

/**
 * This test group by exact trip ids and test that the reduce function
 * works properly. It do not merge any groups.
 */
@Test
public void aSimpleTestGrpupByMatchingTripIdsNoMerge() {
    List<Itinerary> result;
    // Group 1
    Itinerary i1 = newItinerary(A).bus(1, 0, 10, E).build();
    // Group 2, with 2 itineraries with the same id (no need to merge)
    Itinerary i2a = newItinerary(A).bus(2, 1, 11, E).build();
    Itinerary i2b = newItinerary(A).bus(2, 5, 16, E).build();
    List<Itinerary> all = List.of(i1, i2a, i2b);
    // With min Limit = 1, expect the best trips from both groups
    result = createFilter(1).filter(all);
    assertEquals(toStr(List.of(i1, i2a)), toStr(result));
    // With min Limit = 2, also one from each group
    result = createFilter(2).filter(all);
    assertEquals(toStr(List.of(i1, i2a)), toStr(result));
    // With min Limit = 3, we get all 3 itineraries
    result = createFilter(3).filter(all);
    assertEquals(toStr(List.of(i1, i2a, i2b)), toStr(result));
}
Also used : TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Itinerary(org.opentripplanner.model.plan.Itinerary) Test(org.junit.Test)

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