Search in sources :

Example 46 with Stop

use of org.onebusaway.gtfs.model.Stop in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method setUp.

@Before
public void setUp() {
    graph = new Graph();
    // a 0.1 degree x 0.1 degree square
    tl = new IntersectionVertex(graph, "tl", -74.01, 40.01);
    tr = new IntersectionVertex(graph, "tr", -74.0, 40.01);
    bl = new IntersectionVertex(graph, "bl", -74.01, 40.0);
    br = new IntersectionVertex(graph, "br", -74.00, 40.0);
    top = new StreetEdge(tl, tr, GeometryUtils.makeLineString(-74.01, 40.01, -74.0, 40.01), "top", 1500, StreetTraversalPermission.ALL, false);
    bottom = new StreetEdge(br, bl, GeometryUtils.makeLineString(-74.01, 40.0, -74.0, 40.0), "bottom", 1500, StreetTraversalPermission.ALL, false);
    left = new StreetEdge(bl, tl, GeometryUtils.makeLineString(-74.01, 40.0, -74.01, 40.01), "left", 1500, StreetTraversalPermission.ALL, false);
    right = new StreetEdge(br, tr, GeometryUtils.makeLineString(-74.0, 40.0, -74.0, 40.01), "right", 1500, StreetTraversalPermission.PEDESTRIAN, false);
    @SuppressWarnings("unused") StreetEdge topBack = new StreetEdge(tr, tl, (LineString) top.getGeometry().reverse(), "topBack", 1500, StreetTraversalPermission.ALL, true);
    @SuppressWarnings("unused") StreetEdge bottomBack = new StreetEdge(br, bl, (LineString) bottom.getGeometry().reverse(), "bottomBack", 1500, StreetTraversalPermission.ALL, true);
    leftBack = new StreetEdge(tl, bl, (LineString) left.getGeometry().reverse(), "leftBack", 1500, StreetTraversalPermission.ALL, true);
    rightBack = new StreetEdge(tr, br, (LineString) right.getGeometry().reverse(), "rightBack", 1500, StreetTraversalPermission.ALL, true);
    Stop s1 = new Stop();
    s1.setName("transitVertex 1");
    s1.setLon(-74.005);
    s1.setLat(40.0099999);
    s1.setId(new AgencyAndId("A", "fleem station"));
    Stop s2 = new Stop();
    s2.setName("transitVertex 2");
    s2.setLon(-74.002);
    s2.setLat(40.0099999);
    s2.setId(new AgencyAndId("A", "morx station"));
    station1 = new TransitStop(graph, s1);
    station2 = new TransitStop(graph, s2);
    station1.addMode(TraverseMode.RAIL);
    station2.addMode(TraverseMode.RAIL);
    graph.rebuildVertexAndEdgeIndices();
    // Linkers aren't run otherwise in testNetworkLinker
    graph.hasStreets = true;
    graph.hasTransit = true;
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) LineString(com.vividsolutions.jts.geom.LineString) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Before(org.junit.Before)

Example 47 with Stop

use of org.onebusaway.gtfs.model.Stop in project OpenTripPlanner by opentripplanner.

the class TestOnBoardRouting method testOnBoardRouting.

/**
 * Compute a set of path between two random stop locations in a test GTFS.
 *
 * For each departure/arrival location, compute a normal path (depart alighted). Then re-run the
 * same itinerary but with departure while on-board at a randomly-picked up trip alongside the
 * path.
 *
 * We assert that the two itineraries will arrive at the same time, at the same place, with at
 * least one less boarding, and take a less or equals amount of time.
 */
