Search in sources :

Example 31 with IntersectionVertex

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

the class SimpleTraversalCostModelTest method testRightNoLightInCar.

@Test
public void testRightNoLightInCar() {
    // 3 points that form a right turn on the map
    Coordinate a = new Coordinate(40.750167, -73.990989);
    Coordinate b = new Coordinate(40.749094, -73.988049);
    Coordinate c = new Coordinate(40.748509, -73.988693);
    // A vertex for each. No light.
    IntersectionVertex u = vertex("from_v", a, false);
    IntersectionVertex v = vertex("intersection", b, false);
    IntersectionVertex w = vertex("to_v", c, false);
    // Two edges.
    StreetEdge fromEdge = edge(u, v, 1.0, false);
    StreetEdge toEdge = edge(v, w, 1.0, false);
    // 3rd edge prevents inferral of free-flowingness
    StreetEdge extraEdge = edge(v, u, 1.0, false);
    int turnAngle = costModel.calculateTurnAngle(fromEdge, toEdge, options);
    assertTrue(costModel.isRightTurn(turnAngle));
    assertFalse(costModel.isLeftTurn(turnAngle));
    float fromSpeed = 1.0f;
    float toSpeed = 1.0f;
    TraverseMode mode = TraverseMode.CAR;
    double traversalCost = costModel.computeTraversalCost(v, fromEdge, toEdge, mode, options, fromSpeed, toSpeed);
    // Cost with default values = 8.0
    assertEquals(8.0, traversalCost, 0.0);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Test(org.junit.Test)

Example 32 with IntersectionVertex

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

the class SimpleTraversalCostModelTest method testStraightNoLightInCar.

@Test
public void testStraightNoLightInCar() {
    // 3 points on a roughly on line
    Coordinate a = new Coordinate(-73.990989, 40.750167);
    Coordinate b = new Coordinate(-73.988049, 40.749094);
    Coordinate c = new Coordinate(-73.984981, 40.747761);
    // A vertex for each. No light.
    IntersectionVertex u = vertex("from_v", a, false);
    IntersectionVertex v = vertex("intersection", b, false);
    IntersectionVertex w = vertex("to_v", c, false);
    // Two edges.
    StreetEdge fromEdge = edge(u, v, 1.0, false);
    StreetEdge toEdge = edge(v, w, 1.0, false);
    // 3rd edge prevents inferral of free-flowingness
    StreetEdge extraEdge = edge(v, u, 1.0, false);
    float fromSpeed = 1.0f;
    float toSpeed = 1.0f;
    TraverseMode mode = TraverseMode.CAR;
    double traversalCost = costModel.computeTraversalCost(v, fromEdge, toEdge, mode, options, fromSpeed, toSpeed);
    // Cost with default values = 5.0
    assertEquals(5, traversalCost, 0.0);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Test(org.junit.Test)

Example 33 with IntersectionVertex

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

the class SimpleTraversalCostModelTest method testFreeFlowing.

@Test
public void testFreeFlowing() {
    // 3 points on a roughly on line
    Coordinate a = new Coordinate(-73.990989, 40.750167);
    Coordinate b = new Coordinate(-73.988049, 40.749094);
    Coordinate c = new Coordinate(-73.984981, 40.747761);
    // A vertex for each. No light.
    IntersectionVertex u = vertex("from_v", a, false);
    IntersectionVertex v = vertex("intersection", b, false);
    IntersectionVertex w = vertex("to_v", c, false);
    v.freeFlowing = (true);
    // Two edges.
    StreetEdge fromEdge = edge(u, v, 1.0, false);
    StreetEdge toEdge = edge(v, w, 1.0, false);
    float fromSpeed = 1.0f;
    float toSpeed = 1.0f;
    TraverseMode mode = TraverseMode.CAR;
    double traversalCost = costModel.computeTraversalCost(v, fromEdge, toEdge, mode, options, fromSpeed, toSpeed);
    // Vertex is free-flowing so cost should be 0.0.
    assertEquals(0.0, traversalCost, 0.0);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Test(org.junit.Test)

Example 34 with IntersectionVertex

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

the class TestGraph method testGetEdgesMultiple.

public void testGetEdgesMultiple() {
    Graph g = new Graph();
    Vertex a = new IntersectionVertex(g, "A", 5, 5);
    Vertex b = new IntersectionVertex(g, "B", 6, 6);
    Vertex c = new IntersectionVertex(g, "C", 3, 2);
    Set<Edge> expectedEdges = new HashSet<Edge>(4);
    expectedEdges.add(new FreeEdge(a, b));
    expectedEdges.add(new FreeEdge(b, c));
    expectedEdges.add(new FreeEdge(c, b));
    expectedEdges.add(new FreeEdge(c, a));
    Set<Edge> edges = new HashSet<Edge>(g.getEdges());
    assertEquals(4, edges.size());
    assertEquals(expectedEdges, edges);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 35 with IntersectionVertex

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

the class TestTurns method testIntersectionVertex.

public void testIntersectionVertex() {
    GeometryFactory gf = new GeometryFactory();
    LineString geometry = gf.createLineString(new Coordinate[] { new Coordinate(-0.10, 0), new Coordinate(0, 0) });
    IntersectionVertex v1 = new IntersectionVertex(null, "v1", -0.10, 0);
    IntersectionVertex v2 = new IntersectionVertex(null, "v2", 0, 0);
    StreetEdge leftEdge = new StreetEdge(v1, v2, geometry, "morx", 10.0, StreetTraversalPermission.ALL, true);
    LineString geometry2 = gf.createLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(-0.10, 0) });
    StreetEdge rightEdge = new StreetEdge(v1, v2, geometry2, "fleem", 10.0, StreetTraversalPermission.ALL, false);
    assertEquals(180, Math.abs(leftEdge.getOutAngle() - rightEdge.getOutAngle()));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge)

Aggregations

IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)38 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)23 Graph (org.opentripplanner.routing.graph.Graph)17 Coordinate (com.vividsolutions.jts.geom.Coordinate)16 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)14 Vertex (org.opentripplanner.routing.graph.Vertex)12 LineString (com.vividsolutions.jts.geom.LineString)10 Test (org.junit.Test)10 Edge (org.opentripplanner.routing.graph.Edge)10 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)8 HashSet (java.util.HashSet)8 FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)8 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)5 ArrayList (java.util.ArrayList)5 Point (com.vividsolutions.jts.geom.Point)4 P2 (org.opentripplanner.common.model.P2)4 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 State (org.opentripplanner.routing.core.State)3 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)3