Search in sources :

Example 46 with Edge

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

the class InterleavedBidirectionalHeuristic method streetSearch.

/**
 * Explore the streets around the origin or target, recording the minimum weight of a path to each street vertex.
 * When searching around the target, also retain the states that reach transit stops since we'll want to
 * explore the transit network backward, in order to guide the main forward search.
 *
 * The main search always proceeds from the "origin" to the "target" (names remain unchanged in arriveBy mode).
 * The reverse heuristic search always proceeds outward from the target (name remains unchanged in arriveBy).
 *
 * When the main search is departAfter:
 * it gets outgoing edges and traverses them with arriveBy=false,
 * the heuristic search gets incoming edges and traverses them with arriveBy=true,
 * the heuristic destination street search also gets incoming edges and traverses them with arriveBy=true,
 * the heuristic origin street search gets outgoing edges and traverses them with arriveBy=false.
 *
 * When main search is arriveBy:
 * it gets incoming edges and traverses them with arriveBy=true,
 * the heuristic search gets outgoing edges and traverses them with arriveBy=false,
 * the heuristic destination street search also gets outgoing edges and traverses them with arriveBy=false,
 * the heuristic origin street search gets incoming edges and traverses them with arriveBy=true.
 * The streetSearch method traverses using the real traverse method rather than the lower bound traverse method
 * because this allows us to keep track of the distance walked.
 * Perhaps rather than tracking walk distance, we should just check the straight-line radius and
 * only walk within that distance. This would avoid needing to call the main traversal functions.
 *
 * TODO what if the egress segment is by bicycle or car mode? This is no longer admissible.
 */
private TObjectDoubleMap<Vertex> streetSearch(RoutingRequest rr, boolean fromTarget, long abortTime) {
    LOG.debug("Heuristic street search around the {}.", fromTarget ? "target" : "origin");
    rr = rr.clone();
    if (fromTarget) {
        rr.setArriveBy(!rr.arriveBy);
    }
    // Create a map that returns Infinity when it does not contain a vertex.
    TObjectDoubleMap<Vertex> vertices = new TObjectDoubleHashMap<>(100, 0.5f, Double.POSITIVE_INFINITY);
    ShortestPathTree spt = new DominanceFunction.MinimumWeight().getNewShortestPathTree(rr);
    // TODO use normal OTP search for this.
    BinHeap<State> pq = new BinHeap<State>();
    Vertex initVertex = fromTarget ? rr.rctx.target : rr.rctx.origin;
    State initState = new State(initVertex, rr);
    pq.insert(initState, 0);
    while (!pq.empty()) {
        if (abortTime < Long.MAX_VALUE && System.currentTimeMillis() > abortTime) {
            return null;
        }
        State s = pq.extract_min();
        Vertex v = s.getVertex();
        // This is the lowest cost we will ever see for this vertex. We can record the cost to reach it.
        if (v instanceof TransitStop) {
            // place vertices on the transit queue so we can explore the transit network backward later.
            if (fromTarget) {
                double weight = s.getWeight();
                transitQueue.insert(v, weight);
                if (weight > maxWeightSeen) {
                    maxWeightSeen = weight;
                }
            }
            continue;
        }
        // Record the cost to reach this vertex.
        if (!vertices.containsKey(v)) {
            // FIXME time or weight? is RR using right mode?
            vertices.put(v, (int) s.getWeight());
        }
        for (Edge e : rr.arriveBy ? v.getIncoming() : v.getOutgoing()) {
            // arriveBy has been set to match actual directional behavior in this subsearch.
            // Walk cutoff will happen in the street edge traversal method.
            State s1 = e.traverse(s);
            if (s1 == null) {
                continue;
            }
            if (spt.add(s1)) {
                pq.insert(s1, s1.getWeight());
            }
        }
    }
    LOG.debug("Heuristric street search hit {} vertices.", vertices.size());
    LOG.debug("Heuristric street search hit {} transit stops.", transitQueue.size());
    return vertices;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) State(org.opentripplanner.routing.core.State) BinHeap(org.opentripplanner.common.pqueue.BinHeap) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction) Edge(org.opentripplanner.routing.graph.Edge)

Example 47 with Edge

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

the class AreaEdgeList method removeEdge.

public void removeEdge(AreaEdge edge) {
    edges.remove(edge);
    // reconstruct vertices
    vertices.clear();
    for (Edge e : edges) {
        vertices.add((IntersectionVertex) e.getFromVertex());
    }
}
Also used : Edge(org.opentripplanner.routing.graph.Edge)

Example 48 with Edge

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

the class RoutingContext method overlappingStreetEdges.

/**
 * Returns the StreetEdges that overlap between two vertices edge sets.
 */