@SuppressWarnings("deprecation")
public void testOnBoardRouting() throws Exception {
    String feedId = graph.getFeedIds().iterator().next();
    // Seed the random generator to make consistent set of tests
    Random rand = new Random(42);
    // Number of tests to run
    final int NTESTS = 100;
    int n = 0;
    while (true) {
        /* Compute a normal path between two random stops... */
        Vertex origin, destination;
        do {
            /* See FAKE_GTFS for available locations */
            origin = graph.getVertex(feedId + ":" + (char) (65 + rand.nextInt(20)));
            destination = graph.getVertex(feedId + ":" + (char) (65 + rand.nextInt(20)));
        } while (origin.equals(destination));
        /* ...at a random date/time */
        RoutingRequest options = new RoutingRequest();
        options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 5 + rand.nextInt(4), 1 + rand.nextInt(20), 4 + rand.nextInt(10), rand.nextInt(60), 0);
        ShortestPathTree spt;
        GraphPath path;
        options.setRoutingContext(graph, origin, destination);
        spt = aStar.getShortestPathTree(options);
        path = spt.getPath(destination, false);
        if (path == null)
            continue;
        System.out.println("Testing path between " + origin.getLabel() + " and " + destination.getLabel() + " at " + new Date(options.dateTime * 1000));
        long arrivalTime1 = 0L;
        long elapsedTime1 = 0L;
        int numBoardings1 = 0;
        Vertex arrivalVertex1 = null;
        if (verbose)
            System.out.println("PATH 1 ---------------------");
        for (State s : path.states) {
            if (verbose)
                System.out.println(s + " [" + s.getVertex().getClass().getName() + "]");
            arrivalTime1 = s.getTimeSeconds();
            arrivalVertex1 = s.getVertex();
            elapsedTime1 = s.getElapsedTimeSeconds();
            numBoardings1 = s.getNumBoardings();
        }
        /* Get a random transit hop from the computed path */
        Stop end = null;
        PatternStopVertex nextV = null;
        TripTimes tripTimes = null;
        int stopIndex = 0;
        long newStart = 0L;
        int nhop = 0;
        for (State s : path.states) {
            if (s.getVertex() instanceof PatternArriveVertex && s.getBackEdge() instanceof PatternHop)
                nhop++;
        }
        int hop = rand.nextInt(nhop);
        nhop = 0;
        float k = rand.nextFloat();
        for (State s : path.states) {
            Vertex v = s.getVertex();
            if (v instanceof PatternArriveVertex && s.getBackEdge() instanceof PatternHop) {
                if (hop == nhop) {
                    PatternArriveVertex pav = (PatternArriveVertex) v;
                    end = pav.getStop();
                    nextV = pav;
                    PatternHop phe = (PatternHop) s.getBackEdge();
                    stopIndex = phe.getStopIndex();
                    tripTimes = s.getTripTimes();
                    int hopDuration = tripTimes.getRunningTime(stopIndex);
                    /*
                         * New start time at k% of hop. Note: do not try to make: round(time +
                         * k.hop) as it will be off few seconds due to floating-point rounding
                         * errors.
                         */
                    newStart = s.getBackState().getTimeSeconds() + Math.round(hopDuration * k);
                    break;
                }
                nhop++;
            }
        }
        System.out.println("Boarded depart: trip=" + tripTimes.trip + ", nextStop=" + nextV.getStop() + " stopIndex=" + stopIndex + " startTime=" + new Date(newStart * 1000L));
        /* And use it for onboard departure */
        double lat = end.getLat();
        // Mock location, not really important here.
        double lon = end.getLon();
        OnboardDepartVertex onboardOrigin = new OnboardDepartVertex("OnBoard_Origin", lat, lon);
        @SuppressWarnings("unused") OnBoardDepartPatternHop currentHop = new OnBoardDepartPatternHop(onboardOrigin, nextV, tripTimes, options.rctx.serviceDays.get(1), stopIndex, k);
        options.dateTime = newStart;
        options.setRoutingContext(graph, onboardOrigin, destination);
        spt = aStar.getShortestPathTree(options);
        /* Re-compute a new path starting boarded */
        GraphPath path2 = spt.getPath(destination, false);
        assertNotNull(path2);
        if (verbose)
            System.out.println("PATH 2 ---------------------");
        long arrivalTime2 = 0L;
        long elapsedTime2 = 0L;
        int numBoardings2 = 0;
        Vertex arrivalVertex2 = null;
        for (State s : path2.states) {
            if (verbose)
                System.out.println(s + " [" + s.getVertex().getClass().getName() + "]");
            arrivalTime2 = s.getTimeSeconds();
            arrivalVertex2 = s.getVertex();
            elapsedTime2 = s.getElapsedTimeSeconds();
            numBoardings2 = s.getNumBoardings();
        }
        /* Arrival time and vertex *must* match */
        assertEquals(arrivalTime1, arrivalTime2);
        assertEquals(arrivalVertex1, destination);
        assertEquals(arrivalVertex2, destination);
        /* On-board *must* be shorter in time */
        assertTrue(elapsedTime2 <= elapsedTime1);
        /* On-board *must* have less boardings */
        assertTrue(numBoardings2 < numBoardings1);
        /* Cleanup edges */
        for (Edge edge : onboardOrigin.getOutgoing()) {
            graph.removeEdge(edge);
        }
        n++;
        if (n > NTESTS)
            break;
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) OnboardDepartVertex(org.opentripplanner.routing.vertextype.OnboardDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) PatternStopVertex(org.opentripplanner.routing.vertextype.PatternStopVertex) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath) OnboardDepartVertex(org.opentripplanner.routing.vertextype.OnboardDepartVertex) Date(java.util.Date) Random(java.util.Random) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) OnBoardDepartPatternHop(org.opentripplanner.routing.edgetype.OnBoardDepartPatternHop) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) PatternStopVertex(org.opentripplanner.routing.vertextype.PatternStopVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) OnBoardDepartPatternHop(org.opentripplanner.routing.edgetype.OnBoardDepartPatternHop) Edge(org.opentripplanner.routing.graph.Edge)

