Search in sources :

Example 86 with Vertex

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

the class OverlayGraph method removeEdge.

public void removeEdge(Edge e) {
    Vertex fromv = e.getFromVertex();
    Vertex tov = e.getToVertex();
    removeOutgoing(fromv, e);
    removeIncoming(tov, e);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex)

Example 87 with Vertex

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

the class InterleavedBidirectionalHeuristic method doSomeWork.

/**
 * Move backward N steps through the transit network.
 * This improves the heuristic's knowledge of the transit network as seen from the target,
 * making its lower bounds on path weight progressively more accurate.
 */
@Override
public void doSomeWork() {
    if (finished)
        return;
    for (int i = 0; i < HEURISTIC_STEPS_PER_MAIN_STEP; ++i) {
        if (transitQueue.empty()) {
            finished = true;
            break;
        }
        int uWeight = (int) transitQueue.peek_min_key();
        Vertex u = transitQueue.extract_min();
        // The weight of the queue head is uniformly increasing.
        // This is the highest weight ever seen for a closed vertex.
        maxWeightSeen = uWeight;
        // Now that this vertex is closed, we can store its weight for use as a lower bound / heuristic value.
        // We don't implement decrease-key operations though, so check whether a smaller value is already known.
        double uWeightOld = postBoardingWeights.get(u);
        if (uWeight < uWeightOld) {
            // Including when uWeightOld is infinite because the vertex is not yet closed.
            postBoardingWeights.put(u, uWeight);
        } else {
            // The vertex was already closed. This time it necessarily has a higher weight, so skip it.
            continue;
        }
        // When the main search is arriveBy the heuristic search looks at OUTgoing edges.
        for (Edge e : routingRequest.arriveBy ? u.getOutgoing() : u.getIncoming()) {
            // Do not enter streets in this phase, which should only touch transit.
            if (e instanceof StreetTransitLink) {
                continue;
            }
            Vertex v = routingRequest.arriveBy ? e.getToVertex() : e.getFromVertex();
            double edgeWeight = e.weightLowerBound(routingRequest);
            // this saves time by not reverse-exploring those routes and avoids maxFound of INF.
            if (Double.isInfinite(edgeWeight)) {
                continue;
            }
            double vWeight = uWeight + edgeWeight;
            double vWeightOld = postBoardingWeights.get(v);
            if (vWeight < vWeightOld) {
                // Should only happen when vWeightOld is infinite because it is not yet closed.
                transitQueue.insert(v, vWeight);
            }
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Edge(org.opentripplanner.routing.graph.Edge)

Example 88 with Vertex

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

the class LinkingTest method jaggedArrayToVertexMap.

private TObjectIntMap<String> jaggedArrayToVertexMap(int[] value, Graph g) {
    TObjectIntMap<String> ret = new TObjectIntHashMap<String>();
    for (int i = 0; i < value.length; i++) {
        Vertex v = g.getVertexById(value[i++]);
        if (!v.getLabel().startsWith("osm:node"))
            continue;
        ret.put(v.getLabel(), value[i]);
    }
    return ret;
}
Also used : SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) LineString(com.vividsolutions.jts.geom.LineString)

Example 89 with Vertex

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

the class GraphVisualizer method traceOld.

protected void traceOld() {
    HashSet<Vertex> seenVertices = new HashSet<Vertex>();
    DisplayVertex selected = (DisplayVertex) nearbyVertices.getSelectedValue();
    if (selected == null) {
        System.out.println("no vertex selected");
        return;
    }
    Vertex v = selected.vertex;
    System.out.println("initial vertex: " + v);
    Queue<Vertex> toExplore = new LinkedList<Vertex>();
    toExplore.add(v);
    seenVertices.add(v);
    while (!toExplore.isEmpty()) {
        Vertex src = toExplore.poll();
        for (Edge e : src.getOutgoing()) {
            Vertex tov = e.getToVertex();
            if (!seenVertices.contains(tov)) {
                seenVertices.add(tov);
                toExplore.add(tov);
            }
        }
    }
    showGraph.setHighlightedVertices(seenVertices);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 90 with Vertex

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

the class GraphVisualizer method trace.

protected void trace() {
    DisplayVertex selected = (DisplayVertex) nearbyVertices.getSelectedValue();
    if (selected == null) {
        return;
    }
    Vertex v = selected.vertex;
    if (tracingVertex != v) {
        tracingVertex = v;
        closed = new HashSet<Vertex>();
        open = new HashSet<Vertex>();
        open.add(v);
        seen = new HashSet<Vertex>();
    }
    HashSet<Vertex> newOpen = new HashSet<Vertex>();
    for (Vertex v2 : open) {
        closed.add(v2);
        for (Edge e : v2.getOutgoing()) {
            Vertex target = e.getToVertex();
            if (closed.contains(target)) {
                continue;
            }
            newOpen.add(target);
        }
    }
    seen.addAll(newOpen);
    open = newOpen;
    showGraph.setHighlightedVertices(seen);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

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