Package org.opentripplanner.routing.core

Examples of org.opentripplanner.routing.core.State


        RoutingRequest options = proto.clone();
        options.setMode(TraverseMode.CUSTOM_MOTOR_VEHICLE);
        options.setRoutingContext(_graph, v1, v2);
       
        State s0 = new State(options);
        State s1 = e1.traverse(s0);
       
        // Should use the speed on the edge.
        double expectedWeight = e1.getDistance() / e1.getCarSpeed();
        long expectedDuration = (long) Math.ceil(expectedWeight);
        assertEquals(expectedDuration, s1.getElapsedTimeSeconds(), 0.0);
        assertEquals(expectedWeight, s1.getWeight(), 0.0);
    }
View Full Code Here


        RoutingRequest forward = proto.clone();
        forward.setMode(TraverseMode.BICYCLE);
        forward.bikeSpeed = 3.0f;
        forward.setRoutingContext(_graph, v0, v2);

        State s0 = new State(forward);
        State s1 = e0.traverse(s0);
        State s2 = e1.traverse(s1);

        RoutingRequest reverse = proto.clone();
        reverse.setMode(TraverseMode.BICYCLE);
        reverse.setArriveBy(true);
        reverse.bikeSpeed = 3.0f;
        reverse.setRoutingContext(_graph, v0, v2);

        State s3 = new State(reverse);
        State s4 = e1.traverse(s3);
        State s5 = e0.traverse(s4);

        assertEquals(73, s2.getElapsedTimeSeconds());
        assertEquals(73, s5.getElapsedTimeSeconds());
    }
View Full Code Here

        RoutingRequest forward = proto.clone();
        forward.setMode(TraverseMode.BICYCLE);
        forward.setRoutingContext(_graph, v0, v2);

        State s0 = new State(forward);
        State s1 = e0.traverse(s0);
        State s2 = e1.traverse(s1);

        RoutingRequest reverse = proto.clone();
        reverse.setMode(TraverseMode.BICYCLE);
        reverse.setArriveBy(true);
        reverse.setRoutingContext(_graph, v0, v2);

        State s3 = new State(reverse);
        State s4 = e1.traverse(s3);
        State s5 = e0.traverse(s4);

        assertEquals(42, s2.getElapsedTimeSeconds());
        assertEquals(42, s5.getElapsedTimeSeconds());
    }
View Full Code Here

        RoutingRequest noPenalty = proto.clone();
        noPenalty.setMode(TraverseMode.BICYCLE);
        noPenalty.setRoutingContext(_graph, v0, v0);

        State s0 = new State(noPenalty);
        State s1 = e0.traverse(s0);
        State s2 = e1.traverse(s1);
        State s3 = e2.traverse(s2);

        RoutingRequest withPenalty = proto.clone();
        withPenalty.bikeSwitchTime = (42);
        withPenalty.bikeSwitchCost = (23);
        withPenalty.setMode(TraverseMode.BICYCLE);
        withPenalty.setRoutingContext(_graph, v0, v0);

        State s4 = new State(withPenalty);
        State s5 = e0.traverse(s4);
        State s6 = e1.traverse(s5);
        State s7 = e2.traverse(s6);

        assertEquals(0, s0.getElapsedTimeSeconds());
        assertEquals(0, s1.getElapsedTimeSeconds());
        assertEquals(0, s2.getElapsedTimeSeconds());
        assertEquals(0, s3.getElapsedTimeSeconds());

        assertEquals(0.0, s0.getWeight(), 0.0);
        assertEquals(0.0, s1.getWeight(), 0.0);
        assertEquals(0.0, s2.getWeight(), 0.0);
        assertEquals(0.0, s3.getWeight(), 0.0);

        assertEquals(0.0, s4.getWeight(), 0.0);
        assertEquals(23.0, s5.getWeight(), 0.0);
        assertEquals(23.0, s6.getWeight(), 0.0);
        assertEquals(23.0, s7.getWeight(), 0.0);

        assertEquals(0, s4.getElapsedTimeSeconds());
        assertEquals(42, s5.getElapsedTimeSeconds());
        assertEquals(42, s6.getElapsedTimeSeconds());
        assertEquals(42, s7.getElapsedTimeSeconds());
    }
View Full Code Here

    @Test
    public void testTurnRestriction() {
        StreetEdge e0 = edge(v0, v1, 50.0, StreetTraversalPermission.ALL);
        StreetEdge e1 = edge(v1, v2, 18.4, StreetTraversalPermission.ALL);
        State state = new State(v2, 0, proto.clone());

        state.getOptions().setArriveBy(true);
        _graph.addTurnRestriction(e1, new TurnRestriction(e1, e0, null, TraverseModeSet.allModes()));

        assertNotNull(e0.traverse(e1.traverse(state)));
    }
View Full Code Here

        // but here we're making them manually.
        pEdge1.visibleTo = options.rctx;
        pEdge2.visibleTo = options.rctx;

        // Traverse both the partial and parent edges.
        State s0 = new State(options);
        State s1 = e1.traverse(s0);
       
        State partialS0 = new State(options);
        State partialS1 = pEdge1.traverse(partialS0);
       
        // Traversal of original and partial edges should yield the same results.
        assertEquals(s1.getTimeSeconds(), partialS1.getTimeSeconds());
        assertEquals(s1.getElapsedTimeSeconds(), partialS1.getElapsedTimeSeconds());
        assertEquals(s1.getWeight(), partialS1.getWeight(), 0.0);
       
        // Now traverse the second partial/parent edge pair.
        State s2 = e2.traverse(s1);
        State partialS2 = pEdge2.traverse(partialS1);
       
        // Same checks as above.
        assertEquals(s2.getTimeSeconds(), partialS2.getTimeSeconds());
        assertEquals(s2.getElapsedTimeSeconds(), partialS2.getElapsedTimeSeconds());
        assertEquals(s2.getWeight(), partialS2.getWeight(), 0.0);
    }