Example 48 with Stop

use of org.onebusaway.gtfs.model.Stop in project OpenTripPlanner by opentripplanner.

the class TestStopMatcher method testStopMatcher.

/**
 * Test different stop matchers
 */
public void testStopMatcher() {
    Stop s1 = new Stop();
    s1.setId(new AgencyAndId("A1", "42"));
    Stop s2 = new Stop();
    s2.setId(new AgencyAndId("A1", "43"));
    StopMatcher emptyMatcher = StopMatcher.emptyMatcher();
    assertFalse(emptyMatcher.matches(s1));
    assertFalse(emptyMatcher.matches(s2));
    StopMatcher matcherS1 = StopMatcher.parse("A1:42");
    assertTrue(matcherS1.matches(s1));
    assertFalse(matcherS1.matches(s2));
    StopMatcher matcherS2 = StopMatcher.parse("A1:43");
    assertFalse(matcherS2.matches(s1));
    assertTrue(matcherS2.matches(s2));
    StopMatcher matcherS1S2 = StopMatcher.parse("A1:42,A1:43");
    assertTrue(matcherS1S2.matches(s1));
    assertTrue(matcherS1S2.matches(s2));
    StopMatcher nullList = StopMatcher.parse(null);
    assertTrue(nullList.isEmpty());
    StopMatcher emptyList = StopMatcher.parse("");
    assertTrue(emptyList.isEmpty());
    StopMatcher degenerate = StopMatcher.parse(",,,");
    assertTrue(degenerate.isEmpty());
    boolean thrown = false;
    try {
        @SuppressWarnings("unused") StopMatcher badMatcher = StopMatcher.parse("A1");
    } catch (IllegalArgumentException e) {
        thrown = true;
    }
    assertTrue(thrown);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop)

Example 49 with Stop

use of org.onebusaway.gtfs.model.Stop in project OpenTripPlanner by opentripplanner.

the class TestStopMatcher method testStopMatcherParents.

/**
 * Test different stop matchers including stops with parents
 */
