use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.
the class DijkstraBidirectionRef method updateBestPath.
@Override
protected void updateBestPath(EdgeIteratorState edgeState, SPTEntry entryCurrent, int traversalId) {
SPTEntry entryOther = bestWeightMapOther.get(traversalId);
if (entryOther == null)
return;
boolean reverse = bestWeightMapFrom == bestWeightMapOther;
// update μ
double newWeight = entryCurrent.weight + entryOther.weight;
if (traversalMode.isEdgeBased()) {
if (entryOther.edge != entryCurrent.edge)
throw new IllegalStateException("cannot happen for edge based execution of " + getName());
if (entryOther.adjNode != entryCurrent.adjNode) {
// prevents the path to contain the edge at the meeting point twice and subtract the weight (excluding turn weight => no previous edge)
entryCurrent = entryCurrent.parent;
newWeight -= weighting.calcWeight(edgeState, reverse, EdgeIterator.NO_EDGE);
} else if (!traversalMode.hasUTurnSupport())
// we detected a u-turn at meeting point, skip if not supported
return;
}
if (newWeight < bestPath.getWeight()) {
bestPath.setSwitchToFrom(reverse);
bestPath.setSPTEntry(entryCurrent);
bestPath.setWeight(newWeight);
bestPath.setSPTEntryTo(entryOther);
}
}
use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.
the class PathBidirRefTest method testExtract2.
@Test
public void testExtract2() {
Graph g = createGraph();
g.edge(1, 2, 10, false);
g.edge(2, 3, 20, false);
EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
EdgeIterator iter = explorer.setBaseNode(1);
iter.next();
PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 10);
pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 0);
explorer = g.createEdgeExplorer(new DefaultEdgeFilter(carEncoder, true, false));
iter = explorer.setBaseNode(3);
iter.next();
pw.edgeTo = new SPTEntry(iter.getEdge(), 2, 20);
pw.edgeTo.parent = new SPTEntry(EdgeIterator.NO_EDGE, 3, 0);
Path p = pw.extract();
assertEquals(Helper.createTList(1, 2, 3), p.calcNodes());
assertEquals(30, p.getDistance(), 1e-4);
}
use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.
the class PathBidirRefTest method testExtract.
@Test
public void testExtract() {
Graph g = createGraph();
g.edge(1, 2, 10, true);
PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
EdgeIterator iter = explorer.setBaseNode(1);
iter.next();
pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 0);
pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 10);
pw.edgeTo = new SPTEntry(EdgeIterator.NO_EDGE, 2, 0);
Path p = pw.extract();
assertEquals(Helper.createTList(1, 2), p.calcNodes());
assertEquals(10, p.getDistance(), 1e-4);
}
Aggregations