Search in sources :

Example 26 with Vertex

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

the class TestPatternHopFactory method testBoardAlight.

public void testBoardAlight() throws Exception {
    Vertex stop_a_depart = graph.getVertex(feedId + ":A_depart");
    Vertex stop_b_depart = graph.getVertex(feedId + ":B_depart");
    assertEquals(1, stop_a_depart.getDegreeOut());
    assertEquals(3, stop_b_depart.getDegreeOut());
    for (Edge e : stop_a_depart.getOutgoing()) {
        assertEquals(TransitBoardAlight.class, e.getClass());
        assertTrue(((TransitBoardAlight) e).boarding);
    }
    TransitBoardAlight pb = (TransitBoardAlight) stop_a_depart.getOutgoing().iterator().next();
    Vertex journey_a_1 = pb.getToVertex();
    assertEquals(1, journey_a_1.getDegreeIn());
    for (Edge e : journey_a_1.getOutgoing()) {
        if (e.getToVertex() instanceof TransitStop) {
            assertEquals(TransitBoardAlight.class, e.getClass());
        } else {
            assertEquals(PatternHop.class, e.getClass());
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 27 with Vertex

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

the class TestPatternHopFactory method testRunForTrain.

public void testRunForTrain() {
    /**
     * This is the notorious Byrd bug: we're going from Q to T at 8:30.
     *  There's a trip from S to T at 8:50 and a second one at 9:50.
     *  To get to S by 8:50, we need to take trip 12.1 from Q to R, and 13.1
     *  from R to S.  If we take the direct-but-slower 11.1, we'll miss
     *  the 8:50 and have to catch the 9:50.
     */
    Vertex destination = graph.getVertex(feedId + ":T");
    RoutingRequest options = new RoutingRequest();
    // test is designed such that transfers must be instantaneous
    options.transferSlack = (0);
    GregorianCalendar startTime = new GregorianCalendar(2009, 11, 2, 8, 30, 0);
    startTime.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    options.dateTime = TestUtils.toSeconds(startTime);
    options.setRoutingContext(graph, feedId + ":Q", destination.getLabel());
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(destination, false);
    long endTime = path.getEndTime();
    Calendar c = new GregorianCalendar();
    c.setTimeInMillis(endTime * 1000L);
    assertTrue(endTime - TestUtils.toSeconds(startTime) < 7200);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 28 with Vertex

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

the class TestPatternHopFactory method testRoutingOverMidnight.

public void testRoutingOverMidnight() throws Exception {
    // this route only runs on weekdays
    Vertex stop_g = graph.getVertex(feedId + ":G_depart");
    Vertex stop_h = graph.getVertex(feedId + ":H_arrive");
    ShortestPathTree spt;
    GraphPath path;
    RoutingRequest options = new RoutingRequest();
    // Friday evening
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 23, 20, 0);
    options.setRoutingContext(graph, stop_g, stop_h);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_h, false);
    assertNotNull(path);
    assertEquals(4, path.states.size());
    // Saturday morning
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 0, 5, 0);
    options.dateTime = startTime;
    options.setRoutingContext(graph, stop_g.getLabel(), stop_h.getLabel());
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_h, false);
    assertNotNull(path);
    assertEquals(4, path.states.size());
    long endTime = path.getEndTime();
    assertTrue(endTime < startTime + 60 * 60);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 29 with Vertex

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

the class TestPatternHopFactory method testTripBikesAllowed.

public void testTripBikesAllowed() throws Exception {
    Vertex stop_a = graph.getVertex(feedId + ":A");
    Vertex stop_b = graph.getVertex(feedId + ":B");
    Vertex stop_c = graph.getVertex(feedId + ":C");
    Vertex stop_d = graph.getVertex(feedId + ":D");
    RoutingRequest options = new RoutingRequest();
    options.modes.setWalk(false);
    options.modes.setBicycle(true);
    options.modes.setTransit(true);
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 0, 0, 0);
    options.setRoutingContext(graph, stop_a, stop_b);
    ShortestPathTree spt;
    GraphPath path;
    // route: bikes allowed, trip: no value
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_b, false);
    assertNotNull(path);
    // route: bikes allowed, trip: bikes not allowed
    options.setRoutingContext(graph, stop_d, stop_c);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_c, false);
    assertNull(path);
    // route: bikes not allowed, trip: bikes allowed
    options.setRoutingContext(graph, stop_c, stop_d);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_d, false);
    assertNotNull(path);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 30 with Vertex

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

the class OnBoardDepartServiceImplTest method testOnBoardDepartureAtArrivalTime.

@Test
public final void testOnBoardDepartureAtArrivalTime() {
    Coordinate[] coordinates = new Coordinate[2];
    coordinates[0] = new Coordinate(0.0, 0.0);
    coordinates[1] = new Coordinate(0.0, 1.0);
    TransitStop station0 = mock(TransitStop.class);
    TransitStop station1 = mock(TransitStop.class);
    PatternDepartVertex depart = mock(PatternDepartVertex.class);
    PatternArriveVertex arrive = mock(PatternArriveVertex.class);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    ServiceDay serviceDay = mock(ServiceDay.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("GMT"));
    when(station0.getX()).thenReturn(coordinates[0].x);
    when(station0.getY()).thenReturn(coordinates[0].y);
    when(station1.getX()).thenReturn(coordinates[1].x);
    when(station1.getY()).thenReturn(coordinates[1].y);
    RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
    AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
    Agency agency = new Agency();
    Route route = new Route();
    ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2);
    StopTime stopDepartTime = new StopTime();
    StopTime stopArriveTime = new StopTime();
    Stop stopDepart = new Stop();
    Stop stopArrive = new Stop();
    Trip trip = new Trip();
    routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
    agency.setId(agencyAndId.getAgencyId());
    route.setId(agencyAndId);
    route.setAgency(agency);
    stopDepart.setId(new AgencyAndId("Station", "0"));
    stopArrive.setId(new AgencyAndId("Station", "1"));
    stopDepartTime.setStop(stopDepart);
    stopDepartTime.setDepartureTime(0);
    stopArriveTime.setArrivalTime(10);
    stopArriveTime.setStop(stopArrive);
    stopTimes.add(stopDepartTime);
    stopTimes.add(stopArriveTime);
    trip.setId(agencyAndId);
    trip.setRoute(route);
    TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    StopPattern stopPattern = new StopPattern(stopTimes);
    TripPattern tripPattern = new TripPattern(route, stopPattern);
    TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
    when(depart.getTripPattern()).thenReturn(tripPattern);
    PatternHop patternHop = new PatternHop(depart, arrive, stopDepart, stopArrive, 0);
    when(graph.getEdges()).thenReturn(Collections.<Edge>singletonList(patternHop));
    when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
    routingRequest.from = new GenericLocation();
    routingRequest.startingTransitTripId = agencyAndId;
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(10);
    when(graph.getVertex("Station_0")).thenReturn(station0);
    when(graph.getVertex("Station_1")).thenReturn(station1);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
    assertEquals(coordinates[1].x, vertex.getX(), 0.0);
    assertEquals(coordinates[1].y, vertex.getY(), 0.0);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) ServiceDay(org.opentripplanner.routing.core.ServiceDay) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) RoutingContext(org.opentripplanner.routing.core.RoutingContext) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) StopPattern(org.opentripplanner.model.StopPattern) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Graph(org.opentripplanner.routing.graph.Graph) Coordinate(com.vividsolutions.jts.geom.Coordinate) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Test(org.junit.Test)

Aggregations

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11