Package org.opentripplanner.routing.graph

Examples of org.opentripplanner.routing.graph.Graph$GraphObjectInputStream


public class StreetfulStopLinkerTest {
    @Test
    public final void testStreetfulStopLinker() {
        final double speed = new RoutingRequest().walkSpeed;

        Graph graph = new Graph();

        Stop stopA = new Stop();
        Stop stopB = new Stop();
        Stop stopC = new Stop();
        Stop stopD = new Stop();
        Stop stopE = new Stop();

        stopA.setId(new AgencyAndId("Stop", "A"));
        stopA.setLon(0);
        stopA.setLat(0);
        stopB.setId(new AgencyAndId("Stop", "B"));
        stopB.setLon(0);
        stopB.setLat(3);
        stopC.setId(new AgencyAndId("Stop", "C"));
        stopC.setLon(3);
        stopC.setLat(3);
        stopD.setId(new AgencyAndId("Stop", "D"));
        stopD.setLon(3);
        stopD.setLat(0);
        stopE.setId(new AgencyAndId("Stop", "E"));
        stopE.setLon(2);
        stopE.setLat(2);

        TransitStop transitStopA = new TransitStop(graph, stopA);
        TransitStop transitStopB = new TransitStop(graph, stopB);
        TransitStop transitStopC = new TransitStop(graph, stopC);
        TransitStop transitStopD = new TransitStop(graph, stopD);
        TransitStop transitStopE = new TransitStop(graph, stopE);

        IntersectionVertex intersectionA = new IntersectionVertex(graph, "Intersection A", 1, 1);
        IntersectionVertex intersectionB = new IntersectionVertex(graph, "Intersection B", 1, 2);
        IntersectionVertex intersectionC = new IntersectionVertex(graph, "Intersection C", 2, 2);
        IntersectionVertex intersectionD = new IntersectionVertex(graph, "Intersection D", 2, 1);

        intersectionA.freeFlowing = (true);
        intersectionB.freeFlowing = (true);
        intersectionC.freeFlowing = (true);
        intersectionD.freeFlowing = (true);

        new StreetTransitLink(transitStopA, intersectionA, true);
        new StreetTransitLink(intersectionB, transitStopB, true);
        new StreetTransitLink(intersectionC, transitStopC, true);
        new StreetTransitLink(intersectionD, transitStopD, true);
        new StreetTransitLink(intersectionA, transitStopE, true);

        PackedCoordinateSequence coordinatesAB = new PackedCoordinateSequence.Double(
                new double[]{1, 1, 1, 2}, 2);
        PackedCoordinateSequence coordinatesBC = new PackedCoordinateSequence.Double(
                new double[]{1, 2, 2, 2}, 2);
        PackedCoordinateSequence coordinatesCD = new PackedCoordinateSequence.Double(
                new double[]{2, 2, 2, 1}, 2);
        PackedCoordinateSequence coordinatesAD = new PackedCoordinateSequence.Double(
                new double[]{1, 1, 2, 1}, 2);

        GeometryFactory geometryFactory = new GeometryFactory();

        LineString lineStringAB = new LineString(coordinatesAB, geometryFactory);
        LineString lineStringBC = new LineString(coordinatesBC, geometryFactory);
        LineString lineStringCD = new LineString(coordinatesCD, geometryFactory);
        LineString lineStringAD = new LineString(coordinatesAD, geometryFactory);

        // Powers of 2 avoid complications related to floating point arithmetic
        new StreetEdge(intersectionA, intersectionB, lineStringAB, "Edge AB", 2 * speed,
                StreetTraversalPermission.ALL, false);
        new StreetEdge(intersectionB, intersectionC, lineStringBC, "Edge BC", 4 * speed,
                StreetTraversalPermission.ALL, false);
        new StreetEdge(intersectionC, intersectionD, lineStringCD, "Edge CD", 8 * speed,
                StreetTraversalPermission.ALL, false);
        new StreetEdge(intersectionA, intersectionD, lineStringAD, "Edge AD", 16 * speed,
                StreetTraversalPermission.ALL, false);

        StreetfulStopLinker streetfulStopLinker = new StreetfulStopLinker();

        assertEquals(9, graph.countVertices());
        assertEquals(9, graph.countEdges());

        // The duration of the shortest path (A => E) is 2 seconds
        streetfulStopLinker.maxDuration = 1;
        streetfulStopLinker.buildGraph(graph, null);
        assertEquals(9, graph.countEdges());

        // The duration of the longest path (A => D) is 16 seconds
        streetfulStopLinker.maxDuration = 18;
        streetfulStopLinker.buildGraph(graph, null);
        assertEquals(13, graph.countEdges());
        assertEquals(9, graph.countVertices());

        final double results[] = new double[4];
        for (Edge edge : graph.getEdges()) {
            if (edge instanceof SimpleTransfer) {
                assertEquals(transitStopA, edge.getFromVertex());
                assertNotSame(transitStopA, edge.getToVertex());
                double EPSILON_D = 0.1;
                if (edge.getToVertex().equals(transitStopB)) {
View Full Code Here


    public void testBannedStopGroup() throws ParameterException {
        // Create StopMatcher instance
        StopMatcher stopMatcher = StopMatcher.parse("TriMet:2106,TriMet:65-tc");
        // Find stops in graph
        Graph graph = Context.getInstance().graph;

        Stop stop65_tc = ((TransitStationStop) graph.getVertex("TriMet:65-tc")).getStop();
        assertNotNull(stop65_tc);

        Stop stop12921 = ((TransitStationStop) graph.getVertex("TriMet:12921")).getStop();
        assertNotNull(stop12921);

        Stop stop13132 = ((TransitStationStop) graph.getVertex("TriMet:13132")).getStop();
        assertNotNull(stop13132);

        Stop stop2106 = ((TransitStationStop) graph.getVertex("TriMet:2106")).getStop();
        assertNotNull(stop2106);

        Stop stop2107 = ((TransitStationStop) graph.getVertex("TriMet:2107")).getStop();
        assertNotNull(stop2107);

        // Match stop with id 65-tc
        assertTrue(stopMatcher.matches(stop65_tc));
        // Match stop with id 12921 that has TriMet:65-tc as a parent
View Full Code Here

        TestPlanner planner = new TestPlanner(
                "portland", "45.5264892578125,-122.60479259490967", "45.511622,-122.645564");

        // Replace the transfer table with an empty table
        TransferTable table = new TransferTable();
        Graph graph = Context.getInstance().graph;
        when(graph.getTransferTable()).thenReturn(table);

        // Do the planning
        Response response = planner.getItineraries();
        Itinerary itinerary = response.getPlan().itinerary.get(0);
        // Check the ids of the first two busses
View Full Code Here

        TestPlanner planner = new TestPlanner(
                "portland", "45.5264892578125,-122.60479259490967", "45.511622,-122.645564");

        // Replace the transfer table with an empty table
        TransferTable table = new TransferTable();
        Graph graph = Context.getInstance().graph;
        when(graph.getTransferTable()).thenReturn(table);

        // Do the planning
        Response response = planner.getItineraries();
        Itinerary itinerary = response.getPlan().itinerary.get(0);
        // Check the ids of the first two busses
View Full Code Here

        TestPlanner planner = new TestPlanner(
                "portland", "45.506077,-122.621139", "45.464637,-122.706061");

        // Replace the transfer table with an empty table
        TransferTable table = new TransferTable();
        Graph graph = Context.getInstance().graph;
        when(graph.getTransferTable()).thenReturn(table);

        // Do the planning
        Response response = planner.getItineraries();
        Itinerary itinerary = response.getPlan().itinerary.get(0);
        // Check the ids of the first two busses
        assertEquals("751W1320", itinerary.legs.get(1).tripId);
        assertEquals("91W1350", itinerary.legs.get(3).tripId);

        // Now add a timed transfer between two other busses
        addTripToTripTransferTimeToTable(table, "7528", "9756", "75", "12", "750W1300", "120W1320"
                , StopTransfer.TIMED_TRANSFER);
        // Don't forget to also add a TimedTransferEdge
        Vertex fromVertex = graph.getVertex("TriMet:7528_arrive");
        Vertex toVertex = graph.getVertex("TriMet:9756_depart");
        TimedTransferEdge timedTransferEdge = new TimedTransferEdge(fromVertex, toVertex);

        // Do the planning again
        response = planner.getItineraries();
        itinerary = response.getPlan().itinerary.get(0);
View Full Code Here

    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;

        options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
        options.setRoutingContext(gg, "Caltrain:Millbrae Caltrain", "Caltrain:Mountain View Caltrain");
        spt = aStar.getShortestPathTree(options);
        path = spt.getPath(gg.getVertex("Caltrain: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, "Caltrain:Millbrae Caltrain", "Caltrain:Mountain View Caltrain");
        spt = aStar.getShortestPathTree(options);
        path = spt.getPath(gg.getVertex("Caltrain:Millbrae Caltrain"), true);

        long expectedStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 39, 0);

        assertTrue(path.getStartTime() - expectedStartTime <= 1);

View Full Code Here

        TestPlanner planner = new TestPlanner(
                "portland", "45.506077,-122.621139", "45.464637,-122.706061");

        // Replace the transfer table with an empty table
        TransferTable table = new TransferTable();
        Graph graph = Context.getInstance().graph;
        when(graph.getTransferTable()).thenReturn(table);

        // Do the planning
        Response response = planner.getItineraries();
        Itinerary itinerary = response.getPlan().itinerary.get(0);
        // Check the ids of the first two busses
        assertEquals("751W1320", itinerary.legs.get(1).tripId);
        assertEquals("91W1350", itinerary.legs.get(3).tripId);

        // Now add a timed transfer between two other busses
        addStopToStopTransferTimeToTable(table, "7528", "9756", StopTransfer.TIMED_TRANSFER);
        // Don't forget to also add a TimedTransferEdge
        Vertex fromVertex = graph.getVertex("TriMet:7528_arrive");
        Vertex toVertex = graph.getVertex("TriMet:9756_depart");
        TimedTransferEdge timedTransferEdge = new TimedTransferEdge(fromVertex, toVertex);

        // Do the planning again
        response = planner.getItineraries();
        itinerary = response.getPlan().itinerary.get(0);
View Full Code Here

    }

    public void testMaxTime() {

        Graph graph = ConstantsForTests.getInstance().getPortlandGraph();
        Vertex start = graph.getVertex("TriMet:8371");
        Vertex end = graph.getVertex("TriMet:8374");

        RoutingRequest options = new RoutingRequest();
        long startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 34, 25);
        options.dateTime = startTime;
        // one hour is more than enough time
View Full Code Here

     * Apply an update to a table trip pattern and check whether the update was applied correctly
     */
    private void applyUpdateToTripPattern(TripPattern pattern, String tripId, String stopId,
            int stopSeq, int arrive, int depart, ScheduleRelationship scheduleRelationship,
            int timestamp, ServiceDate serviceDate) throws ParseException {
        Graph graph = Context.getInstance().graph;
        TimetableResolver snapshot = graph.timetableSnapshotSource.getTimetableSnapshot();
        Timetable timetable = snapshot.resolve(pattern, serviceDate);
        TimeZone timeZone = new SimpleTimeZone(-7, "PST");
        long today = serviceDate.getAsDate(timeZone).getTime() / 1000;
        TripDescriptor.Builder tripDescriptorBuilder = TripDescriptor.newBuilder();
View Full Code Here

        alerts[2].setId("2");
        alerts[3].setId("3");
    }

    private AlertPatchServiceImpl getAlertPatchServiceImpl() {
        AlertPatchServiceImpl alertPatchService = new AlertPatchServiceImpl(new Graph());
        return alertPatchService;
    }
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.graph.Graph$GraphObjectInputStream

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.