Package org.opentripplanner.routing.spt

Examples of org.opentripplanner.routing.spt.ShortestPathTree


        Vertex start = graph.getVertex("TriMet:8371");
        Vertex end = graph.getVertex("TriMet:8374");
        options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 34, 25);
        // must set routing context _after_ options is fully configured (time)
        options.setRoutingContext(graph, start, end);
        ShortestPathTree spt = null;

        /*
         * The MAX Red, Blue, and Green lines all run along the same trackage between the stops 8374 and 8371. Together, they form the white line. No,
         * wait, that's light. They make a pretty good test case for banned routes, since if one is banned, you can always take another.
         */
        String[][] maxLines = { { "MAX Red Line", null }, { "MAX Blue Line", null },
                { "MAX Green Line", null }, { null, "90" }, { null, "100" }, { null, "200" } };
        for (int i = 0; i < maxLines.length; ++i) {
            String lineName = maxLines[i][0];
            String lineId = maxLines[i][1];
            String routeSpecStr = "TriMet_" + (lineName != null ? lineName : "")
                    + (lineId != null ? "_" + lineId : "");
                options.setBannedRoutes(routeSpecStr);
            spt = aStar.getShortestPathTree(options);
            GraphPath path = spt.getPath(end, true);
            for (State s : path.states) {
                if (s.getBackEdge() instanceof PatternHop) {
                    PatternHop e = (PatternHop) s.getBackEdge();
                    Route route = e.getPattern().route;
                    assertFalse(options.bannedRoutes.matches(route));
View Full Code Here


            while (start == null)
                start = graph.getVertex("TriMet:" + rand.nextInt(10000));
            while (end == null)
                end = graph.getVertex("TriMet:" + rand.nextInt(10000));
            options.setRoutingContext(graph, start, end);
            ShortestPathTree spt = null;

            int n = rand.nextInt(5) + 3;
            for (int j = 0; j < n; j++) {
                spt = aStar.getShortestPathTree(options);
                GraphPath path = spt.getPath(end, true);
                if (path == null || spt == null)
                    break; // No path found
                // List of used [trip,stop index] in the path
                Set<T2<AgencyAndId, BannedStopSet>> usedTripDefs = new HashSet<T2<AgencyAndId, BannedStopSet>>();
                for (State s : path.states) {
View Full Code Here

        GenericAStar aStar = new GenericAStar();

        // it is impossible to get from v1 to v3 by walking
        RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK,TRANSIT"));
        options.setRoutingContext(graph, v1, v3);
        ShortestPathTree tree = aStar.getShortestPathTree(options);

        GraphPath path = tree.getPath(v3, false);
        assertNull(path);

        // or biking + walking (assuming walking bikes is disallowed)
        options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
        options.freezeTraverseMode();
        options.setRoutingContext(graph, v1, v3);
        tree = aStar.getShortestPathTree(options);

        path = tree.getPath(v3, false);
        assertNull(path);

        // so we add a bike share
        BikeRentalStation station = new BikeRentalStation();
        station.id = "id";
        station.name = "station";
        station.x = -77.049;
        station.y = 36.856;
        station.bikesAvailable = 5;
        station.spacesAvailable = 5;
        BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
        new StreetBikeRentalLink(stationVertex, v2);
        new StreetBikeRentalLink(v2, stationVertex);
        Set<String> networks = new HashSet<String>(Arrays.asList("default"));
        new RentABikeOnEdge(stationVertex, stationVertex, networks);
        new RentABikeOffEdge(stationVertex, stationVertex, networks);

        // but we can't get off the bike at v3, so we still fail
        options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
        options.freezeTraverseMode();
        options.setRoutingContext(graph, v1, v3);
        tree = aStar.getShortestPathTree(options);

        path = tree.getPath(v3, false);
        // null is returned because the only state at the target is not final
        assertNull(path);

        BikeRentalStation station2 = new BikeRentalStation();
        station2.id = "id2";
        station2.name = "station2";
        station2.x = -77.049;
        station2.y = 36.857;
        station2.bikesAvailable = 5;
        station2.spacesAvailable = 5;
        BikeRentalStationVertex stationVertex2 = new BikeRentalStationVertex(graph, station2);
        new StreetBikeRentalLink(stationVertex2, v3);
        new StreetBikeRentalLink(v3, stationVertex2);
        new RentABikeOnEdge(stationVertex2, stationVertex2, networks);
        new RentABikeOffEdge(stationVertex2, stationVertex2, networks);

        // now we succeed!
        options = new RoutingRequest();
        new QualifiedModeSetSequence("BICYCLE_RENT,TRANSIT").applyToRequest(options);
        options.setRoutingContext(graph, v1, v3);
        tree = aStar.getShortestPathTree(options);

        path = tree.getPath(v3, false);
        assertNotNull(path);
    }
View Full Code Here

        Vertex stop_a = graph.getVertex("agency:A");
        Vertex stop_c = graph.getVertex("agency:C");
        RoutingRequest options = new RoutingRequest();

        ShortestPathTree spt;
        GraphPath path;

        // non-existing trip
        tripDescriptorBuilder = TripDescriptor.newBuilder();
        tripDescriptorBuilder.setTripId("b");
        tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.CANCELED);
        tripUpdateBuilder = TripUpdate.newBuilder();
        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        tripUpdate = tripUpdateBuilder.build();
        assertFalse(timetable.update(tripUpdate, timeZone, serviceDate));

        // update trip with bad data
        tripDescriptorBuilder = TripDescriptor.newBuilder();
        tripDescriptorBuilder.setTripId("1.1");
        tripDescriptorBuilder.setScheduleRelationship(
                TripDescriptor.ScheduleRelationship.SCHEDULED);
        tripUpdateBuilder = TripUpdate.newBuilder();
        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
        stopTimeUpdateBuilder.setStopSequence(0);
        stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SKIPPED);
        tripUpdate = tripUpdateBuilder.build();
        assertFalse(timetable.update(tripUpdate, timeZone, serviceDate));

        // update trip with non-increasing data
        tripDescriptorBuilder = TripDescriptor.newBuilder();
        tripDescriptorBuilder.setTripId("1.1");
        tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
        tripUpdateBuilder = TripUpdate.newBuilder();
        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
        stopTimeUpdateBuilder.setStopSequence(2);
        stopTimeUpdateBuilder.setScheduleRelationship(
                StopTimeUpdate.ScheduleRelationship.SCHEDULED);
        stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
        stopTimeEventBuilder.setTime(TestUtils.dateInSeconds(
                "America/New_York", 2009, AUGUST, 7, 0, 10, 1));
        stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
        stopTimeEventBuilder.setTime(TestUtils.dateInSeconds(
                "America/New_York", 2009, AUGUST, 7, 0, 10, 0));
        tripUpdate = tripUpdateBuilder.build();
        assertFalse(timetable.update(tripUpdate, timeZone, serviceDate));

        //---
        long startTime = TestUtils.dateInSeconds("America/New_York", 2009, AUGUST, 7, 0, 0, 0);
        long endTime;
        options.dateTime = startTime;

        //---
        options.setRoutingContext(graph, stop_a, stop_c);
        spt = aStar.getShortestPathTree(options);
        path = spt.getPath(stop_c, false);
        assertNotNull(path);
        endTime = startTime + 20 * 60;
        assertEquals(endTime, path.getEndTime());

        // update trip
        tripDescriptorBuilder = TripDescriptor.newBuilder();
        tripDescriptorBuilder.setTripId("1.1");
        tripDescriptorBuilder.setScheduleRelationship(
                TripDescriptor.ScheduleRelationship.SCHEDULED);
        tripUpdateBuilder = TripUpdate.newBuilder();
        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
        stopTimeUpdateBuilder.setStopSequence(1);
        stopTimeUpdateBuilder.setScheduleRelationship(
                StopTimeUpdate.ScheduleRelationship.SCHEDULED);
        stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
        stopTimeEventBuilder.setTime(TestUtils.dateInSeconds(
                "America/New_York", 2009, AUGUST, 7, 0, 2, 0));
        stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
        stopTimeEventBuilder.setTime(TestUtils.dateInSeconds(
                "America/New_York", 2009, AUGUST, 7, 0, 2, 0));
        tripUpdate = tripUpdateBuilder.build();
        assertEquals(20*60, timetable.getTripTimes(trip_1_1_index).getArrivalTime(2));
        assertTrue(timetable.update(tripUpdate, timeZone, serviceDate));
        assertEquals(20*60 + 120, timetable.getTripTimes(trip_1_1_index).getArrivalTime(2));

        //---
        options.setRoutingContext(graph, stop_a, stop_c);
        spt = aStar.getShortestPathTree(options);
        path = spt.getPath(stop_c, false);
        assertNotNull(path);
        endTime = startTime + 20 * 60 + 120;
        assertEquals(endTime, path.getEndTime());

        // cancel trip
        tripDescriptorBuilder = TripDescriptor.newBuilder();
        tripDescriptorBuilder.setTripId("1.1");
        tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.CANCELED);
        tripUpdateBuilder = TripUpdate.newBuilder();
        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        tripUpdate = tripUpdateBuilder.build();
        assertTrue(timetable.update(tripUpdate, timeZone, serviceDate));

        TripTimes tripTimes = timetable.getTripTimes(trip_1_1_index);
        for (int i = 0; i < tripTimes.getNumStops(); i++) {
            assertEquals(TripTimes.UNAVAILABLE, tripTimes.getDepartureTime(i));
            assertEquals(TripTimes.UNAVAILABLE, tripTimes.getArrivalTime(i));
        }

        //---
        options.setRoutingContext(graph, stop_a, stop_c);
        spt = aStar.getShortestPathTree(options);
        path = spt.getPath(stop_c, false);
        assertNotNull(path);
        endTime = startTime + 40 * 60;
        assertEquals(endTime, path.getEndTime());

        // update trip arrival time incorrectly
View Full Code Here

        this.sptServiceFactory = sptServiceFactory;
    }

    @Override
    public List<GraphPath> getPaths(RoutingRequest options) {
        ShortestPathTree spt = sptServiceFactory.instantiate().getShortestPathTree(options);
        if (spt == null) {
            return Collections.emptyList();
        }
        return spt.getPaths();
    }
