Search in sources :

Example 96 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class ShowGraph method findVisibleElements.

@SuppressWarnings("unchecked")
private synchronized void findVisibleElements() {
    visibleVertices = (List<Vertex>) vertexIndex.query(modelBounds);
    visibleStreetEdges.clear();
    visibleLinkEdges.clear();
    visibleTransitEdges.clear();
    for (Edge de : (Iterable<Edge>) edgeIndex.query(modelBounds)) {
        if (de instanceof PatternEdge) {
            visibleTransitEdges.add(de);
        } else if (de instanceof PathwayEdge || de instanceof StreetTransitLink || de instanceof SimpleTransfer) {
            visibleLinkEdges.add(de);
        } else if (de instanceof StreetEdge) {
            visibleStreetEdges.add(de);
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge)

Example 97 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class ShowGraph method labelState.

private void labelState(State s, String str) {
    fill(240, 240, 240);
    Vertex v = s.getVertex();
    drawVertex(v, 8);
    str += " " + shortDateFormat.format(new Date(s.getTimeSeconds() * 1000));
    str += " [" + (int) s.getWeight() + "]";
    double x = toScreenX(v.getX()) + 10;
    double y = toScreenY(v.getY());
    double dy = y - lastLabelY;
    if (dy == 0) {
        y = lastLabelY + 20;
    } else if (Math.abs(dy) < 20) {
        y = lastLabelY + Math.signum(dy) * 20;
    }
    text(str, (float) x, (float) y);
    lastLabelY = y;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex)

Example 98 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class TestUnconnectedAreas method testUnconnectedParkAndRide.

/**
 * The P+R.osm.gz file contains 2 park and ride, one a single way area and the other a
 * multipolygon with a hole. Both are not linked to any street, apart from three roads that
 * crosses the P+R with w/o common nodes.
 *
 * This test just make sure we correctly link those P+R with the street network by creating
 * virtual nodes at the place where the street intersects the P+R areas. See ticket #1562.
 */
@Test
public void testUnconnectedParkAndRide() throws Exception {
    Graph gg = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(getClass().getResource("P+R.osm.gz").getFile());
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, new HashMap<Class<?>, Object>());
    assertEquals(1, gg.getBuilderAnnotations().size());
    int nParkAndRide = 0;
    int nParkAndRideLink = 0;
    for (Vertex v : gg.getVertices()) {
        if (v instanceof ParkAndRideVertex) {
            nParkAndRide++;
        }
    }
    for (Edge e : gg.getEdges()) {
        if (e instanceof ParkAndRideLinkEdge) {
            nParkAndRideLink++;
        }
    }
    assertEquals(2, nParkAndRide);
    assertEquals(10, nParkAndRideLink);
}
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) 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)

Example 99 with Vertex

use of org.opentripplanner.routing.graph.Vertex 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 100 with Vertex

use of org.opentripplanner.routing.graph.Vertex 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

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11