Search in sources :

Example 76 with Graph

use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.

the class AddTripPatternTest method testTimetableTrips.

/**
 * Test adding trips with a timetable rather than frequencies
 */
@Test
public void testTimetableTrips() throws Exception {
    AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
    atp.timetables.add(getTimetable(false));
    // get a graph
    Graph g = buildGraphNoTransit();
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    // materialize the trip pattern
    atp.materialize(g);
    // there should be five stops because one point is not a stop
    assertEquals(5, atp.temporaryStops.length);
    // they should all be linked into the graph
    for (int i = 0; i < atp.temporaryStops.length; i++) {
        assertNotNull(atp.temporaryStops[i].sample);
        assertNotNull(atp.temporaryStops[i].sample.v0);
        assertNotNull(atp.temporaryStops[i].sample.v1);
    }
    // no services running: not needed for trips added on the fly.
    TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, new BitSet(), DayOfWeek.WEDNESDAY);
    Scenario scenario = new Scenario(0);
    scenario.modifications = Lists.newArrayList(atp);
    ProfileRequest req = new ProfileRequest();
    req.scenario = scenario;
    req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
    RaptorWorkerData data = new RaptorWorkerData(g, window, req);
    assertEquals(5, data.nStops);
    // make sure we can find the stops
    AStar aStar = new AStar();
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.from = new GenericLocation(39.963417, -82.980799);
    rr.batch = true;
    rr.setRoutingContext(g);
    rr.batch = true;
    ShortestPathTree spt = aStar.getShortestPathTree(rr);
    TIntIntMap stops = data.findStopsNear(spt, g, false, 1.3f);
    // we should have found stops
    assertFalse(stops.isEmpty());
    // ensure that the times made it into the data
    // This is after the first dwell time has been applied
    assertEquals(7 * 3600 + 30, data.timetablesForPattern.get(0).getDeparture(0, 0));
}
Also used : BitSet(java.util.BitSet) AStar(org.opentripplanner.routing.algorithm.AStar) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TIntIntMap(gnu.trove.map.TIntIntMap) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 77 with Graph

use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.

the class RoutersTest method testRouters.

@Test
public void testRouters() {
    OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
    otpServer.getGraphService().registerGraph("", new MemoryGraphSource(null, new Graph()));
    otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("", new Graph()));
    otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "A", 0, 0, 0));
    otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "B", 0, 1, 0));
    otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "C", 1, 1, 0));
    // this needs to be added since convex hull isn't lazy loaded anymore
    otpServer.getGraphService().getRouter("A").graph.calculateConvexHull();
    otpServer.getGraphService().getRouter("").graph.calculateConvexHull();
    // this needs to be added since it is otherwise calculated during OSM/Transit loading
    // which doesn't happen in this test
    otpServer.getGraphService().getRouter("A").graph.calculateEnvelope();
    otpServer.getGraphService().getRouter("").graph.calculateEnvelope();
    Routers routerApi = new Routers();
    routerApi.otpServer = otpServer;
    RouterList routers = routerApi.getRouterIds();
    assertEquals(2, routers.routerInfo.size());
    RouterInfo router0 = routers.routerInfo.get(0);
    RouterInfo router1 = routers.routerInfo.get(1);
    RouterInfo otherRouter;
    RouterInfo defaultRouter;
    if (router0.routerId.equals("")) {
        defaultRouter = router0;
        otherRouter = router1;
    } else {
        defaultRouter = router1;
        otherRouter = router0;
    }
    assertEquals("", defaultRouter.routerId);
    assertEquals("A", otherRouter.routerId);
    assertTrue(otherRouter.polygon.getArea() > 0);
}
Also used : GraphService(org.opentripplanner.routing.services.GraphService) ExitVertex(org.opentripplanner.routing.vertextype.ExitVertex) CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) Graph(org.opentripplanner.routing.graph.Graph) OTPServer(org.opentripplanner.standalone.OTPServer) MemoryGraphSource(org.opentripplanner.routing.impl.MemoryGraphSource) RouterList(org.opentripplanner.api.model.RouterList) RouterInfo(org.opentripplanner.api.model.RouterInfo) Test(org.junit.Test)

