Package org.opentripplanner.routing.core

Examples of org.opentripplanner.routing.core.State


        }
    }

    @Override
    public List<State> getStates(Vertex dest) {
        State s = states.get(dest);
        if (s == null)
            return Collections.emptyList();
        else
            return Arrays.asList(s); // single-element array-backed list
    }
View Full Code Here


        return states.get(dest);
    }

    @Override
    public boolean visit(State s) {
        final State existing = states.get(s.getVertex());
        return (s == existing);
    }
View Full Code Here

        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(stop_e, true);
        assertNotNull(path);
        // expect no notes because we are during the break
        State noAlertPatchesState = path.states.get(1);
        Edge noAlertPatchesEdge = noAlertPatchesState.getBackEdge();
        HashSet<Alert> noAlertPatchesAlerts = new HashSet<Alert>();
        for (AlertPatch alertPatch : graph.getAlertPatches(noAlertPatchesEdge)) {
            if (alertPatch.displayDuring(noAlertPatchesState)) {
                noAlertPatchesAlerts.add(alertPatch.getAlert());
            }
        }
        assertEquals(new HashSet<Alert>(), noAlertPatchesAlerts);

        // now a trip during the second period
        options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 8, 0, 0);
        options.setRoutingContext(graph, stop_a, stop_e);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(stop_e, false); // do not optimize because we want the first trip
        assertNotNull(path);
        HashSet<Alert> expectedNotes = new HashSet<Alert>();
        expectedNotes.add(note1);
        State oneAlertPatchState = path.states.get(1);
        Edge oneAlertPatchEdge = oneAlertPatchState.getBackEdge();
        HashSet<Alert> oneAlertPatchAlerts = new HashSet<Alert>();
        for (AlertPatch alertPatch : graph.getAlertPatches(oneAlertPatchEdge)) {
            if (alertPatch.displayDuring(oneAlertPatchState)) {
                oneAlertPatchAlerts.add(alertPatch.getAlert());
            }
View Full Code Here

        options.walkReluctance = 1;

        options.setTriangleSafetyFactor(0);
        options.setTriangleSlopeFactor(0);
        options.setTriangleTimeFactor(1);
        State startState = new State(v1, options);
        State result = testStreet.traverse(startState);
        double timeWeight = result.getWeight();
        double expectedTimeWeight = slopeSpeedLength / options.getSpeed(TraverseMode.BICYCLE);
        assertTrue(Math.abs(expectedTimeWeight - timeWeight) < 0.00001);

        options.setTriangleSafetyFactor(0);
        options.setTriangleSlopeFactor(1);
        options.setTriangleTimeFactor(0);
        startState = new State(v1, options);
        result = testStreet.traverse(startState);
        double slopeWeight = result.getWeight();
        double expectedSlopeWeight = slopeWorkLength / options.getSpeed(TraverseMode.BICYCLE);
        assertTrue(Math.abs(expectedSlopeWeight - slopeWeight) < 0.00001);
        assertTrue(length * 1.5 / options.getSpeed(TraverseMode.BICYCLE) < slopeWeight);
        assertTrue(length * 1.5 * 10 / options.getSpeed(TraverseMode.BICYCLE) > slopeWeight);

        options.setTriangleSafetyFactor(1);
        options.setTriangleSlopeFactor(0);
        options.setTriangleTimeFactor(0);
        startState = new State(v1, options);
        result = testStreet.traverse(startState);
        double safetyWeight = result.getWeight();
        double slopeSafety = costs.slopeSafetyCost;
        double expectedSafetyWeight = (trueLength * 0.74 + slopeSafety) / options.getSpeed(TraverseMode.BICYCLE);
        assertTrue(Math.abs(expectedSafetyWeight - safetyWeight) < 0.00001);

        final double ONE_THIRD = 1/3.0;
        options.setTriangleSafetyFactor(ONE_THIRD);
        options.setTriangleSlopeFactor(ONE_THIRD);
        options.setTriangleTimeFactor(ONE_THIRD);
        startState = new State(v1, options);
        result = testStreet.traverse(startState);
        double averageWeight = result.getWeight();
        assertTrue(Math.abs(safetyWeight * ONE_THIRD + slopeWeight * ONE_THIRD + timeWeight * ONE_THIRD - averageWeight) < 0.00000001);

    }
