Search in sources :

Example 16 with EdgeExplorer

use of com.graphhopper.util.EdgeExplorer in project graphhopper by graphhopper.

the class Dijkstra method runAlgo.

protected void runAlgo() {
    EdgeExplorer explorer = outEdgeExplorer;
    while (true) {
        visitedNodes++;
        if (isMaxVisitedNodesExceeded() || finished())
            break;
        int startNode = currEdge.adjNode;
        EdgeIterator iter = explorer.setBaseNode(startNode);
        while (iter.next()) {
            if (!accept(iter, currEdge.edge))
                continue;
            int traversalId = traversalMode.createTraversalId(iter, false);
            double tmpWeight = weighting.calcWeight(iter, false, currEdge.edge) + currEdge.weight;
            if (Double.isInfinite(tmpWeight))
                continue;
            SPTEntry nEdge = fromMap.get(traversalId);
            if (nEdge == null) {
                nEdge = new SPTEntry(iter.getEdge(), iter.getAdjNode(), tmpWeight);
                nEdge.parent = currEdge;
                fromMap.put(traversalId, nEdge);
                fromHeap.add(nEdge);
            } else if (nEdge.weight > tmpWeight) {
                fromHeap.remove(nEdge);
                nEdge.edge = iter.getEdge();
                nEdge.weight = tmpWeight;
                nEdge.parent = currEdge;
                fromHeap.add(nEdge);
            } else
                continue;
            updateBestPath(iter, nEdge, traversalId);
        }
        if (fromHeap.isEmpty())
            break;
        currEdge = fromHeap.poll();
        if (currEdge == null)
            throw new AssertionError("Empty edge cannot happen");
    }
}
Also used : SPTEntry(com.graphhopper.storage.SPTEntry) EdgeIterator(com.graphhopper.util.EdgeIterator) EdgeExplorer(com.graphhopper.util.EdgeExplorer)

Aggregations

EdgeExplorer (com.graphhopper.util.EdgeExplorer)16 Test (org.junit.Test)11 Graph (com.graphhopper.storage.Graph)8 GraphBuilder (com.graphhopper.storage.GraphBuilder)6 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)4 EdgeIterator (com.graphhopper.util.EdgeIterator)4 SPTEntry (com.graphhopper.storage.SPTEntry)3 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 HashMap (java.util.HashMap)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)1 GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 Agency (com.conveyal.gtfs.model.Agency)1 Fare (com.conveyal.gtfs.model.Fare)1 StopTime (com.conveyal.gtfs.model.StopTime)1 Trip (com.conveyal.gtfs.model.Trip)1