use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class EdgeBasedNodeContractorTest method testContractNode_twoNormalEdges_bidirectional.
@Test
public void testContractNode_twoNormalEdges_bidirectional() {
// 0 -- 3 -- 2 -- 4 -- 1
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 3).setDistance(1));
final EdgeIteratorState e3to2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 2).setDistance(3));
final EdgeIteratorState e2to4 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 4).setDistance(5));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 1).setDistance(1));
setTurnCost(e3to2, e2to4, 2, 4);
setTurnCost(e2to4, e3to2, 2, 4);
freeze();
setMaxLevelOnAllNodes();
contractNodes(2, 0, 1, 3, 4);
checkShortcuts(// places
createShortcut(3, 4, e3to2, e2to4, 12, true, false), createShortcut(3, 4, e2to4, e3to2, 12, false, true));
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class EdgeBasedNodeContractorTest method testContractNode_shortcutDoesNotSpanUTurn.
@Test
public void testContractNode_shortcutDoesNotSpanUTurn() {
// 2 -> 7 -> 3 -> 5 -> 6
// |
// 1 <-> 4
final EdgeIteratorState e7to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(7, 3).setDistance(1));
final EdgeIteratorState e3to5 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 5).setDistance(1));
final EdgeIteratorState e3to4 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(2));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 7).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 6).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 4).setDistance(1));
freeze();
setMaxLevelOnAllNodes();
setRestriction(7, 3, 5);
contractNodes(3, 4, 2, 6, 7, 5, 1);
checkShortcuts(// from contracting node 3
createShortcut(4, 7, e7to3, e3to4, 3, false, true), createShortcut(4, 5, e3to4, e3to5, 3, true, false));
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class EdgeBasedNodeContractorTest method testNodeContraction_zeroWeightLoop_twoLoopsAndEdge_withTurnRestriction.
@Test
public void testNodeContraction_zeroWeightLoop_twoLoopsAndEdge_withTurnRestriction() {
// /|
// 0 -> 1 -> 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));
EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(1));
EdgeIteratorState edge3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 3).setDistance(0));
EdgeIteratorState edge4 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 4).setDistance(1));
// add a few more loops to make this test more difficult to pass
GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 3).setDistance(0));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 3).setDistance(0));
// we have to use the zero weight loop so it may not be excluded
setTurnCost(edge2, edge3, 3, 5);
setRestriction(edge2, edge4, 3);
freeze();
setMaxLevelOnAllNodes();
contractNodes(2, 0, 4, 1, 3);
checkNumShortcuts(1);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class EdgeBasedNodeContractorTest method testNodeContraction_duplicateEdge_severalLoops.
@Test
public void testNodeContraction_duplicateEdge_severalLoops() {
// 5 -- 4 -- 3 -- 1
// |\ |
// | \ /
// -- 2
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 3).setDistance(47));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 4).setDistance(19));
EdgeIteratorState e2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 5).setDistance(38));
// note there is a duplicate edge here (with different weight)
EdgeIteratorState e3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 5).setDistance(57));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(10));
EdgeIteratorState e5 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 5).setDistance(56));
setTurnCost(e3, e2, 5, 4);
setTurnCost(e2, e3, 5, 5);
setTurnCost(e5, e3, 5, 3);
setTurnCost(e3, e5, 5, 2);
setTurnCost(e2, e5, 5, 2);
setTurnCost(e5, e2, 5, 1);
freeze();
setMaxLevelOnAllNodes();
contractNodes(4, 5, 1, 3, 2);
// note that the shortcut edge ids depend on the insertion order which might change when changing the implementation
checkNumShortcuts(11);
checkShortcuts(// from node 4 contraction
createShortcut(5, 3, 5, 4, 5, 4, 66, true, false), createShortcut(5, 3, 4, 5, 4, 5, 66, false, true), createShortcut(3, 2, 1, 4, 1, 4, 29, false, true), createShortcut(3, 2, 4, 1, 4, 1, 29, true, false), createShortcut(5, 2, 1, 5, 1, 5, 75, false, true), createShortcut(5, 2, 5, 1, 5, 1, 75, true, false), // from node 5 contraction
createShortcut(2, 2, 3, 2, 3, 2, 99, true, false), createShortcut(2, 2, 3, 1, 3, 6, 134, true, false), createShortcut(2, 2, 1, 2, 8, 2, 114, true, false), createShortcut(3, 2, 2, 4, 2, 7, 106, false, true), createShortcut(3, 2, 4, 2, 9, 2, 105, true, false));
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class NodeBasedNodeContractorTest method testDirectedGraph.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testDirectedGraph(boolean reverse) {
// 5 6 7
// \|/
// 4-3_1<-\ 10
// \_|/
// 0___2_11
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 2).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(10, 2).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(11, 2).setDistance(2));
// create a longer one directional edge => no longish one-dir shortcut should be created
final EdgeIteratorState edge2to1bidirected = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 1).setDistance(2));
final EdgeIteratorState edge2to1directed = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 1).setDistance(10));
final EdgeIteratorState edge1to3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 3).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 5).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 6).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 7).setDistance(2));
freeze();
setMaxLevelOnAllNodes();
// directed one
if (reverse) {
contractInOrder(1, 0, 11, 10, 4, 5, 6, 7, 3, 2);
checkShortcuts(expectedShortcut(3, 2, edge1to3, edge2to1bidirected, true, true));
} else {
contractInOrder(1, 0, 11, 10, 4, 5, 6, 7, 2, 3);
checkShortcuts(expectedShortcut(2, 3, edge2to1bidirected, edge1to3, true, true));
}
}
Aggregations