Search in sources :

Example 6 with StreetVertex

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

the class LinkingTest method testSplitting.

/**
 * Ensure that splitting edges yields edges that are identical in length for forward and back edges.
 * StreetEdges have lengths expressed internally in mm, and we want to be sure that not only do they
 * sum to the same values but also that they
 */
@Test
public void testSplitting() {
    GeometryFactory gf = GeometryUtils.getGeometryFactory();
    double x = -122.123;
    double y = 37.363;
    for (double delta = 0; delta <= 2; delta += 0.005) {
        StreetVertex v0 = new IntersectionVertex(null, "zero", x, y);
        StreetVertex v1 = new IntersectionVertex(null, "one", x + delta, y + delta);
        LineString geom = gf.createLineString(new Coordinate[] { v0.getCoordinate(), v1.getCoordinate() });
        double dist = SphericalDistanceLibrary.distance(v0.getCoordinate(), v1.getCoordinate());
        StreetEdge s0 = new StreetEdge(v0, v1, geom, "test", dist, StreetTraversalPermission.ALL, false);
        StreetEdge s1 = new StreetEdge(v1, v0, (LineString) geom.reverse(), "back", dist, StreetTraversalPermission.ALL, true);
        // split it but not too close to the end
        double splitVal = Math.random() * 0.95 + 0.025;
        SplitterVertex sv0 = new SplitterVertex(null, "split", x + delta * splitVal, y + delta * splitVal, s0);
        SplitterVertex sv1 = new SplitterVertex(null, "split", x + delta * splitVal, y + delta * splitVal, s1);
        P2<StreetEdge> sp0 = s0.split(sv0, true);
        P2<StreetEdge> sp1 = s1.split(sv1, true);
        // distances expressed internally in mm so this epsilon is plenty good enough to ensure that they
        // have the same values
        assertEquals(sp0.first.getDistance(), sp1.second.getDistance(), 0.0000001);
        assertEquals(sp0.second.getDistance(), sp1.first.getDistance(), 0.0000001);
        assertFalse(sp0.first.isBack());
        assertFalse(sp0.second.isBack());
        assertTrue(sp1.first.isBack());
        assertTrue(sp1.second.isBack());
    }
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) LineString(com.vividsolutions.jts.geom.LineString) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) Test(org.junit.Test)

Example 7 with StreetVertex

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

the class TestGraph method testGetEdgesAndVerticesById.

public void testGetEdgesAndVerticesById() {
    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> allEdges = new HashSet<Edge>(4);
    allEdges.add(edge(a, b, 1.0));
    allEdges.add(edge(b, c, 1.0));
    allEdges.add(edge(c, b, 1.0));
    allEdges.add(edge(c, a, 1.0));
    // Before rebuilding the indices, they are empty.
    for (Edge e : allEdges) {
        assertNull(g.getEdgeById(e.getId()));
    }
    for (Vertex v : g.getVertices()) {
        assertNull(g.getVertexById(v.getIndex()));
    }
    g.rebuildVertexAndEdgeIndices();
    for (Edge e : allEdges) {
        assertEquals(e, g.getEdgeById(e.getId()));
    }
    for (Vertex v : g.getVertices()) {
        assertEquals(v, g.getVertexById(v.getIndex()));
    }
}
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) 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 8 with StreetVertex

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

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

the class TestStreetMatcher method edges.

private void edges(String... vLabels) {
    for (int i = 0; i < vLabels.length - 1; i++) {
        StreetVertex vA = (StreetVertex) _graph.getVertex(vLabels[i]);
        StreetVertex vB = (StreetVertex) _graph.getVertex(vLabels[i + 1]);
        new SimpleEdge(vA, vB);
        new SimpleEdge(vB, vA);
    }
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 10 with StreetVertex

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

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