use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.
the class PathBidirRef method extract.
/**
* Extracts path from two shortest-path-tree
*/
@Override
public Path extract() {
if (sptEntry == null || edgeTo == null)
return this;
if (sptEntry.adjNode != edgeTo.adjNode)
throw new IllegalStateException("Locations of the 'to'- and 'from'-Edge has to be the same." + toString() + ", fromEntry:" + sptEntry + ", toEntry:" + edgeTo);
extractSW.start();
if (switchFromAndToSPTEntry) {
SPTEntry ee = sptEntry;
sptEntry = edgeTo;
edgeTo = ee;
}
int prevEdge = EdgeIterator.NO_EDGE;
SPTEntry currEdge = sptEntry;
while (EdgeIterator.Edge.isValid(currEdge.edge)) {
processEdge(currEdge.edge, currEdge.adjNode, prevEdge);
prevEdge = currEdge.edge;
currEdge = currEdge.parent;
}
setFromNode(currEdge.adjNode);
reverseOrder();
currEdge = edgeTo;
int tmpEdge = currEdge.edge;
while (EdgeIterator.Edge.isValid(tmpEdge)) {
currEdge = currEdge.parent;
processEdge(tmpEdge, currEdge.adjNode, currEdge.edge);
tmpEdge = currEdge.edge;
}
setEndNode(currEdge.adjNode);
extractSW.stop();
return setFound(true);
}
use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.
the class Path method extract.
/**
* Extracts the Path from the shortest-path-tree determined by sptEntry.
*/
public Path extract() {
if (isFound())
throw new IllegalStateException("Extract can only be called once");
extractSW.start();
SPTEntry goalEdge = sptEntry;
int prevEdge = EdgeIterator.NO_EDGE;
setEndNode(goalEdge.adjNode);
while (EdgeIterator.Edge.isValid(goalEdge.edge)) {
processEdge(goalEdge.edge, goalEdge.adjNode, prevEdge);
prevEdge = goalEdge.edge;
goalEdge = goalEdge.parent;
}
setFromNode(goalEdge.adjNode);
reverseOrder();
extractSW.stop();
return setFound(true);
}
use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.
the class AbstractBinHeapTest method testSize.
@Test
public void testSize() {
PriorityQueue<SPTEntry> juQueue = new PriorityQueue<SPTEntry>(100);
BinHeapWrapper<Number, Integer> binHeap = createHeap(100);
Random rand = new Random(1);
int N = 1000;
for (int i = 0; i < N; i++) {
int val = rand.nextInt();
binHeap.insert(val, i);
juQueue.add(new SPTEntry(EdgeIterator.NO_EDGE, i, val));
}
assertEquals(juQueue.size(), binHeap.getSize());
for (int i = 0; i < N; i++) {
assertEquals(juQueue.poll().adjNode, binHeap.pollElement(), 1e-5);
}
assertEquals(binHeap.getSize(), 0);
}
use of com.graphhopper.storage.SPTEntry 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");
}
}
use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.
the class DijkstraBidirectionRef method fillEdges.
void fillEdges(SPTEntry currEdge, PriorityQueue<SPTEntry> prioQueue, IntObjectMap<SPTEntry> bestWeightMap, EdgeExplorer explorer, boolean reverse) {
EdgeIterator iter = explorer.setBaseNode(currEdge.adjNode);
while (iter.next()) {
if (!accept(iter, currEdge.edge))
continue;
int traversalId = traversalMode.createTraversalId(iter, reverse);
double tmpWeight = weighting.calcWeight(iter, reverse, currEdge.edge) + currEdge.weight;
if (Double.isInfinite(tmpWeight))
continue;
SPTEntry ee = bestWeightMap.get(traversalId);
if (ee == null) {
ee = new SPTEntry(iter.getEdge(), iter.getAdjNode(), tmpWeight);
ee.parent = currEdge;
bestWeightMap.put(traversalId, ee);
prioQueue.add(ee);
} else if (ee.weight > tmpWeight) {
prioQueue.remove(ee);
ee.edge = iter.getEdge();
ee.weight = tmpWeight;
ee.parent = currEdge;
prioQueue.add(ee);
} else
continue;
if (updateBestPath)
updateBestPath(iter, ee, traversalId);
}
}
Aggregations