View Full Code Here

        options.transferSlack = (0);

        long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
        options.dateTime = startTime;

        ShortestPathTree spt;
        GraphPath path;

        // A to B
        options.setRoutingContext(graph, stop_a, stop_b);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(stop_b, false);
        assertNotNull(path);
        assertEquals(6, path.states.size());

        // A to C
        options.setRoutingContext(graph, stop_a, stop_c);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(stop_c, false);
        assertNotNull(path);
        assertEquals(8, path.states.size());

        // A to D (change at C)
        options.setRoutingContext(graph, stop_a, stop_d);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(stop_d, false);
        assertNotNull(path);
        // there are two paths of different lengths
        // both arrive at 40 minutes after midnight
        List<TransitStop> stops = extractStopVertices(path);
        assertEquals(stops.size(), 3);
        assertEquals(stops.get(1), stop_c);
        long endTime = startTime + 40 * 60;
        assertEquals(endTime, path.getEndTime());

        //A to E (change at C)
        options.setRoutingContext(graph, stop_a, stop_e);
        spt = aStar.getShortestPathTree(options);
        path = spt.getPath(stop_e, false);
        assertNotNull(path);
        stops = extractStopVertices(path);
        assertEquals(stops.size(), 3);
        assertEquals(stops.get(1), stop_c);
        endTime = startTime + 70 * 60;
 