View Full Code Here

        // All intersections take 10 minutes - we'll notice if one isn't counted.
        double turnDurationSecs = 10.0 * 60.0
        options.traversalCostModel = (new DummyCostModel(turnDurationSecs));
        options.turnReluctance = (1.0);
       
        State s0 = new State(options);
        State s1 = e1.traverse(s0);
        State s2 = e2.traverse(s1);
        State s3 = e3.traverse(s2);
       
        Edge partialE2First = intermediate.getIncoming().iterator().next();
        Edge partialE2Second = intermediate.getOutgoing().iterator().next();
        System.out.println(intermediate.getIncoming());
        System.out.println(intermediate.getOutgoing());
       
        State partialS0 = new State(options);
        State partialS1 = e1.traverse(partialS0);
        State partialS2A = partialE2First.traverse(partialS1);
        State partialS2B = partialE2Second.traverse(partialS2A);
        State partialS3 = e3.traverse(partialS2B);
       
        // Should start at the same time.
        assertEquals(s0.getTimeSeconds(), partialS0.getTimeSeconds());
       
        // Time and cost should be the same up to a rounding difference.
        assertTrue(Math.abs(s3.getTimeSeconds() - partialS3.getTimeSeconds()) <= 1);
        assertTrue(Math.abs(s3.getElapsedTimeSeconds() - partialS3.getElapsedTimeSeconds()) <= 1);
        assertTrue(Math.abs(s3.getWeight() - partialS3.getWeight()) <= 1);
       
        // All intersections take 0 seconds now.
        options.traversalCostModel = (new DummyCostModel(0.0));

        State s0NoCost = new State(options);
        State s1NoCost = e1.traverse(s0NoCost);
        State s2NoCost = e2.traverse(s1NoCost);
        State s3NoCost = e3.traverse(s2NoCost);
       
        State partialS0NoCost = new State(options);
        State partialS1NoCost = e1.traverse(partialS0NoCost);
        State partialS2ANoCost = partialE2First.traverse(partialS1NoCost);
        State partialS2BNoCost = partialE2Second.traverse(partialS2ANoCost);
        State partialS3NoCost = e3.traverse(partialS2BNoCost);
       
        // Time and cost should be the same up to a rounding difference.
        assertTrue(Math.abs(s3NoCost.getTimeSeconds() - partialS3NoCost.getTimeSeconds()) <= 1);
        assertTrue(Math.abs(s3NoCost.getElapsedTimeSeconds() - partialS3NoCost.getElapsedTimeSeconds()) <= 1);
        assertTrue(Math.abs(s3NoCost.getWeight() - partialS3NoCost.getWeight()) <= 1);
       
        // Difference in duration and weight between now and before should be
        // entirely due to the crossing of 2 intersections at v2 and v3.
        double expectedDifference = 2 * 10 * 60.0;
        double durationDiff = s3.getTimeSeconds() - s3NoCost.getTimeSeconds();
        double partialDurationDiff = partialS3.getTimeSeconds() - partialS3NoCost.getTimeSeconds();
        assertTrue(Math.abs(durationDiff - expectedDifference) <= 1);
        assertTrue(Math.abs(partialDurationDiff - expectedDifference) <= 1);
       
        // Turn reluctance is 1.0, so weight == duration.
        double weightDiff = s3.getWeight() - s3NoCost.getWeight();
        double partialWeightDiff = partialS3.getWeight() - partialS3NoCost.getWeight();
        assertTrue(Math.abs(weightDiff - expectedDifference) <= 1);
        assertTrue(Math.abs(partialWeightDiff - expectedDifference) <= 1);
    }
View Full Code Here

        return Arrays.asList(TSPPathFinder.findShortestPath(toVertex, fromVertex, paths,
                verticesCopy, time, options));
    }

    private GraphPath joinPaths(List<GraphPath> paths) {
        State lastState = paths.get(0).states.getLast();
        GraphPath newPath = new GraphPath(lastState, false);
        Vertex lastVertex = lastState.getVertex();
        for (GraphPath path : paths.subList(1, paths.size())) {
            lastState = newPath.states.getLast();
            // add a leg-switching state
            LegSwitchingEdge legSwitchingEdge = new LegSwitchingEdge(lastVertex, lastVertex);
            lastState = legSwitchingEdge.traverse(lastState);
View Full Code Here

        options.setDummyRoutingContext(graph);
        GenericDijkstra search = new GenericDijkstra(options);
        search.setSkipEdgeStrategy(new ListedEdgesOnly(edges));
        Set<Edge> usedEdges = new HashSet<Edge>();
        for (Vertex vertex : startingVertices) {
            State state = new State(vertex, options);
            ShortestPathTree spt = search.getShortestPathTree(state);
            for (Vertex endVertex : startingVertices) {
                GraphPath path = spt.getPath(endVertex, false);
                if (path != null) {
                    for (Edge edge : path.edges) {
View Full Code Here

        StateEditor s0e = s0.edit(this);
        s0e.incrementWeight(options.bikeParkCost);
        s0e.incrementTimeInSeconds(options.bikeParkTime);
        s0e.setBackMode(TraverseMode.LEG_SWITCH);
        s0e.setBikeParked(false);
        State s1 = s0e.makeState();
        return s1;
    }
View Full Code Here

TOP

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

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.