Search in sources :

Example 11 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TestAStar method testBasic.

public void testBasic() throws Exception {
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.CALTRAIN_GTFS));
    Graph gg = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(gg);
    gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    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 : 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.core.RoutingRequest) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File)

Example 12 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TestFares method testFareComponent.

public void testFareComponent() throws Exception {
    Graph gg = new Graph();
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FARE_COMPONENT_GTFS));
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(gg);
    gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    String feedId = gg.getFeedIds().iterator().next();
    RoutingRequest options = new RoutingRequest();
    long startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
    options.dateTime = startTime;
    ShortestPathTree spt;
    GraphPath path = null;
    Fare fare = null;
    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);
    fare = fareService.getCost(path);
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new AgencyAndId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new AgencyAndId("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);
    fare = fareService.getCost(path);
    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);
    fare = fareService.getCost(path);
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 2);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new AgencyAndId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new AgencyAndId("agency", "1"));
    assertEquals(fareComponents.get(1).price, tenUSD);
    assertEquals(fareComponents.get(1).fareId, new AgencyAndId(feedId, "BC"));
    assertEquals(fareComponents.get(1).routes.get(0), new AgencyAndId("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);
    fare = fareService.getCost(path);
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new AgencyAndId(feedId, "BD"));
    assertEquals(fareComponents.get(0).routes.get(0), new AgencyAndId("agency", "2"));
    assertEquals(fareComponents.get(0).routes.get(1), new AgencyAndId("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);
    fare = fareService.getCost(path);
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new AgencyAndId(feedId, "EG"));
    assertEquals(fareComponents.get(0).routes.get(0), new AgencyAndId("agency", "5"));
    assertEquals(fareComponents.get(0).routes.get(1), new AgencyAndId("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);
    fare = fareService.getCost(path);
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new AgencyAndId(feedId, "CD"));
    assertEquals(fareComponents.get(0).routes.get(0), new AgencyAndId("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);
    fare = fareService.getCost(path);
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new AgencyAndId(feedId, "EG"));
    assertEquals(fareComponents.get(0).routes.get(0), new AgencyAndId("agency", "5"));
    assertEquals(fareComponents.get(0).routes.get(1), new AgencyAndId("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);
    fare = fareService.getCost(path);
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 2);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new AgencyAndId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new AgencyAndId("agency", "1"));
    assertEquals(fareComponents.get(1).price, tenUSD);
    assertEquals(fareComponents.get(1).fareId, new AgencyAndId(feedId, "BD"));
    assertEquals(fareComponents.get(1).routes.get(0), new AgencyAndId("agency", "2"));
    assertEquals(fareComponents.get(1).routes.get(1), new AgencyAndId("agency", "3"));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) 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) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) FareComponent(org.opentripplanner.routing.core.FareComponent) File(java.io.File)

Example 13 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TestOnBoardRouting method setUp.

public void setUp() throws Exception {
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File)

Example 14 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method setUp.

public void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    feedId = context.getFeedId().getId();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    String[] stops = { feedId + ":A", feedId + ":B", feedId + ":C", feedId + ":D", feedId + ":E", feedId + ":entrance_a", feedId + ":entrance_b" };
    for (int i = 0; i < stops.length; ++i) {
        TransitStop stop = (TransitStop) (graph.getVertex(stops[i]));
        IntersectionVertex front = new IntersectionVertex(graph, "near_1_" + stop.getStopId(), stop.getX() + 0.0001, stop.getY() + 0.0001);
        IntersectionVertex back = new IntersectionVertex(graph, "near_2_" + stop.getStopId(), stop.getX() - 0.0001, stop.getY() - 0.0001);
        StreetEdge street1 = new StreetEdge(front, back, GeometryUtils.makeLineString(stop.getX() + 0.0001, stop.getY() + 0.0001, stop.getX() - 0.0001, stop.getY() - 0.0001), "street", 100, StreetTraversalPermission.ALL, false);
        StreetEdge street2 = new StreetEdge(back, front, GeometryUtils.makeLineString(stop.getX() - 0.0001, stop.getY() - 0.0001, stop.getX() + 0.0001, stop.getY() + 0.0001), "street", 100, StreetTraversalPermission.ALL, true);
    }
    StreetLinkerModule ttsnm = new StreetLinkerModule();
    // Linkers aren't run otherwise
    graph.hasStreets = true;
    graph.hasTransit = true;
    ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) File(java.io.File) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule)

Example 15 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TimetableSnapshotTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    patternIndex = new HashMap<AgencyAndId, TripPattern>();
    for (TransitStopDepart tsd : Iterables.filter(graph.getVertices(), TransitStopDepart.class)) {
        for (TransitBoardAlight tba : Iterables.filter(tsd.getOutgoing(), TransitBoardAlight.class)) {
            if (!tba.boarding)
                continue;
            TripPattern pattern = tba.getPattern();
            for (Trip trip : pattern.getTrips()) {
                patternIndex.put(trip.getId(), pattern);
            }
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File) TransitStopDepart(org.opentripplanner.routing.vertextype.TransitStopDepart) BeforeClass(org.junit.BeforeClass)

Aggregations

GTFSPatternHopFactory (org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory)15 File (java.io.File)14 Graph (org.opentripplanner.routing.graph.Graph)13 GtfsContext (org.opentripplanner.gtfs.GtfsContext)10 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)5 GraphPath (org.opentripplanner.routing.spt.GraphPath)4 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)4 IOException (java.io.IOException)3 BeforeClass (org.junit.BeforeClass)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)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 Trip (org.onebusaway.gtfs.model.Trip)2 StreetLinkerModule (org.opentripplanner.graph_builder.module.StreetLinkerModule)2 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)2 TransitStopDepart (org.opentripplanner.routing.vertextype.TransitStopDepart)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1