Search in sources :

Example 1 with ParkAndRideEdge

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

the class TestUnconnectedAreas method testGeometricGraphWithClasspathFile.

/**
 * We've written several OSM files that exhibit different situations but should show the same results. Test with this code.
 */
public List<String> testGeometricGraphWithClasspathFile(String fn, int prCount, int prlCount) {
    Graph g = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(getClass().getResource(fn).getFile());
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(g, new HashMap<Class<?>, Object>());
    Vertex pr = null;
    int nParkAndRide = 0;
    int nParkAndRideLink = 0;
    for (Vertex v : g.getVertices()) {
        if (v instanceof ParkAndRideVertex) {
            nParkAndRide++;
            pr = v;
        }
    }
    for (Edge e : g.getEdges()) {
        if (e instanceof ParkAndRideLinkEdge) {
            nParkAndRideLink++;
        }
    }
    assertEquals(prCount, nParkAndRide);
    assertEquals(prlCount, nParkAndRideLink);
    assertNotNull(pr);
    // make sure it is connected
    List<String> connections = new ArrayList<String>();
    for (Edge e : pr.getOutgoing()) {
        if (e instanceof ParkAndRideEdge)
            continue;
        assertTrue(e instanceof ParkAndRideLinkEdge);
        connections.add(e.getToVertex().getLabel());
    }
    // symmetry
    for (Edge e : pr.getIncoming()) {
        if (e instanceof ParkAndRideEdge)
            continue;
        assertTrue(e instanceof ParkAndRideLinkEdge);
        assertTrue(connections.contains(e.getFromVertex().getLabel()));
    }
    return connections;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) ArrayList(java.util.ArrayList) ParkAndRideEdge(org.opentripplanner.routing.edgetype.ParkAndRideEdge) Graph(org.opentripplanner.routing.graph.Graph) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) File(java.io.File) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) ParkAndRideEdge(org.opentripplanner.routing.edgetype.ParkAndRideEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 2 with ParkAndRideEdge

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

the class TestUnconnectedAreas method testCoincidentNodeUnconnectedParkAndRide.

/**
 * This test ensures that if a Park and Ride has a node that is exactly atop a node on a way, the graph
 * builder will not loop forever trying to split it. The hackett-pr.osm.gz file contains a park-and-ride lot in
 * Hackettstown, NJ, which demonstrates this behavior. See discussion in ticket 1605.
 */
@Test
public void testCoincidentNodeUnconnectedParkAndRide() throws Exception {
    Graph g = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(getClass().getResource("hackett_pr.osm.gz").getFile());
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(g, new HashMap<Class<?>, Object>());
    Vertex washTwp = null;
    int nParkAndRide = 0;
    int nParkAndRideLink = 0;
    for (Vertex v : g.getVertices()) {
        if (v instanceof ParkAndRideVertex) {
            nParkAndRide++;
            washTwp = v;
        }
    }
    for (Edge e : g.getEdges()) {
        if (e instanceof ParkAndRideLinkEdge) {
            nParkAndRideLink++;
        }
    }
    assertEquals(1, nParkAndRide);
    // the P+R should get four connections, since the entrance road is duplicated as well, and crosses twice
    // since there are in and out edges, that brings the total to 8 per P+R.
    // Even though the park and rides get merged, duplicate edges remain from when they were separate.
    // FIXME: we shouldn't have duplicate edges.
    assertEquals(16, nParkAndRideLink);
    assertNotNull(washTwp);
    List<String> connections = new ArrayList<String>();
    for (Edge e : washTwp.getOutgoing()) {
        if (e instanceof ParkAndRideEdge)
            continue;
        assertTrue(e instanceof ParkAndRideLinkEdge);
        connections.add(e.getToVertex().getLabel());
    }
    // symmetry
    for (Edge e : washTwp.getIncoming()) {
        if (e instanceof ParkAndRideEdge)
            continue;
        assertTrue(e instanceof ParkAndRideLinkEdge);
        assertTrue(connections.contains(e.getFromVertex().getLabel()));
    }
    assertTrue(connections.contains("osm:node:3096570222"));
    assertTrue(connections.contains("osm:node:3094264704"));
    assertTrue(connections.contains("osm:node:3094264709"));
    assertTrue(connections.contains("osm:node:3096570227"));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) ArrayList(java.util.ArrayList) ParkAndRideEdge(org.opentripplanner.routing.edgetype.ParkAndRideEdge) Graph(org.opentripplanner.routing.graph.Graph) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) File(java.io.File) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) ParkAndRideEdge(org.opentripplanner.routing.edgetype.ParkAndRideEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Aggregations

File (java.io.File)2 ArrayList (java.util.ArrayList)2 FileBasedOpenStreetMapProviderImpl (org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl)2 ParkAndRideEdge (org.opentripplanner.routing.edgetype.ParkAndRideEdge)2 ParkAndRideLinkEdge (org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge)2 Edge (org.opentripplanner.routing.graph.Edge)2 Graph (org.opentripplanner.routing.graph.Graph)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 ParkAndRideVertex (org.opentripplanner.routing.vertextype.ParkAndRideVertex)2 Test (org.junit.Test)1