Search in sources :

Example 71 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class PlainStreetEdgeTest method testTraverseAsPedestrian.

@Test
public void testTraverseAsPedestrian() {
    StreetEdge e1 = edge(v1, v2, 100.0, StreetTraversalPermission.ALL);
    e1.setCarSpeed(10.0f);
    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);
}
Also used : State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 72 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class TestTriangle method testTriangle.

public void testTriangle() {
    Coordinate c1 = new Coordinate(-122.575033, 45.456773);
    Coordinate c2 = new Coordinate(-122.576668, 45.451426);
    StreetVertex v1 = new IntersectionVertex(null, "v1", c1.x, c1.y, (NonLocalizedString) null);
    StreetVertex v2 = new IntersectionVertex(null, "v2", c2.x, c2.y, (NonLocalizedString) null);
    GeometryFactory factory = new GeometryFactory();
    LineString geometry = factory.createLineString(new Coordinate[] { c1, c2 });
    double length = 650.0;
    StreetWithElevationEdge testStreet = new StreetWithElevationEdge(v1, v2, geometry, "Test Lane", length, StreetTraversalPermission.ALL, false);
    // a safe street
    testStreet.setBicycleSafetyFactor(0.74f);
    Coordinate[] profile = new Coordinate[] { // slope = 0.1
    new Coordinate(0, 0), new Coordinate(length / 2, length / 20.0), // slope = -0.1
    new Coordinate(length, 0) };
    PackedCoordinateSequence elev = new PackedCoordinateSequence.Double(profile);
    testStreet.setElevationProfile(elev, false);
    SlopeCosts costs = ElevationUtils.getSlopeCosts(elev, true);
    double trueLength = costs.lengthMultiplier * length;
    double slopeWorkLength = testStreet.getSlopeWorkCostEffectiveLength();
    double slopeSpeedLength = testStreet.getSlopeSpeedEffectiveLength();
    RoutingRequest options = new RoutingRequest(TraverseMode.BICYCLE);
    options.optimize = OptimizeType.TRIANGLE;
    options.bikeSpeed = 6.0;
    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);
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) SlopeCosts(org.opentripplanner.routing.util.SlopeCosts) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) State(org.opentripplanner.routing.core.State) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) PackedCoordinateSequence(org.opentripplanner.common.geometry.PackedCoordinateSequence)

Example 73 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class TurnCostTest method testForwardDefaultConstTurnCosts.

@Test
public void testForwardDefaultConstTurnCosts() {
    RoutingRequest options = proto.clone();
    options.traversalCostModel = (new ConstantIntersectionTraversalCostModel(10.0));
    options.setRoutingContext(_graph, topRight, bottomLeft);
    // Without turn costs, this path costs 2x100 + 2x50 = 300.
    // Since we traverse 3 intersections, the total cost should be 330.
    GraphPath path = checkForwardRouteDuration(options, 330);
    // The intersection traversal cost should be applied to the state *after*
    // the intersection itself.
    List<State> states = path.states;
    assertEquals(5, states.size());
    assertEquals("maple_1st", states.get(0).getVertex().getLabel());
    assertEquals("main_1st", states.get(1).getVertex().getLabel());
    assertEquals("main_2nd", states.get(2).getVertex().getLabel());
    assertEquals("broad_2nd", states.get(3).getVertex().getLabel());
    assertEquals("broad_3rd", states.get(4).getVertex().getLabel());
    assertEquals(0, states.get(0).getElapsedTimeSeconds());
    // maple_main1 = 50
    assertEquals(50, states.get(1).getElapsedTimeSeconds());
    // main1_2 = 100
    assertEquals(160, states.get(2).getElapsedTimeSeconds());
    // main_broad2 = 50
    assertEquals(220, states.get(3).getElapsedTimeSeconds());
    // broad2_3 = 100
    assertEquals(330, states.get(4).getElapsedTimeSeconds());
}
Also used : State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) ConstantIntersectionTraversalCostModel(org.opentripplanner.routing.core.ConstantIntersectionTraversalCostModel) Test(org.junit.Test)

Example 74 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class TurnCostTest method testForwardCarNoTurnCosts.

@Test
public void testForwardCarNoTurnCosts() {
    RoutingRequest options = proto.clone();
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(_graph, topRight, bottomLeft);
    // Without turn costs, this path costs 3x100 + 1x50 = 300.
    GraphPath path = checkForwardRouteDuration(options, 350);
    List<State> states = path.states;
    assertEquals(5, states.size());
    assertEquals("maple_1st", states.get(0).getVertex().getLabel());
    assertEquals("main_1st", states.get(1).getVertex().getLabel());
    assertEquals("broad_1st", states.get(2).getVertex().getLabel());
    assertEquals("broad_2nd", states.get(3).getVertex().getLabel());
    assertEquals("broad_3rd", states.get(4).getVertex().getLabel());
}
Also used : State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 75 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class Sample method evalBoardings.

public byte evalBoardings(ShortestPathTree spt) {
    State s0 = spt.getState(v0);
    State s1 = spt.getState(v1);
    int m0 = 255;
    int m1 = 255;
    if (s0 != null)
        m0 = (s0.getNumBoardings());
    if (s1 != null)
        m1 = (s1.getNumBoardings());
    return (byte) ((m0 < m1) ? m0 : m1);
}
Also used : State(org.opentripplanner.routing.core.State)

Aggregations

State (org.opentripplanner.routing.core.State)78 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)42 GraphPath (org.opentripplanner.routing.spt.GraphPath)25 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)24 Test (org.junit.Test)23 Edge (org.opentripplanner.routing.graph.Edge)22 Vertex (org.opentripplanner.routing.graph.Vertex)20 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)8 Graph (org.opentripplanner.routing.graph.Graph)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)6 LineString (com.vividsolutions.jts.geom.LineString)5 HashSet (java.util.HashSet)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Trip (org.onebusaway.gtfs.model.Trip)5 StateEditor (org.opentripplanner.routing.core.StateEditor)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)5