Search in sources :

Example 16 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex 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 17 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class TurnCostTest method before.

@Before
public void before() {
    _graph = new Graph();
    // Graph for a fictional grid city with turn restrictions
    StreetVertex maple1 = vertex("maple_1st", 2.0, 2.0);
    StreetVertex maple2 = vertex("maple_2nd", 1.0, 2.0);
    StreetVertex maple3 = vertex("maple_3rd", 0.0, 2.0);
    StreetVertex main1 = vertex("main_1st", 2.0, 1.0);
    StreetVertex main2 = vertex("main_2nd", 1.0, 1.0);
    StreetVertex main3 = vertex("main_3rd", 0.0, 1.0);
    StreetVertex broad1 = vertex("broad_1st", 2.0, 0.0);
    StreetVertex broad2 = vertex("broad_2nd", 1.0, 0.0);
    StreetVertex broad3 = vertex("broad_3rd", 0.0, 0.0);
    // Each block along the main streets has unit length and is one-way
    StreetEdge maple1_2 = edge(maple1, maple2, 100.0, false);
    StreetEdge maple2_3 = edge(maple2, maple3, 100.0, false);
    StreetEdge main1_2 = edge(main1, main2, 100.0, false);
    StreetEdge main2_3 = edge(main2, main3, 100.0, false);
    broad1_2 = edge(broad1, broad2, 100.0, false);
    StreetEdge broad2_3 = edge(broad2, broad3, 100.0, false);
    // Each cross-street connects
    maple_main1 = edge(maple1, main1, 50.0, false);
    StreetEdge main_broad1 = edge(main1, broad1, 100.0, false);
    StreetEdge maple_main2 = edge(maple2, main2, 50.0, false);
    StreetEdge main_broad2 = edge(main2, broad2, 50.0, false);
    StreetEdge maple_main3 = edge(maple3, main3, 100.0, false);
    StreetEdge main_broad3 = edge(main3, broad3, 100.0, false);
    // Turn restrictions are only for driving modes.
    // - can't turn from 1st onto Main.
    // - can't turn from 2nd onto Main.
    // - can't turn from 2nd onto Broad.
    DisallowTurn(maple_main1, main1_2);
    DisallowTurn(maple_main2, main2_3);
    DisallowTurn(main_broad2, broad2_3);
    // Hold onto some vertices for the tests
    topRight = maple1;
    bottomLeft = broad3;
    // Make a prototype routing request.
    proto = new RoutingRequest();
    proto.carSpeed = 1.0;
    proto.walkSpeed = 1.0;
    proto.bikeSpeed = 1.0;
    proto.turnReluctance = (1.0);
    proto.setWalkReluctance(1.0);
    proto.stairsReluctance = (1.0);
    // Turn costs are all 0 by default.
    proto.traversalCostModel = (new ConstantIntersectionTraversalCostModel(0.0));
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) ConstantIntersectionTraversalCostModel(org.opentripplanner.routing.core.ConstantIntersectionTraversalCostModel) Before(org.junit.Before)

Example 18 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class GraphServiceTest method setUp.

@Override
protected void setUp() throws IOException {
    // Ensure a dummy disk location exists
    basePath = new File("test_graphs");
    if (!basePath.exists())
        basePath.mkdir();
    // Create an empty graph and it's serialized form
    emptyGraph = new Graph();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    emptyGraph.save(new ObjectOutputStream(baos));
    emptyGraphData = baos.toByteArray();
    // Create a small graph with 2 vertices and one edge and it's serialized form
    smallGraph = new Graph();
    StreetVertex v1 = new IntersectionVertex(smallGraph, "v1", 0, 0);
    StreetVertex v2 = new IntersectionVertex(smallGraph, "v2", 0, 0.1);
    new StreetEdge(v1, v2, null, "v1v2", 11000, StreetTraversalPermission.PEDESTRIAN, false);
    baos = new ByteArrayOutputStream();
    smallGraph.save(new ObjectOutputStream(baos));
    smallGraphData = baos.toByteArray();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Aggregations

StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)18 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)8 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)8 Graph (org.opentripplanner.routing.graph.Graph)7 Vertex (org.opentripplanner.routing.graph.Vertex)5 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 LineString (com.vividsolutions.jts.geom.LineString)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)4 State (org.opentripplanner.routing.core.State)4 Edge (org.opentripplanner.routing.graph.Edge)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 File (java.io.File)2 Before (org.junit.Before)2 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)2 FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)2 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)2 SplitterVertex (org.opentripplanner.routing.vertextype.SplitterVertex)2 Envelope (com.vividsolutions.jts.geom.Envelope)1