Search in sources :

Example 91 with Graph

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

the class RoutingContextTest method testSetServiceDays.

@Test
public void testSetServiceDays() throws Exception {
    String feedId = "FEED";
    String agencyId = "AGENCY";
    Agency agency = new Agency();
    agency.setId(agencyId);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    CalendarService calendarService = mock(CalendarService.class);
    // You're probably not supposed to do this to mocks (access their fields directly)
    // But I know of no other way to do this since the mock object has only action-free stub methods.
    routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
    when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("Europe/Budapest"));
    when(graph.getCalendarService()).thenReturn(calendarService);
    when(graph.getFeedIds()).thenReturn(Collections.singletonList("FEED"));
    when(graph.getAgencies(feedId)).thenReturn(Collections.singletonList(agency));
    when(calendarService.getTimeZoneForAgencyId(agencyId)).thenReturn(TimeZone.getTimeZone("Europe/Budapest"));
    when(routingRequest.getSecondsSinceEpoch()).thenReturn(1393750800L, 1396126800L, /* 2014-03-29T22:00:00+01:00 */
    1396132200L, /* 2014-03-29T23:30:00+01:00 */
    1396135800L, 1401696000L, 1414272600L, /* 2014-10-25T23:30:00+02:00 */
    1414276200L, /* 2014-10-26T00:30:00+02:00 */
    1414279800L);
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 3, 1), new ServiceDate(2014, 3, 2), new ServiceDate(2014, 3, 3));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 3, 28), new ServiceDate(2014, 3, 29), new ServiceDate(2014, 3, 30));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 3, 28), new ServiceDate(2014, 3, 29), new ServiceDate(2014, 3, 30));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 3, 29), new ServiceDate(2014, 3, 30), new ServiceDate(2014, 3, 31));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 6, 1), new ServiceDate(2014, 6, 2), new ServiceDate(2014, 6, 3));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 24), new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26), new ServiceDate(2014, 10, 27));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26), new ServiceDate(2014, 10, 27));
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Agency(org.onebusaway.gtfs.model.Agency) Graph(org.opentripplanner.routing.graph.Graph) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) Test(org.junit.Test)

Example 92 with Graph

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

the class SimpleTraversalCostModelTest method before.

@Before
public void before() {
    _graph = new Graph();
    costModel = new SimpleIntersectionTraversalCostModel();
    // Initialize the routing request.
    options = new RoutingRequest();
    options.carSpeed = 1.0;
    options.walkSpeed = 1.0;
    options.carDecelerationSpeed = (2.0);
    options.carAccelerationSpeed = (2.0);
    options.setModes(TraverseModeSet.allModes());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) Before(org.junit.Before)

Example 93 with Graph

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

the class TestGraph method testGetEdgesMultiple.

public void testGetEdgesMultiple() {
    Graph g = new Graph();
    Vertex a = new IntersectionVertex(g, "A", 5, 5);
    Vertex b = new IntersectionVertex(g, "B", 6, 6);
    Vertex c = new IntersectionVertex(g, "C", 3, 2);
    Set<Edge> expectedEdges = new HashSet<Edge>(4);
    expectedEdges.add(new FreeEdge(a, b));
    expectedEdges.add(new FreeEdge(b, c));
    expectedEdges.add(new FreeEdge(c, b));
    expectedEdges.add(new FreeEdge(c, a));
    Set<Edge> edges = new HashSet<Edge>(g.getEdges());
    assertEquals(4, edges.size());
    assertEquals(expectedEdges, edges);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 94 with Graph

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

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

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