Example 78 with Graph

use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.

the class AlertPatchTest method setUp.

public void setUp() throws Exception {
    aStar = new AStar();
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    options = new RoutingRequest();
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    graph.index(new DefaultStreetVertexIndexFactory());
    feedId = context.getFeedId().getId();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) GtfsContext(org.opentripplanner.gtfs.GtfsContext) AStar(org.opentripplanner.routing.algorithm.AStar) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) File(java.io.File)

Example 79 with Graph

use of org.opentripplanner.routing.graph.Graph 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 80 with Graph

use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.

the class ConvertToFrequencyTest method testSimpleConversion.

/**
 * The simplest case of frequency conversion: no weird loop routes or anything like that, travel times always same, etc.
 */
@Test
public void testSimpleConversion() throws Exception {
    Graph gg = buildGraphNoTransit();
    addTransit(gg);
    link(gg);
    gg.index(new DefaultStreetVertexIndexFactory());
    ProfileRequest pr1 = new ProfileRequest();
    pr1.date = new LocalDate(2015, 6, 10);
    pr1.fromTime = 7 * 3600;
    pr1.toTime = 9 * 3600;
    pr1.fromLat = pr1.toLat = 39.9621;
    pr1.fromLon = pr1.toLon = -83.0007;
    pr1.accessModes = pr1.egressModes = pr1.directModes = new QualifiedModeSet("WALK");
    pr1.transitModes = new TraverseModeSet("TRANSIT");
    RepeatedRaptorProfileRouter rrpr1 = new RepeatedRaptorProfileRouter(gg, pr1);
    rrpr1.route();
    ProfileRequest pr2 = new ProfileRequest();
    pr2.date = new LocalDate(2015, 6, 10);
    pr2.fromTime = 7 * 3600;
    pr2.toTime = 9 * 3600;
    pr2.fromLat = pr2.toLat = 39.9621;
    pr2.fromLon = pr2.toLon = -83.0007;
    pr2.accessModes = pr2.egressModes = pr2.directModes = new QualifiedModeSet("WALK");
    pr2.transitModes = new TraverseModeSet("TRANSIT");
    ConvertToFrequency ctf = new ConvertToFrequency();
    ctf.groupBy = ConvertToFrequency.ConversionGroup.ROUTE_DIRECTION;
    ctf.routeId = new String[] { "route" };
    ctf.windowStart = 5 * 3600;
    ctf.windowEnd = 10 * 3600;
    pr2.scenario = new Scenario(0);
    pr2.scenario.modifications = Arrays.asList(ctf);
    RepeatedRaptorProfileRouter rrpr2 = new RepeatedRaptorProfileRouter(gg, pr2);
    rrpr2.route();
    assertFalse(rrpr1.raptorWorkerData.hasFrequencies);
    assertTrue(rrpr2.raptorWorkerData.hasFrequencies);
    RaptorWorkerTimetable tt = rrpr2.raptorWorkerData.timetablesForPattern.get(0);
    assertEquals(FakeGraph.FREQUENCY, tt.headwaySecs[0]);
    assertEquals(FakeGraph.TRAVEL_TIME, tt.frequencyTrips[0][2]);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) ConvertToFrequency(org.opentripplanner.analyst.scenario.ConvertToFrequency) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) RaptorWorkerTimetable(org.opentripplanner.profile.RaptorWorkerTimetable) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) Scenario(org.opentripplanner.analyst.scenario.Scenario) Test(org.junit.Test)

Aggregations

Graph (org.opentripplanner.routing.graph.Graph)105 Test (org.junit.Test)39 File (java.io.File)28 Vertex (org.opentripplanner.routing.graph.Vertex)27 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)24 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)20 Edge (org.opentripplanner.routing.graph.Edge)19 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)14 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)14 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)13 GTFSPatternHopFactory (org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory)13 GraphPath (org.opentripplanner.routing.spt.GraphPath)13 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)13 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)11 ArrayList (java.util.ArrayList)10 Before (org.junit.Before)10 Trip (org.onebusaway.gtfs.model.Trip)9