Search in sources :

Example 21 with Itinerary

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

the class LatestDepartureTimeFilterTest method filterOnLatestDepartureTime.

@Test
public void filterOnLatestDepartureTime() {
    // Given:
    Itinerary it = newItinerary(A).bus(32, 0, 60, E).build();
    Instant time = it.firstLeg().startTime.toInstant();
    // When:
    assertTrue(new LatestDepartureTimeFilter(time.minusSeconds(1)).filter(List.of(it)).isEmpty());
    assertFalse(new LatestDepartureTimeFilter(time).filter(List.of(it)).isEmpty());
}
Also used : Instant(java.time.Instant) TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Itinerary(org.opentripplanner.model.plan.Itinerary) Test(org.junit.Test)

Example 22 with Itinerary

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

the class OtpDefaultSortOrderTest method sortStreetBeforeTransitThenTime.

@Test
public void sortStreetBeforeTransitThenTime() {
    Itinerary walk = newItinerary(A, 0).walk(5, G).build();
    Itinerary bicycle = newItinerary(B).bicycle(4, 6, G).build();
    Itinerary bus = newItinerary(C).bus(21, 1, 4, G).build();
    Itinerary rail = newItinerary(D).rail(21, 3, 7, G).build();
    // Eliminate cost
    walk.generalizedCost = bicycle.generalizedCost = bus.generalizedCost = rail.generalizedCost = 0;
    // Depart-after-sort
    result = departAfterSort().filter(List.of(walk, bicycle, bus, rail));
    assertEquals(toStr(walk, bicycle, bus, rail), toStr(result));
    // Arrive-by-sort
    result = arriveBySort().filter(List.of(walk, bicycle, bus, rail));
    assertEquals(toStr(bicycle, walk, rail, bus), toStr(result));
}
Also used : TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Itinerary(org.opentripplanner.model.plan.Itinerary) Test(org.junit.Test)

Example 23 with Itinerary

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

the class OtpDefaultSortOrderTest method sortOnGeneralizedCostVsNumberOfTransfers.

@Test
public void sortOnGeneralizedCostVsNumberOfTransfers() {
    // Best cost, 1 transfer
    Itinerary iA = newItinerary(A).bus(11, 0, 20, C).bus(21, 22, 40, G).build();
    iA.generalizedCost = 1;
    // Same cost, more transfers (2 transfers)
    Itinerary iB = newItinerary(B).bus(11, 0, 10, C).bus(21, 12, 20, D).bus(31, 22, 40, G).build();
    iB.generalizedCost = 1;
    // Worse on cost, better on transfers
    Itinerary iC = newItinerary(C).bus(11, 0, 40, G).build();
    iC.generalizedCost = 100;
    // Verify depart-after sort on generalized-cost, then transfers
    assertEquals(toStr(iA, iB, iC), toStr(departAfterSort().filter(List.of(iB, iC, iA))));
    // Verify arrive-by sort on generalized-cost, then transfers
    assertEquals(toStr(iA, iB, iC), toStr(arriveBySort().filter(List.of(iC, iA, iB))));
}
Also used : TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Itinerary(org.opentripplanner.model.plan.Itinerary) Test(org.junit.Test)

Example 24 with Itinerary

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

the class OtpDefaultSortOrderTest method sortOnGeneralizedCostVsTime.

@Test
public void sortOnGeneralizedCostVsTime() {
    Itinerary iA = newItinerary(A).bus(21, 0, 20, G).build();
    iA.generalizedCost = 1;
    // Better on arrival-time, but worse on cost
    Itinerary iB = newItinerary(B).bus(21, 0, 10, G).build();
    iB.generalizedCost = 100;
    // Better on departure-time, but worse on cost
    Itinerary iC = newItinerary(C).bus(21, 10, 20, G).build();
    iC.generalizedCost = 100;
    // Verify depart-after sort on arrival-time, then cost
    assertEquals(toStr(iB, iA, iC), toStr(departAfterSort().filter(List.of(iB, iA, iC))));
    // Verify arrive-by sort on departure-time, then cost
    assertEquals(toStr(iC, iA, iB), toStr(arriveBySort().filter(List.of(iB, iA, iC))));
}
Also used : TestItineraryBuilder.newItinerary(org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary) Itinerary(org.opentripplanner.model.plan.Itinerary) Test(org.junit.Test)

Example 25 with Itinerary

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

the class GroupByTripIdAndDistanceTest method getKeySetOfLegsByLimitTest.

@Test
public void getKeySetOfLegsByLimitTest() {
    Itinerary i = newItinerary(A).bus(11, 0, 5, B).bus(21, 10, 12, C).bus(31, 20, 23, D).build();
    Leg l1 = i.legs.get(0);
    Leg l2 = i.legs.get(1);
    Leg l3 = i.legs.get(2);
    Double d1 = l1.distanceMeters;
    Double d3 = l3.distanceMeters;
    // These test relay on the internal sort by distance, witch make the implementation
    // a bit simpler, but strictly is not something the method grantees
    assertEquals(List.of(l1), getKeySetOfLegsByLimit(List.of(l1, l2, l3), d1 - 0.01));
    assertEquals(List.of(l1, l3), getKeySetOfLegsByLimit(List.of(l1, l2, l3), d1 + 0.01));
    assertEquals(List.of(l1, l3), getKeySetOfLegsByLimit(List.of(l1, l2, l3), d1 + d3 - 0.01));
    assertEquals(List.of(l1, l3, l2), getKeySetOfLegsByLimit(List.of(l1, l2, l3), d1 + d3 + 0.01));
}
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)

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