Search in sources :

Example 11 with GeometryAndBlockProcessor

use of org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor in project OpenTripPlanner by opentripplanner.

the class TimetableSnapshotTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    Graph graph = new Graph();
    GtfsContext context = GtfsContextBuilder.contextBuilder(ConstantsForTests.FAKE_GTFS).withIssueStoreAndDeduplicator(graph).build();
    GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, context.getCalendarServiceData());
    patternIndex = new HashMap<>();
    for (TripPattern tripPattern : graph.tripPatternForId.values()) {
        for (Trip trip : tripPattern.getTrips()) {
            patternIndex.put(trip.getId(), tripPattern);
        }
    }
}
Also used : GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) Graph(org.opentripplanner.routing.graph.Graph) GtfsContext(org.opentripplanner.gtfs.GtfsContext) BeforeClass(org.junit.BeforeClass)

Example 12 with GeometryAndBlockProcessor

use of org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor in project OpenTripPlanner by opentripplanner.

the class TestAStar method testBasic.

public void testBasic() throws Exception {
    GtfsContext context = contextBuilder(ConstantsForTests.CALTRAIN_GTFS).build();
    Graph gg = new Graph();
    GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
    factory.run(gg);
    gg.putService(CalendarServiceData.class, context.getCalendarServiceData());
    RoutingRequest options = new RoutingRequest();
    ShortestPathTree spt;
    GraphPath path = null;
    String feedId = gg.getFeedIds().iterator().next();
    options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
    options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":Mountain View Caltrain"), true);
    long endTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 13, 29, 0);
    assertEquals(path.getEndTime(), endTime);
    /* test backwards traversal */
    options.setArriveBy(true);
    options.dateTime = endTime;
    options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":Millbrae Caltrain"), true);
    long expectedStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 39, 0);
    assertTrue(path.getStartTime() - expectedStartTime <= 1);
}
Also used : GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest)

Example 13 with GeometryAndBlockProcessor

use of org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor in project OpenTripPlanner by opentripplanner.

the class TestFares method testFareComponent.

public void testFareComponent() throws Exception {
    Graph gg = new Graph();
    GtfsContext context = contextBuilder(ConstantsForTests.FARE_COMPONENT_GTFS).build();
    GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
    factory.run(gg);
    gg.putService(CalendarServiceData.class, context.getCalendarServiceData());
    String feedId = gg.getFeedIds().iterator().next();
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
    ShortestPathTree spt;
    GraphPath path;
    Fare fare;
    List<FareComponent> fareComponents = null;
    FareService fareService = gg.getService(FareService.class);
    Money tenUSD = new Money(new WrappedCurrency("USD"), 1000);
    // A -> B, base case
    options.setRoutingContext(gg, feedId + ":A", feedId + ":B");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":B"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
    // D -> E, null case
    options.setRoutingContext(gg, feedId + ":D", feedId + ":E");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":E"), true);
    // was: fareService.getCost(path);
    fare = null;
    assertNull(fare);
    // A -> C, 2 components in a path
    options.setRoutingContext(gg, feedId + ":A", feedId + ":C");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":C"), true);
    // was:  fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 2);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
    assertEquals(fareComponents.get(1).price, tenUSD);
    assertEquals(fareComponents.get(1).fareId, new FeedScopedId(feedId, "BC"));
    assertEquals(fareComponents.get(1).routes.get(0), new FeedScopedId("agency", "2"));
    // B -> D, 2 fully connected components
    options.setRoutingContext(gg, feedId + ":B", feedId + ":D");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":D"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "BD"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "2"));
    assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "3"));
    // E -> G, missing in between fare
    options.setRoutingContext(gg, feedId + ":E", feedId + ":G");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":G"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "EG"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "5"));
    assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "6"));
    // C -> E, missing fare after
    options.setRoutingContext(gg, feedId + ":C", feedId + ":E");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":E"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "CD"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "3"));
    // D -> G, missing fare before
    options.setRoutingContext(gg, feedId + ":D", feedId + ":G");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":G"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "EG"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "5"));
    assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "6"));
    // A -> D, use individual component parts
    options.setRoutingContext(gg, feedId + ":A", feedId + ":D");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":D"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 2);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
    assertEquals(fareComponents.get(1).price, tenUSD);
    assertEquals(fareComponents.get(1).fareId, new FeedScopedId(feedId, "BD"));
    assertEquals(fareComponents.get(1).routes.get(0), new FeedScopedId("agency", "2"));
    assertEquals(fareComponents.get(1).routes.get(1), new FeedScopedId("agency", "3"));
}
Also used : GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) FareService(org.opentripplanner.routing.services.FareService) Fare(org.opentripplanner.routing.core.Fare) Money(org.opentripplanner.routing.core.Money) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) FeedScopedId(org.opentripplanner.model.FeedScopedId) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) FareComponent(org.opentripplanner.routing.core.FareComponent)

Example 14 with GeometryAndBlockProcessor

use of org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor in project OpenTripPlanner by opentripplanner.

the class TimetableTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    GtfsContext context = contextBuilder(ConstantsForTests.FAKE_GTFS).build();
    graph = new Graph();
    GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, context.getCalendarServiceData());
    patternIndex = new HashMap<>();
    for (TripPattern pattern : graph.tripPatternForId.values()) {
        for (Trip trip : pattern.getTrips()) {
            patternIndex.put(trip.getId(), pattern);
        }
    }
    pattern = patternIndex.get(new FeedScopedId("agency", "1.1"));
    timetable = pattern.scheduledTimetable;
}
Also used : GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) Graph(org.opentripplanner.routing.graph.Graph) GtfsContext(org.opentripplanner.gtfs.GtfsContext) BeforeClass(org.junit.BeforeClass)

Aggregations

GeometryAndBlockProcessor (org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor)14 Graph (org.opentripplanner.routing.graph.Graph)12 GtfsContext (org.opentripplanner.gtfs.GtfsContext)10 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)4 GraphPath (org.opentripplanner.routing.spt.GraphPath)4 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)4 BeforeClass (org.junit.BeforeClass)3 AddTransitModelEntitiesToGraph (org.opentripplanner.graph_builder.module.AddTransitModelEntitiesToGraph)3 Fare (org.opentripplanner.routing.core.Fare)3 Money (org.opentripplanner.routing.core.Money)3 WrappedCurrency (org.opentripplanner.routing.core.WrappedCurrency)3 FareService (org.opentripplanner.routing.services.FareService)3 IOException (java.io.IOException)2 StreetLinkerModule (org.opentripplanner.graph_builder.module.StreetLinkerModule)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)1