View Full Code Here

        // The alert should be preserved
        // traverse the FreeEdge from the StreetLocation to the new IntersectionVertex
        RoutingRequest req = new RoutingRequest();
        req.setMaxWalkDistance(Double.MAX_VALUE);
        State traversedOne = new State((Vertex) start, req);
        State currentState;
        for (Edge e : start.getOutgoing()) {
            currentState = e.traverse(traversedOne);
            if (currentState != null) {
                traversedOne = currentState;
                break;
            }
        }

        assertEquals(alerts, graph.streetNotesService.getNotes(traversedOne));
        assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
        assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());

        // now, make sure wheelchair alerts are preserved
        Alert wheelchairAlert = Alert.createSimpleAlerts("This is the wheelchair alert");
        Set<Alert> wheelchairAlerts = new HashSet<>();
        wheelchairAlerts.add(wheelchairAlert);

        graph.streetNotesService.removeStaticNotes(left);
        graph.streetNotesService.removeStaticNotes(leftBack);
        graph.streetNotesService.addStaticNote(left, wheelchairAlert,
                StreetNotesService.WHEELCHAIR_MATCHER);
        graph.streetNotesService.addStaticNote(leftBack, wheelchairAlert,
                StreetNotesService.WHEELCHAIR_MATCHER);

        req.setWheelchairAccessible(true);

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

        traversedOne = new State((Vertex) start, req);
        for (Edge e : start.getOutgoing()) {
            currentState = e.traverse(traversedOne);
            if (currentState != null) {
                traversedOne = currentState;
                break;
View Full Code Here

    @Test
    public final void testTerminalFor() {
        // Create a long distance path parser
        Parser parser = new Parser();

        State emptyState = mock(State.class);

        State streetState = mock(State.class);
        when(streetState.getBackEdge()).thenReturn(mock(StreetEdge.class));

        State linkState = mock(State.class);
        when(linkState.getBackEdge()).thenReturn(mock(StreetTransitLink.class));

        State stationState = mock(State.class);
        when(stationState.getBackEdge()).thenReturn(mock(PreAlightEdge.class));

        State onboardState = mock(State.class);
        when(onboardState.getBackEdge()).thenReturn(mock(PatternHop.class));

        State transferState = mock(State.class);
        when(transferState.getBackEdge()).thenReturn(mock(TransferEdge.class));

        State stationStopState = mock(State.class);
        when(stationStopState.getBackEdge()).thenReturn(mock(StationStopEdge.class));
        when(stationStopState.getVertex()).thenReturn(mock(TransitStop.class));

        State stopStationState = mock(State.class);
        when(stopStationState.getBackEdge()).thenReturn(mock(StationStopEdge.class));
        when(stopStationState.getVertex()).thenReturn(mock(TransitStation.class));

        try {
            parser.terminalFor(emptyState);
            fail();
        } catch (Throwable throwable) {
View Full Code Here

        // Start in start state and "walk" through state machine
        int currentState = AutomatonState.START;
        for (int i = 0; i < path.size(); i++) {
            Class<? extends Edge> edgeClass = path.get(i);
            // Create dummy state with edge as back edge
            State state = mock(State.class);
            Edge edge = mock(edgeClass);
            when(state.getBackEdge()).thenReturn(edge);
            if (i == 0) {                                                           // First state
                when(state.getVertex()).thenReturn(mock(TransitStop.class));
            } else if (i == path.size() - 1) {                                      // Final state
                when(state.getVertex()).thenReturn(mock(TransitStation.class));
            }

            // Get terminal of state
            int terminal = parser.terminalFor(state);
            // Make a transition
View Full Code Here

        options = new RoutingRequest("BICYCLE");
        options.setRoutingContext(graph, B, D);
        tree = aStar.getShortestPathTree(options);
        path = tree.getPath(D, false);
        assertNotNull(path);
        State s = tree.getState(D);
        assertFalse(s.isBikeParked());
        // TODO backWalkingBike flag is broken
        // assertTrue(s.isBackWalkingBike());
        assertTrue(s.getBackMode() == TraverseMode.WALK);

        // But we can go from B to D with BICYCLE+WALK mode using bike P+R.
        options = new RoutingRequest("BICYCLE_PARK,WALK,TRANSIT");
        options.setRoutingContext(graph, B, D);
        tree = aStar.getShortestPathTree(options);
        path = tree.getPath(D, false);
        assertNotNull(path);
        s = tree.getState(D);
        assertTrue(s.isBikeParked());
        assertFalse(s.isBackWalkingBike());
    }
View Full Code Here

        RoutingRequest options = proto.clone();
        options.setMode(TraverseMode.WALK);
        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() / options.walkSpeed;
        long expectedDuration = (long) Math.ceil(expectedWeight);
        assertEquals(expectedDuration, s1.getElapsedTimeSeconds(), 0.0);
        assertEquals(expectedWeight, s1.getWeight(), 0.0);
    }
View Full Code Here

        RoutingRequest options = proto.clone();
        options.setMode(TraverseMode.CAR);
        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

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.