private Set<StreetEdge> overlappingStreetEdges(Vertex u, Vertex v) {
    Set<Integer> vIds = new HashSet<Integer>();
    Set<Integer> uIds = new HashSet<Integer>();
    for (Edge e : Iterables.concat(v.getIncoming(), v.getOutgoing())) {
        vIds.add(e.getId());
    }
    for (Edge e : Iterables.concat(u.getIncoming(), u.getOutgoing())) {
        uIds.add(e.getId());
    }
    // Intesection of edge IDs between u and v.
    uIds.retainAll(vIds);
    Set<Integer> overlappingIds = uIds;
    // Fetch the edges by ID - important so we aren't stuck with temporary edges.
    Set<StreetEdge> overlap = new HashSet<>();
    for (Integer id : overlappingIds) {
        Edge e = graph.getEdgeById(id);
        if (e == null || !(e instanceof StreetEdge)) {
            continue;
        }
        overlap.add((StreetEdge) e);
    }
    return overlap;
}
Also used : TemporaryPartialStreetEdge(org.opentripplanner.routing.edgetype.TemporaryPartialStreetEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TemporaryPartialStreetEdge(org.opentripplanner.routing.edgetype.TemporaryPartialStreetEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 49 with Edge

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

the class GraphVisualizer method checkGraph.

protected void checkGraph() {
    HashSet<Vertex> seenVertices = new HashSet<Vertex>();
    Collection<Vertex> allVertices = getGraph().getVertices();
    Vertex v = allVertices.iterator().next();
    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);
            }
        }
    }
    System.out.println("After investigation, visited " + seenVertices.size() + " of " + allVertices.size());
    /* now, let's find an unvisited vertex */
    for (Vertex u : allVertices) {
        if (!seenVertices.contains(u)) {
            System.out.println("unvisited vertex" + u);
            break;
        }
    }
}
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 50 with Edge

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

the class GraphVisualizer method initRightPanel.

private void initRightPanel(Container pane) {
    /* right panel holds trip pattern and stop metadata */
    JPanel rightPanel = new JPanel();
    rightPanel.setLayout(new BorderLayout());
    pane.add(rightPanel, BorderLayout.LINE_END);
    JTabbedPane rightPanelTabs = new JTabbedPane();
    rightPanel.add(rightPanelTabs, BorderLayout.LINE_END);
    // a place to print out the details of a path
    pathStates = new JList<State>();
    JScrollPane stScrollPane = new JScrollPane(pathStates);
    stScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    rightPanelTabs.addTab("path states", stScrollPane);
    // when you select a path component state, it prints the backedge's metadata
    pathStates.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            outgoingEdges.clearSelection();
            incomingEdges.clearSelection();
            @SuppressWarnings("unchecked") JList<State> theList = (JList<State>) e.getSource();
            State st = (State) theList.getSelectedValue();
            Edge edge = st.getBackEdge();
            reactToEdgeSelection(edge, false);
        }
    });
    metadataList = new JList<String>();
    metadataModel = new DefaultListModel<String>();
    metadataList.setModel(metadataModel);
    JScrollPane mdScrollPane = new JScrollPane(metadataList);
    mdScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    rightPanelTabs.addTab("metadata", mdScrollPane);
    // This is where matched annotations from an annotation search go
    annotationMatches = new JList<GraphBuilderAnnotation>();
    annotationMatches.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            @SuppressWarnings("unchecked") JList<GraphBuilderAnnotation> theList = (JList<GraphBuilderAnnotation>) e.getSource();
            GraphBuilderAnnotation anno = theList.getSelectedValue();
            if (anno == null)
                return;
            showGraph.drawAnotation(anno);
        }
    });
    annotationMatchesModel = new DefaultListModel<GraphBuilderAnnotation>();
    annotationMatches.setModel(annotationMatchesModel);
    JScrollPane amScrollPane = new JScrollPane(annotationMatches);
    amScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    rightPanelTabs.addTab("annotations", amScrollPane);
    Dimension size = new Dimension(200, 1600);
    amScrollPane.setMaximumSize(size);
    amScrollPane.setPreferredSize(size);
    stScrollPane.setMaximumSize(size);
    stScrollPane.setPreferredSize(size);
    mdScrollPane.setMaximumSize(size);
    mdScrollPane.setPreferredSize(size);
    rightPanelTabs.setMaximumSize(size);
    rightPanel.setMaximumSize(size);
}
Also used : GraphBuilderAnnotation(org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) State(org.opentripplanner.routing.core.State) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

Edge (org.opentripplanner.routing.graph.Edge)113 Vertex (org.opentripplanner.routing.graph.Vertex)61 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)53 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)26 HashSet (java.util.HashSet)23 State (org.opentripplanner.routing.core.State)22 Coordinate (com.vividsolutions.jts.geom.Coordinate)19 Graph (org.opentripplanner.routing.graph.Graph)19 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)18 Test (org.junit.Test)17 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)17 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)17 ArrayList (java.util.ArrayList)16 LineString (com.vividsolutions.jts.geom.LineString)15 GraphPath (org.opentripplanner.routing.spt.GraphPath)15 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)12 PathwayEdge (org.opentripplanner.routing.edgetype.PathwayEdge)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 Stop (org.onebusaway.gtfs.model.Stop)9 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)9