use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class AlternativeRoute method getAltNames.
static List<String> getAltNames(Graph graph, SPTEntry ee) {
if (ee == null || !EdgeIterator.Edge.isValid(ee.edge))
return Collections.emptyList();
EdgeIteratorState iter = graph.getEdgeIteratorState(ee.edge, Integer.MIN_VALUE);
if (iter == null)
return Collections.emptyList();
String str = iter.getName();
if (str.isEmpty())
return Collections.emptyList();
return Collections.singletonList(str);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class QueryGraph method createEdgeExplorer.
@Override
public EdgeExplorer createEdgeExplorer(final EdgeFilter edgeFilter) {
// re-use these objects between setBaseNode calls to prevent GC
final EdgeExplorer mainExplorer = baseGraph.createEdgeExplorer(edgeFilter);
final VirtualEdgeIterator virtualEdgeIterator = new VirtualEdgeIterator(edgeFilter, null);
return new EdgeExplorer() {
@Override
public EdgeIterator setBaseNode(int baseNode) {
if (isVirtualNode(baseNode)) {
List<EdgeIteratorState> virtualEdges = virtualEdgesAtVirtualNodes.get(baseNode - baseNodes);
return virtualEdgeIterator.reset(virtualEdges);
} else {
List<EdgeIteratorState> virtualEdges = virtualEdgesAtRealNodes.get(baseNode);
if (virtualEdges == null) {
return mainExplorer.setBaseNode(baseNode);
} else {
return virtualEdgeIterator.reset(virtualEdges);
}
}
}
};
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class EdgeChangeBuilder method addVirtualEdges.
/**
* Adds the virtual edges adjacent to the real tower nodes
*/
private void addVirtualEdges(boolean base, int node, int virtNode) {
QueryOverlay.EdgeChanges edgeChanges = edgeChangesAtRealNodes.get(node);
if (edgeChanges == null) {
edgeChanges = new QueryOverlay.EdgeChanges(2, 2);
edgeChangesAtRealNodes.put(node, edgeChanges);
}
EdgeIteratorState edge = base ? getVirtualEdge(virtNode * 4 + BASE_SNAP) : getVirtualEdge(virtNode * 4 + ADJ_SNAP);
edgeChanges.getAdditionalEdges().add(edge);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class EdgeBasedNodeContractorTest method testContractNodes_necessaryAlternative.
@Test
public void testContractNodes_necessaryAlternative() {
// 1
// | can't go 1->6->3
// v
// 2 -> 6 -> 3 -> 5 -> 4
// | ^
// -> 0-|
final EdgeIteratorState e6to0 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 0).setDistance(4));
final EdgeIteratorState e0to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 3).setDistance(5));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 6).setDistance(1));
final EdgeIteratorState e6to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 3).setDistance(1));
final EdgeIteratorState e3to5 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 5).setDistance(2));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 6).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 4).setDistance(2));
freeze();
setMaxLevelOnAllNodes();
setRestriction(1, 6, 3);
contractAllNodesInOrder();
checkShortcuts(// from contracting node 0: need a shortcut because of turn restriction
createShortcut(3, 6, e6to0, e0to3, 9, false, true), // 2) in case we come from 2->6 (going via node 0 would be more expensive)
createShortcut(5, 6, e6to0.getEdge(), e3to5.getEdge(), 7, e3to5.getEdge(), 11, false, true), createShortcut(5, 6, e6to3, e3to5, 3, false, true));
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class EdgeBasedNodeContractorTest method testContractNode_noUnnecessaryShortcut_witnessPathOfEqualWeight.
@RepeatedTest(10)
public void testContractNode_noUnnecessaryShortcut_witnessPathOfEqualWeight() {
// this test runs repeatedly because it might pass/fail by chance (because path lengths are equal)
// 0 -> 1 -> 5 <_
// v v \
// 2 -> 3 -> 4
GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 1).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 5).setDistance(1));
EdgeIteratorState e2to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(1));
EdgeIteratorState e3to4 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 5).setDistance(1));
EdgeIteratorState e5to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 3).setDistance(1));
freeze();
setMaxLevelOnAllNodes();
contractNodes(3, 2, 0, 1, 5, 4);
// when contracting node 2 there is a witness (1-5-3-4) and no shortcut from 1 to 4 should be introduced.
// what might be tricky here is that both the original path and the witness path have equal weight!
// so we have to make sure that the equal weight witness is not rejected to update the currently best
// path, or (depending on the implementation-specific edge traversal order) the original path does *not*
// update/overwrite the already found witness path.
checkShortcuts(createShortcut(2, 4, e2to3, e3to4, 2), createShortcut(5, 4, e5to3, e3to4, 2));
}
Aggregations