Search in sources :

Example 1 with GraphConnectivity

use of org.opentripplanner.graph_builder.annotation.GraphConnectivity in project OpenTripPlanner by opentripplanner.

the class StreetUtils method depedestrianizeOrRemove.

private static void depedestrianizeOrRemove(Graph graph, Subgraph island) {
    // iterate over the street vertex of the subgraph
    for (Iterator<Vertex> vIter = island.streetIterator(); vIter.hasNext(); ) {
        Vertex v = vIter.next();
        Collection<Edge> outgoing = new ArrayList<Edge>(v.getOutgoing());
        for (Edge e : outgoing) {
            if (e instanceof StreetEdge) {
                StreetEdge pse = (StreetEdge) e;
                StreetTraversalPermission permission = pse.getPermission();
                permission = permission.remove(StreetTraversalPermission.PEDESTRIAN);
                permission = permission.remove(StreetTraversalPermission.BICYCLE);
                if (permission == StreetTraversalPermission.NONE) {
                    graph.removeEdge(pse);
                } else {
                    pse.setPermission(permission);
                }
            }
        }
    }
    for (Iterator<Vertex> vIter = island.streetIterator(); vIter.hasNext(); ) {
        Vertex v = vIter.next();
        if (v.getDegreeOut() + v.getDegreeIn() == 0) {
            graph.remove(v);
        }
    }
    // remove street conncetion form
    for (Iterator<Vertex> vIter = island.stopIterator(); vIter.hasNext(); ) {
        Vertex v = vIter.next();
        Collection<Edge> edges = new ArrayList<Edge>(v.getOutgoing());
        edges.addAll(v.getIncoming());
        for (Edge e : edges) {
            if (e instanceof StreetTransitLink) {
                graph.removeEdge(e);
            }
        }
    }
    LOG.debug(graph.addBuilderAnnotation(new GraphConnectivity(island.getRepresentativeVertex(), island.streetSize())));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) GraphConnectivity(org.opentripplanner.graph_builder.annotation.GraphConnectivity) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

GraphConnectivity (org.opentripplanner.graph_builder.annotation.GraphConnectivity)1 Edge (org.opentripplanner.routing.graph.Edge)1 Vertex (org.opentripplanner.routing.graph.Vertex)1 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)1