Search in sources :

Example 16 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class SimpleTraversalCostModelTest method testLeftNoLightInCar.

@Test
public void testLeftNoLightInCar() {
    // 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.749760, -73.987749);
    // 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);
    assertFalse(costModel.isRightTurn(turnAngle));
    assertTrue(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 17 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class SimpleTraversalCostModelTest method edge.

/**
 * Create an edge. If twoWay, create two edges (back and forth).
 *
 * @param vA
 * @param vB
 * @param length
 * @param back true if this is a reverse edge
 */
private StreetEdge edge(StreetVertex vA, StreetVertex vB, double length, boolean back) {
    String labelA = vA.getLabel();
    String labelB = vB.getLabel();
    String name = String.format("%s_%s", labelA, labelB);
    Coordinate[] coords = new Coordinate[2];
    coords[0] = vA.getCoordinate();
    coords[1] = vB.getCoordinate();
    LineString geom = GeometryUtils.getGeometryFactory().createLineString(coords);
    StreetTraversalPermission perm = StreetTraversalPermission.ALL;
    return new StreetEdge(vA, vB, geom, name, length, perm, back);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) LineString(com.vividsolutions.jts.geom.LineString)

Example 18 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class TestGraph method testGetStreetEdgesSeveral.

public void testGetStreetEdgesSeveral() {
    Graph g = new Graph();
    StreetVertex a = new IntersectionVertex(g, "A", 5, 5);
    StreetVertex b = new IntersectionVertex(g, "B", 6, 6);
    StreetVertex c = new IntersectionVertex(g, "C", 3, 2);
    Set<Edge> allStreetEdges = new HashSet<Edge>(4);
    allStreetEdges.add(edge(a, b, 1.0));
    allStreetEdges.add(edge(b, c, 1.0));
    allStreetEdges.add(edge(c, b, 1.0));
    allStreetEdges.add(edge(c, a, 1.0));
    Set<StreetEdge> edges = new HashSet<StreetEdge>(g.getStreetEdges());
    assertEquals(4, edges.size());
    assertEquals(allStreetEdges, edges);
}
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) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 19 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class TestGraph method testGetStreetEdgesNone.

public void testGetStreetEdgesNone() {
    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> allEdges = new HashSet<Edge>(4);
    allEdges.add(new FreeEdge(a, b));
    allEdges.add(new FreeEdge(b, c));
    allEdges.add(new FreeEdge(c, b));
    allEdges.add(new FreeEdge(c, a));
    Set<StreetEdge> edges = new HashSet<StreetEdge>(g.getStreetEdges());
    assertEquals(0, edges.size());
}
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) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) 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 20 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class TestBikeRental method testBasic.

public void testBasic() throws Exception {
    // generate a very simple graph
    Graph graph = new Graph();
    StreetVertex v1 = new IntersectionVertex(graph, "v1", -77.0492, 38.856, "v1");
    StreetVertex v2 = new IntersectionVertex(graph, "v2", -77.0492, 38.857, "v2");
    StreetVertex v3 = new IntersectionVertex(graph, "v3", -77.0492, 38.858, "v3");
    @SuppressWarnings("unused") Edge walk = new StreetEdge(v1, v2, GeometryUtils.makeLineString(-77.0492, 38.856, -77.0492, 38.857), "S. Crystal Dr", 87, StreetTraversalPermission.PEDESTRIAN, false);
    @SuppressWarnings("unused") Edge mustBike = new StreetEdge(v2, v3, GeometryUtils.makeLineString(-77.0492, 38.857, -77.0492, 38.858), "S. Crystal Dr", 87, StreetTraversalPermission.BICYCLE, false);
    AStar aStar = new AStar();
    // it is impossible to get from v1 to v3 by walking
    RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK,TRANSIT"));
    options.setRoutingContext(graph, v1, v3);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(v3, false);
    assertNull(path);
    // or biking + walking (assuming walking bikes is disallowed)
    options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
    options.freezeTraverseMode();
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    assertNull(path);
    // so we add a bike share
    BikeRentalStation station = new BikeRentalStation();
    station.id = "id";
    station.name = new NonLocalizedString("station");
    station.x = -77.049;
    station.y = 36.856;
    station.bikesAvailable = 5;
    station.spacesAvailable = 5;
    BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
    new StreetBikeRentalLink(stationVertex, v2);
    new StreetBikeRentalLink(v2, stationVertex);
    Set<String> networks = new HashSet<String>(Arrays.asList("default"));
    new RentABikeOnEdge(stationVertex, stationVertex, networks);
    new RentABikeOffEdge(stationVertex, stationVertex, networks);
    // but we can't get off the bike at v3, so we still fail
    options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
    options.freezeTraverseMode();
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    // null is returned because the only state at the target is not final
    assertNull(path);
    BikeRentalStation station2 = new BikeRentalStation();
    station2.id = "id2";
    station2.name = new NonLocalizedString("station2");
    station2.x = -77.049;
    station2.y = 36.857;
    station2.bikesAvailable = 5;
    station2.spacesAvailable = 5;
    BikeRentalStationVertex stationVertex2 = new BikeRentalStationVertex(graph, station2);
    new StreetBikeRentalLink(stationVertex2, v3);
    new StreetBikeRentalLink(v3, stationVertex2);
    new RentABikeOnEdge(stationVertex2, stationVertex2, networks);
    new RentABikeOffEdge(stationVertex2, stationVertex2, networks);
    // now we succeed!
    options = new RoutingRequest();
    new QualifiedModeSet("BICYCLE_RENT,TRANSIT").applyToRoutingRequest(options);
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    assertNotNull(path);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Aggregations

StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)58 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)23 Edge (org.opentripplanner.routing.graph.Edge)22 LineString (com.vividsolutions.jts.geom.LineString)17 Graph (org.opentripplanner.routing.graph.Graph)16 Vertex (org.opentripplanner.routing.graph.Vertex)15 Test (org.junit.Test)13 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)9 HashSet (java.util.HashSet)8 StreetTraversalPermission (org.opentripplanner.routing.edgetype.StreetTraversalPermission)8 State (org.opentripplanner.routing.core.State)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)7 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)5 TraverseMode (org.opentripplanner.routing.core.TraverseMode)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)4 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)4 StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)4