use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class CHTurnCostTest method testFindPath_randomContractionOrder_singleLoopWithNoise.
@RepeatedTest(10)
public void testFindPath_randomContractionOrder_singleLoopWithNoise() {
// 0~15~16~17 solid lines: paths contributing to shortest path from 0 to 14
// | { wiggly lines: extra paths to make it more complicated
// 1~ 2- 3~ 4
// | | | {
// 6- 7- 8 9
// } | } }
// 11~12-13-14
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 6).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 7).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(7, 8).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 3).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 2).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 7).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(7, 12).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(12, 13).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(13, 14).setDistance(2));
// some more edges to make it more complicated -> potentially find more bugs
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(8));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 11).setDistance(3));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(11, 12).setDistance(50));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 13).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 15).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(15, 16).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(16, 17).setDistance(3));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(17, 4).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 9).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(9, 14).setDistance(2));
graph.freeze();
// enforce loop (going counter-clockwise)
setRestriction(6, 7, 12);
setTurnCost(8, 3, 2, 2);
setTurnCost(2, 3, 8, 4);
// make alternative paths not worth it
setTurnCost(1, 2, 7, 3);
setTurnCost(7, 8, 13, 8);
setTurnCost(8, 13, 14, 7);
setTurnCost(16, 17, 4, 4);
setTurnCost(4, 9, 14, 3);
setTurnCost(3, 4, 9, 3);
final IntArrayList expectedPath = IntArrayList.from(0, 1, 6, 7, 8, 3, 2, 7, 12, 13, 14);
final int roadCosts = 15;
final int turnCosts = 2;
checkPathUsingRandomContractionOrder(expectedPath, roadCosts, turnCosts, 0, 14);
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class CHTurnCostTest method testFindPath_loopsMustAlwaysBeAccepted.
@Test
public void testFindPath_loopsMustAlwaysBeAccepted() {
// ---
// \ /
// 0 -- 1 -- 2 -- 3
EdgeIteratorState edge0 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 1).setDistance(1));
EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(1));
EdgeIteratorState edge3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(1));
setTurnCost(edge0, edge1, 1, 1);
setRestriction(edge0, edge2, 1);
graph.freeze();
final IntArrayList expectedPath = IntArrayList.from(0, 1, 1, 2, 3);
checkPath(expectedPath, 4, 1, 0, 3, new int[] { 0, 2, 1, 3 });
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class CHTurnCostTest method testFindPath_randomContractionOrder_complicatedGraphAndPath.
@RepeatedTest(10)
public void testFindPath_randomContractionOrder_complicatedGraphAndPath() {
// In this test we try to find a rather complicated shortest path including a double loop and two p-turns
// with several turn restrictions and turn costs.
// 0 solid lines: paths contributing to shortest path from 0 to 26
// | wiggly lines: extra paths to make it more complicated
// 1~ 2- 3<~4- 5
// \ | | | |
// 6->7->8~ 9-10
// | |\ |
// 11-12 13-14~15~27
// { { | }
// 16-17-18-19-20~28
// | { { | | }
// 21-22-23-24 25-26
// first we add all edges that contribute to the shortest path, verticals: cost=1, horizontals: cost=2
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 7).setDistance(3));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(7, 8).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 3).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 2).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 7).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(7, 12).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(12, 11).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(11, 6).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 7).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(7, 13).setDistance(3));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(13, 14).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(14, 9).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(9, 4).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 5).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 10).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(10, 9).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(14, 19).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(19, 18).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(18, 17).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(17, 16).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(16, 21).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(21, 22).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(22, 23).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(23, 24).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(24, 19).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(19, 20).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(20, 25).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(25, 26).setDistance(2));
// some more edges to make it more complicated -> potentially find more bugs
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 3).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 9).setDistance(75));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(17, 22).setDistance(9));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(18, 23).setDistance(15));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(12, 17).setDistance(50));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(13, 18).setDistance(80));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(14, 15).setDistance(3));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(15, 27).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(27, 28).setDistance(100));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(28, 26).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(20, 28).setDistance(1));
graph.freeze();
// enforce figure of eight curve at node 7
setRestriction(1, 7, 13);
setTurnCost(1, 7, 12, 7);
setTurnCost(2, 7, 13, 7);
// enforce p-loop at the top right (going counter-clockwise)
setRestriction(13, 14, 19);
setTurnCost(4, 5, 10, 3);
setTurnCost(10, 5, 4, 2);
// enforce big p-loop at bottom left (going clockwise)
setRestriction(14, 19, 20);
setTurnCost(17, 16, 21, 3);
// make some alternative paths not worth it
setTurnCost(1, 2, 7, 8);
setTurnCost(20, 28, 26, 3);
// add some more turn costs on the shortest path
setTurnCost(7, 13, 14, 2);
// expected costs of the shortest path
final IntArrayList expectedPath = IntArrayList.from(0, 1, 7, 8, 3, 2, 7, 12, 11, 6, 7, 13, 14, 9, 10, 5, 4, 9, 14, 19, 24, 23, 22, 21, 16, 17, 18, 19, 20, 25, 26);
final int roadCosts = 49;
final int turnCosts = 4;
checkPathUsingRandomContractionOrder(expectedPath, roadCosts, turnCosts, 0, 26);
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class CHTurnCostTest method testFindPath_pTurn_uTurnAtContractedNode.
@Test
public void testFindPath_pTurn_uTurnAtContractedNode() {
// when contracting node 4 we need a loop shortcut at node 6
// 2- 3
// | |
// 4- 0
// |
// 5 -> 6 -> 1
GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 6).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 1).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 0).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 3).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 4).setDistance(1));
graph.freeze();
setRestriction(5, 6, 1);
final IntArrayList expectedPath = IntArrayList.from(5, 6, 4, 0, 3, 2, 4, 6, 1);
checkPath(expectedPath, 8, 0, 5, 1, new int[] { 0, 1, 2, 3, 4, 5, 6 });
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class CHTurnCostTest method checkPathUsingRandomContractionOrder.
private void checkPathUsingRandomContractionOrder(IntArrayList expectedPath, int expectedWeight, int expectedTurnCosts, int from, int to) {
IntArrayList contractionOrder = getRandomIntegerSequence(graph.getNodes(), new Random());
checkPath(expectedPath, expectedWeight, expectedTurnCosts, from, to, contractionOrder.toArray());
}
Aggregations