Search in sources :

Example 1 with TransitEntranceLink

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

the class SimpleStreetSplitter method makeTransitLinkEdges.

/**
 * Make street transit link edges, unless they already exist.
 */
private void makeTransitLinkEdges(TransitEntranceVertex entrance, StreetVertex v) {
    if (!destructiveSplitting) {
        throw new RuntimeException("Transitedges are created with non destructive splitting!");
    }
    // this can happen if we link to duplicate ways that have the same start/end vertices.
    for (TransitEntranceLink e : Iterables.filter(entrance.getOutgoing(), TransitEntranceLink.class)) {
        if (e.getToVertex() == v) {
            return;
        }
    }
    new TransitEntranceLink(entrance, v, entrance.isWheelchairEntrance());
    new TransitEntranceLink(v, entrance, entrance.isWheelchairEntrance());
}
Also used : TransitEntranceLink(org.opentripplanner.routing.edgetype.TransitEntranceLink)

Example 2 with TransitEntranceLink

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

the class StreetUtils method pruneFloatingIslands.

public static void pruneFloatingIslands(Graph graph, int maxIslandSize, int islandWithStopMaxSize, String islandLogName, DataImportIssueStore issueStore) {
    LOG.debug("pruning");
    PrintWriter islandLog = null;
    if (islandLogName != null && !islandLogName.isEmpty()) {
        try {
            islandLog = new PrintWriter(new File(islandLogName));
        } catch (Exception e) {
            LOG.error("Failed to write islands log file", e);
        }
    }
    if (islandLog != null) {
        islandLog.printf("%s\t%s\t%s\t%s\t%s\n", "id", "stopCount", "streetCount", "wkt", "hadRemoved");
    }
    Map<Vertex, Subgraph> subgraphs = new HashMap<Vertex, Subgraph>();
    Map<Vertex, ArrayList<Vertex>> neighborsForVertex = new HashMap<Vertex, ArrayList<Vertex>>();
    // RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT));
    RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
    for (Vertex gv : graph.getVertices()) {
        if (!(gv instanceof StreetVertex)) {
            continue;
        }
        State s0 = new State(gv, options);
        for (Edge e : gv.getOutgoing()) {
            Vertex in = gv;
            if (!(e instanceof StreetEdge || e instanceof StreetTransitLink || e instanceof TransitEntranceLink || e instanceof ElevatorEdge || e instanceof FreeEdge)) {
                continue;
            }
            State s1 = e.traverse(s0);
            if (s1 == null) {
                continue;
            }
            Vertex out = s1.getVertex();
            ArrayList<Vertex> vertexList = neighborsForVertex.get(in);
            if (vertexList == null) {
                vertexList = new ArrayList<Vertex>();
                neighborsForVertex.put(in, vertexList);
            }
            vertexList.add(out);
            vertexList = neighborsForVertex.get(out);
            if (vertexList == null) {
                vertexList = new ArrayList<Vertex>();
                neighborsForVertex.put(out, vertexList);
            }
            vertexList.add(in);
        }
    }
    ArrayList<Subgraph> islands = new ArrayList<Subgraph>();
    /* associate each node with a subgraph */
    for (Vertex gv : graph.getVertices()) {
        if (!(gv instanceof StreetVertex)) {
            continue;
        }
        Vertex vertex = gv;
        if (subgraphs.containsKey(vertex)) {
            continue;
        }
        if (!neighborsForVertex.containsKey(vertex)) {
            continue;
        }
        Subgraph subgraph = computeConnectedSubgraph(neighborsForVertex, vertex);
        if (subgraph != null) {
            for (Iterator<Vertex> vIter = subgraph.streetIterator(); vIter.hasNext(); ) {
                Vertex subnode = vIter.next();
                subgraphs.put(subnode, subgraph);
            }
            islands.add(subgraph);
        }
    }
    LOG.info(islands.size() + " sub graphs found");
    /* remove all tiny subgraphs and large subgraphs without stops */
    for (Subgraph island : islands) {
        boolean hadRemoved = false;
        if (island.stopSize() > 0) {
            // for islands with stops
            if (island.streetSize() < islandWithStopMaxSize) {
                depedestrianizeOrRemove(graph, island, issueStore);
                hadRemoved = true;
            }
        } else {
            // for islands without stops
            if (island.streetSize() < maxIslandSize) {
                depedestrianizeOrRemove(graph, island, issueStore);
                hadRemoved = true;
            }
        }
        if (islandLog != null) {
            WriteNodesInSubGraph(island, islandLog, hadRemoved);
        }
    }
    if (graph.removeEdgelessVertices() > 0) {
        LOG.info("Removed edgeless vertices after pruning islands");
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) State(org.opentripplanner.routing.core.State) Subgraph(org.opentripplanner.common.geometry.Subgraph) TransitEntranceLink(org.opentripplanner.routing.edgetype.TransitEntranceLink) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) ElevatorEdge(org.opentripplanner.routing.edgetype.ElevatorEdge) File(java.io.File) ElevatorEdge(org.opentripplanner.routing.edgetype.ElevatorEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge) PrintWriter(java.io.PrintWriter)

Example 3 with TransitEntranceLink

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

the class StreetUtils method depedestrianizeOrRemove.

private static void depedestrianizeOrRemove(Graph graph, Subgraph island, DataImportIssueStore issueStore) {
    // 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 || e instanceof TransitEntranceLink) {
                graph.removeEdge(e);
            }
        }
    }
    issueStore.add(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.issues.GraphConnectivity) ArrayList(java.util.ArrayList) TransitEntranceLink(org.opentripplanner.routing.edgetype.TransitEntranceLink) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) ElevatorEdge(org.opentripplanner.routing.edgetype.ElevatorEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

TransitEntranceLink (org.opentripplanner.routing.edgetype.TransitEntranceLink)3 ArrayList (java.util.ArrayList)2 ElevatorEdge (org.opentripplanner.routing.edgetype.ElevatorEdge)2 FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)2 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)2 StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)2 Edge (org.opentripplanner.routing.graph.Edge)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Subgraph (org.opentripplanner.common.geometry.Subgraph)1 GraphConnectivity (org.opentripplanner.graph_builder.issues.GraphConnectivity)1 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)1 State (org.opentripplanner.routing.core.State)1 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)1 StreetTraversalPermission (org.opentripplanner.routing.edgetype.StreetTraversalPermission)1