use of com.graphhopper.util.EdgeIterator 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.util.EdgeIterator 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.util.EdgeIterator 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);
}
use of com.graphhopper.util.EdgeIterator in project graphhopper by graphhopper.
the class OSMTurnRelation method getRestrictionAsEntries.
/**
* Transforms this relation into a collection of turn cost entries
* <p>
*
* @param edgeOutExplorer an edge filter which only allows outgoing edges
* @param edgeInExplorer an edge filter which only allows incoming edges
* @return a collection of node cost entries which can be added to the graph later
*/
public Collection<TurnCostTableEntry> getRestrictionAsEntries(TurnCostEncoder encoder, EdgeExplorer edgeOutExplorer, EdgeExplorer edgeInExplorer, OSMReader osmReader) {
int nodeVia = osmReader.getInternalNodeIdOfOsmNode(this.viaOsmNodeId);
try {
// street with restriction was not included (access or tag limits etc)
if (nodeVia == OSMReader.EMPTY_NODE)
return Collections.emptyList();
int edgeIdFrom = EdgeIterator.NO_EDGE;
// get all incoming edges and receive the edge which is defined by fromOsm
EdgeIterator iter = edgeInExplorer.setBaseNode(nodeVia);
while (iter.next()) {
if (osmReader.getOsmIdOfInternalEdge(iter.getEdge()) == this.fromOsmWayId) {
edgeIdFrom = iter.getEdge();
break;
}
}
if (edgeIdFrom == EdgeIterator.NO_EDGE)
return Collections.emptyList();
final Collection<TurnCostTableEntry> entries = new ArrayList<TurnCostTableEntry>();
// get all outgoing edges of the via node
iter = edgeOutExplorer.setBaseNode(nodeVia);
// for TYPE_NOT_* we add ONE restriction (from, via, to)
while (iter.next()) {
int edgeId = iter.getEdge();
long wayId = osmReader.getOsmIdOfInternalEdge(edgeId);
if (edgeId != edgeIdFrom && this.restriction == Type.ONLY && wayId != this.toOsmWayId || this.restriction == Type.NOT && wayId == this.toOsmWayId && wayId >= 0) {
final TurnCostTableEntry entry = new TurnCostTableEntry();
entry.nodeVia = nodeVia;
entry.edgeFrom = edgeIdFrom;
entry.edgeTo = iter.getEdge();
entry.flags = encoder.getTurnFlags(true, 0);
entries.add(entry);
if (this.restriction == Type.NOT)
break;
}
}
return entries;
} catch (Exception e) {
throw new IllegalStateException("Could not built turn table entry for relation of node with osmId:" + this.viaOsmNodeId, e);
}
}
Aggregations