View Full Code Here

    public void testRoutingOverMidnight() throws Exception {
        // this route only runs on weekdays
        Vertex stop_g = graph.getVertex("agency:G_depart");
        Vertex stop_h = graph.getVertex("agency: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);
    }
View Full Code Here

        long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 12, 0, 0);
        RoutingRequest options = new RoutingRequest();
        options.dateTime = startTime;
        options.setRoutingContext(graph, stop_o, stop_p);
        ShortestPathTree spt = aStar.getShortestPathTree(options);
        GraphPath path = spt.getPath(stop_p, false);
        assertNotNull(path);
        long endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 12, 10, 0);
        assertEquals(endTime, path.getEndTime());

        startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 12, 0, 1);
        options.dateTime = startTime;
        options.setRoutingContext(graph, stop_o, stop_p);
        spt = aStar.getShortestPathTree(options);
        path = spt.getPath(stop_p, false);
        assertNotNull(path);
        endTime =  TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 15, 10, 0);
        assertEquals(endTime, path.getEndTime());
    }
View Full Code Here

        Vertex stop_b = graph.getVertex("agency:B_depart");
        Vertex stop_g = graph.getVertex("agency:G_arrive");
        RoutingRequest options = new RoutingRequest();
        options.dateTime = startTime;
        options.setRoutingContext(graph, stop_b, stop_g);
        ShortestPathTree spt = aStar.getShortestPathTree(options);
       
        GraphPath path = spt.getPath(stop_g, false);
        assertNotNull(path);
       
        assertTrue("expected to use much later trip due to min transfer time", path.getEndTime() - startTime > 4.5 * 60 * 60);
       
        /* cleanup */
 
View Full Code Here

    public void testTraverseMode() throws Exception {
        Vertex stop_a = graph.getVertex("agency:A_depart");
        Vertex stop_b = graph.getVertex("agency:B_arrive");

        ShortestPathTree spt;

        RoutingRequest options = new RoutingRequest();
        options.setModes(new TraverseModeSet("TRAINISH"));
        options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 0, 0, 0, 0);
        options.setRoutingContext(graph, stop_a, stop_b);
        spt = aStar.getShortestPathTree(options );

        //a to b is bus only
        assertNull(spt.getPath(stop_b, false));
       
        options.setModes(new TraverseModeSet("TRAINISH,BUSISH"));
        spt = aStar.getShortestPathTree(options);

        assertNotNull(spt.getPath(stop_b, false));
    }
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.spt.ShortestPathTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.