Package org.opentripplanner.routing.core

Examples of org.opentripplanner.routing.core.RoutingRequest


    }

    @Test
    public void testBack() {

        RoutingRequest options = new RoutingRequest();
        options.walkSpeed = 1.0;
        options.setArriveBy(true);
        options.setRoutingContext(_graph, _graph.getVertex("56th_24th"),
                _graph.getVertex("leary_20th"));
        ShortestPathTree tree = new GenericAStar().getShortestPathTree(options);

        GraphPath path = tree.getPath(_graph.getVertex("56th_24th"), false);
View Full Code Here


        // is up and over

        int nVertices = graph.getVertices().size();
        int nEdges = graph.getEdges().size();

        RoutingRequest options = new RoutingRequest();

        HashSet<Edge> turns = new HashSet<Edge>();
        turns.add(left);
        turns.add(leftBack);

        StreetLocation start = StreetLocation.createStreetLocation(graph, "start", "start",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()));

        HashSet<Edge> endTurns = new HashSet<Edge>();
        endTurns.add(right);
        endTurns.add(rightBack);

        StreetLocation end = StreetLocation.createStreetLocation(graph, "end", "end",
                filter(endTurns, StreetEdge.class),
                new LinearLocation(0, 0.8).getCoordinate(right.getGeometry()));

        assertTrue(start.getX() < end.getX());
        assertTrue(start.getY() < end.getY());

        List<Edge> extra = end.getExtra();

        assertEquals(4, extra.size());

        long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
        options.dateTime = startTime;
        options.setRoutingContext(graph, br, end);
        options.setMaxWalkDistance(Double.MAX_VALUE);
        ShortestPathTree spt1 = aStar.getShortestPathTree(options);

        GraphPath pathBr = spt1.getPath(end, false);
        assertNotNull("There must be a path from br to end", pathBr);

        options.setRoutingContext(graph, tr, end);
        ShortestPathTree spt2 = aStar.getShortestPathTree(options);

        GraphPath pathTr = spt2.getPath(end, false);
        assertNotNull("There must be a path from tr to end", pathTr);
        assertTrue("path from bottom to end must be longer than path from top to end",
                pathBr.getWeight() > pathTr.getWeight());

        options.setRoutingContext(graph, start, end);
        ShortestPathTree spt = aStar.getShortestPathTree(options);

        GraphPath path = spt.getPath(end, false);
        assertNotNull("There must be a path from start to end", path);

        // the bottom is not part of the shortest path
        for (State s : path.states) {
            assertNotSame(s.getVertex(), graph.getVertex("bottom"));
            assertNotSame(s.getVertex(), graph.getVertex("bottomBack"));
        }

        options.setArriveBy(true);
        options.setRoutingContext(graph, start, end);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(start, false);
        assertNotNull("There must be a path from start to end (looking back)", path);

        // the bottom edge is not part of the shortest path
        for (State s : path.states) {
            assertNotSame(s.getVertex(), graph.getVertex("bottom"));
            assertNotSame(s.getVertex(), graph.getVertex("bottomBack"));
        }

        // Number of vertices and edges should be the same as before after a cleanup.
        options.cleanup();
        assertEquals(nVertices, graph.getVertices().size());
        assertEquals(nEdges, graph.getEdges().size());

        /*
         * Now, the right edge is not bikeable. But the user can walk their bike. So here are some tests that prove (a) that walking bikes works, but
         * that (b) it is not preferred to riding a tiny bit longer.
         */

        options = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
        start = StreetLocation.createStreetLocation(graph, "start1", "start1",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.95).getCoordinate(top.getGeometry()));
        end = StreetLocation.createStreetLocation(graph, "end1", "end1",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.95).getCoordinate(bottom.getGeometry()));

        options.setRoutingContext(graph, start, end);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(start, false);
        assertNotNull("There must be a path from top to bottom along the right", path);

        // the left edge is not part of the shortest path (even though the bike must be walked along the right)
        for (State s : path.states) {
            assertNotSame(s.getVertex(), graph.getVertex("left"));
            assertNotSame(s.getVertex(), graph.getVertex("leftBack"));
        }

        // Number of vertices and edges should be the same as before after a cleanup.
        options.cleanup();
        assertEquals(nVertices, graph.getVertices().size());
        assertEquals(nEdges, graph.getEdges().size());

        start = StreetLocation.createStreetLocation(graph, "start2", "start2",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.55).getCoordinate(top.getGeometry()));
        end = StreetLocation.createStreetLocation(graph, "end2", "end2",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.55).getCoordinate(bottom.getGeometry()));

        options.setRoutingContext(graph, start, end);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(start, false);
        assertNotNull("There must be a path from top to bottom", path);

        // the right edge is not part of the shortest path, e
        for (State s : path.states) {
            assertNotSame(s.getVertex(), graph.getVertex("right"));
            assertNotSame(s.getVertex(), graph.getVertex("rightBack"));
        }

        // Number of vertices and edges should be the same as before after a cleanup.
        options.cleanup();
        assertEquals(nVertices, graph.getVertices().size());
        assertEquals(nEdges, graph.getEdges().size());
    }