public void testStopMatcherParents() {
    Stop parent = new Stop();
    parent.setId(new AgencyAndId("A1", "10"));
    Stop s1 = new Stop();
    s1.setId(new AgencyAndId("A1", "42"));
    s1.setParentStation("10");
    Stop s2 = new Stop();
    s2.setId(new AgencyAndId("A1", "43"));
    s2.setParentStation("10");
    StopMatcher matcherParent = StopMatcher.parse("A1:10");
    assertTrue(matcherParent.matches(parent));
    assertTrue(matcherParent.matches(s1));
    assertTrue(matcherParent.matches(s2));
    StopMatcher matcherS1 = StopMatcher.parse("A1:42");
    assertFalse(matcherS1.matches(parent));
    assertTrue(matcherS1.matches(s1));
    assertFalse(matcherS1.matches(s2));
    StopMatcher matcherS2 = StopMatcher.parse("A1:43");
    assertFalse(matcherS2.matches(parent));
    assertFalse(matcherS2.matches(s1));
    assertTrue(matcherS2.matches(s2));
    StopMatcher matcherS1S2 = StopMatcher.parse("A1:42,A1:43");
    assertFalse(matcherS1S2.matches(parent));
    assertTrue(matcherS1S2.matches(s1));
    assertTrue(matcherS1S2.matches(s2));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop)

Example 50 with Stop

use of org.onebusaway.gtfs.model.Stop in project OpenTripPlanner by opentripplanner.

the class TestIgnoreRealtimeUpdates method testIgnoreRealtimeUpdates.

public void testIgnoreRealtimeUpdates() throws Exception {
    // Create routing request
    RoutingRequest options = new RoutingRequest();
    // Check that realtime updates are not ignored
    assertFalse(options.ignoreRealtimeUpdates);
    // Create (very simple) new graph
    Graph graph = new Graph();
    Stop stop1 = new Stop();
    stop1.setId(new AgencyAndId("agency", "stop1"));
    Stop stop2 = new Stop();
    stop2.setId(new AgencyAndId("agency", "stop2"));
    Vertex from = new TransitStop(graph, stop1);
    Vertex to = new TransitStop(graph, stop2);
    // Create dummy TimetableSnapshot
    TimetableSnapshot snapshot = new TimetableSnapshot();
    // Mock TimetableSnapshotSource to return dummy TimetableSnapshot
    TimetableSnapshotSource source = mock(TimetableSnapshotSource.class);
    when(source.getTimetableSnapshot()).thenReturn(snapshot);
    graph.timetableSnapshotSource = (source);
    // Create routing context
    RoutingContext rctx = new RoutingContext(options, graph, from, to);
    // Check that the resolver is set as timetable snapshot
    assertNotNull(rctx.timetableSnapshot);
    // Now set routing request to ignore realtime updates
    options.ignoreRealtimeUpdates = (true);
    // Check that realtime updates are ignored
    assertTrue(options.ignoreRealtimeUpdates);
    // Create new routing context
    rctx = new RoutingContext(options, graph, from, to);
    // Check that the timetable snapshot is null in the new routing context
    assertNull(rctx.timetableSnapshot);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TimetableSnapshot(org.opentripplanner.routing.edgetype.TimetableSnapshot) TimetableSnapshotSource(org.opentripplanner.updater.stoptime.TimetableSnapshotSource)

Aggregations

Stop (org.onebusaway.gtfs.model.Stop)160 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)75 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)49 Trip (org.onebusaway.gtfs.model.Trip)40 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)33 StopTime (org.onebusaway.gtfs.model.StopTime)33 Route (org.onebusaway.gtfs.model.Route)28 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)23 Agency (org.onebusaway.gtfs.model.Agency)19 Vertex (org.opentripplanner.routing.graph.Vertex)18 HashMap (java.util.HashMap)14 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)13 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)11 LineString (com.vividsolutions.jts.geom.LineString)10 List (java.util.List)10 GET (javax.ws.rs.GET)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10 GraphPath (org.opentripplanner.routing.spt.GraphPath)10 Coordinate (com.vividsolutions.jts.geom.Coordinate)9