View Full Code Here

    }

    @Test
    public void testForwardExtraEdges() {

        RoutingRequest options = new RoutingRequest();
        options.walkSpeed = 1.0;

        StreetLocation fromLocation = new StreetLocation(_graph, "near_shilshole_22nd",
                new Coordinate(-122.385050, 47.666620), "near_shilshole_22nd");
        fromLocation.getExtra().add(
                new SimpleConcreteEdge(fromLocation, _graph.getVertex("shilshole_22nd")));

        StreetLocation toLocation = new StreetLocation(_graph, "near_56th_20th", new Coordinate(
                -122.382347, 47.669518), "near_56th_20th");
        toLocation.getExtra()
                .add(new SimpleConcreteEdge(_graph.getVertex("56th_20th"), toLocation));

        options.setRoutingContext(_graph, fromLocation, toLocation);
        ShortestPathTree tree = new GenericAStar().getShortestPathTree(options);

        GraphPath path = tree.getPath(toLocation, false);

        List<State> states = path.states;
View Full Code Here

    }

    @Test
    public void testBackExtraEdges() {

        RoutingRequest options = new RoutingRequest();
        options.walkSpeed = 1.0;
        options.setArriveBy(true);

        StreetLocation fromLocation = new StreetLocation(_graph, "near_shilshole_22nd",
                new Coordinate(-122.385050, 47.666620), "near_shilshole_22nd");
        fromLocation.getExtra().add(
                new SimpleConcreteEdge(fromLocation, _graph.getVertex("shilshole_22nd")));

        StreetLocation toLocation = new StreetLocation(_graph, "near_56th_20th", new Coordinate(
                -122.382347, 47.669518), "near_56th_20th");
        toLocation.getExtra()
                .add(new SimpleConcreteEdge(_graph.getVertex("56th_20th"), toLocation));

        options.setRoutingContext(_graph, fromLocation, toLocation);
        ShortestPathTree tree = new GenericAStar().getShortestPathTree(options);

        GraphPath path = tree.getPath(fromLocation, false);

        List<State> states = path.states;
View Full Code Here

        assertEquals("near_56th_20th", states.get(8).getVertex().getLabel());
    }

    @Test
    public void testMultipleTargets() {
        RoutingRequest options = new RoutingRequest();
        options.walkSpeed = 1.0;
        options.batch = true;
        options.setRoutingContext(_graph, _graph.getVertex("56th_24th"), _graph.getVertex("leary_20th"));

        Set<Vertex> targets = new HashSet<Vertex>();
        targets.add(_graph.getVertex("shilshole_22nd"));
        targets.add(_graph.getVertex("market_russell"));
        targets.add(_graph.getVertex("56th_20th"));
View Full Code Here

        assertEquals(nVertices, graph.getVertices().size());
        assertEquals(nEdges, graph.getEdges().size());
    }
   
    public void testRouteToSameEdge() {
        RoutingRequest options = new RoutingRequest();

        HashSet<Edge> turns = new HashSet<Edge>();
        turns.add(left);
        turns.add(leftBack);
       
        StreetLocation start = StreetLocation.createStreetLocation(graph, "start", "start",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()));

        StreetLocation end = StreetLocation.createStreetLocation(graph, "end", "end",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()));

        assertEquals(start.getX(), end.getX());
        assertTrue(start.getY() < end.getY());

        List<Edge> extra = end.getExtra();

        assertEquals(4, extra.size());

        long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
        options.dateTime = startTime;
        options.setRoutingContext(graph, start, end);
        options.setMaxWalkDistance(Double.MAX_VALUE);
        ShortestPathTree spt = aStar.getShortestPathTree(options);

        GraphPath path = spt.getPath(end, false);
        assertNotNull("There must be a path from start to end", path);       
        assertEquals(1, path.edges.size());
View Full Code Here

        assertNotNull("There must be a path from start to end", path);       
        assertEquals(1, path.edges.size());
    }

    public void testRouteToSameEdgeBackwards() {
        RoutingRequest options = new RoutingRequest();

        // Sits only on the leftmost edge, not on its reverse.
        HashSet<Edge> turns = new HashSet<Edge>();
        turns.add(left);

        StreetLocation start = StreetLocation.createStreetLocation(graph, "start", "start",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()));
       
        StreetLocation end = StreetLocation.createStreetLocation(graph, "end", "end",
                filter(turns, StreetEdge.class),
                new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()));

        assertEquals(start.getX(), end.getX());
        assertTrue(start.getY() > end.getY());

        List<Edge> extra = end.getExtra();
        assertEquals(2, extra.size());

        long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
        options.dateTime = startTime;
        options.setRoutingContext(graph, start, end);
        options.setMaxWalkDistance(Double.MAX_VALUE);
        ShortestPathTree spt = aStar.getShortestPathTree(options);

        GraphPath path = spt.getPath(end, false);
        assertNotNull("There must be a path from start to end", path);       
        assertTrue(path.edges.size() > 1);
View Full Code Here

    public void testBannedRoutes() {

        Graph graph = ConstantsForTests.getInstance().getPortlandGraph();

        RoutingRequest options = new RoutingRequest();
        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();
View Full Code Here

        Graph graph = ConstantsForTests.getInstance().getPortlandGraph();
        Random rand = new Random(seed);

        for (int i = 0; i < 20; i++) {
            RoutingRequest options = new RoutingRequest();
            options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 34,
                    25);
            // Pick two random locations
            Vertex start = null;
            Vertex end = null;
            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);
View Full Code Here

                -77.0492, 38.858), "S. Crystal Dr", 87, StreetTraversalPermission.BICYCLE, false);

        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

TOP

Related Classes of org.opentripplanner.routing.core.RoutingRequest

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.