Skip to content

Commit

Permalink
Extract setTurnCost/Restriction in test
Browse files Browse the repository at this point in the history
  • Loading branch information
easbar committed Mar 5, 2020
1 parent 08f0f57 commit aa97389
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ public void directedRouting() {
int leftNorth = graph.edge(9, 0, 1, true).getEdge();

// make paths fully deterministic by applying some turn costs at junction node 2
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 7, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 3).getEdge(), 1);
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 7, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 6).getEdge(), 3);
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 1, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 3).getEdge(), 5);
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 1, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 6).getEdge(), 7);
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 1, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 7).getEdge(), 9);
setTurnCost(7, 2, 3, 1);
setTurnCost(7, 2, 6, 3);
setTurnCost(1, 2, 3, 5);
setTurnCost(1, 2, 6, 7);
setTurnCost(1, 2, 7, 9);

final double unitEdgeWeight = 0.06;
assertPath(calcPath(9, 9, leftNorth, leftSouth),
Expand Down Expand Up @@ -322,8 +322,8 @@ public void worksWithTurnCosts() {
graph.edge(4, 5, 1, true);
graph.edge(5, 2, 1, true);

turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 0, 3).getEdge(), 3, GHUtility.getEdge(graph, 3, 4).getEdge(), Double.POSITIVE_INFINITY);
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 4, 5).getEdge(), 5, GHUtility.getEdge(graph, 5, 2).getEdge(), 6);
setRestriction(0, 3, 4);
setTurnCost(4, 5, 2, 6);

// due to the restrictions we have to take the expensive path with turn costs
assertPath(calcPath(0, 2, 0, 6), 6.24, 4, 6240, nodes(0, 1, 4, 5, 2));
Expand Down Expand Up @@ -356,8 +356,8 @@ public void finiteUTurnCosts() {
int right6 = graph.edge(9, 6, 10, true).getEdge();

// enforce p-turn (using the loop in clockwise direction)
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 0, 1).getEdge(), 1, GHUtility.getEdge(graph, 1, 6).getEdge(), Double.POSITIVE_INFINITY);
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 5, 4).getEdge(), 4, GHUtility.getEdge(graph, 4, 3).getEdge(), Double.POSITIVE_INFINITY);
setRestriction(0, 1, 6);
setRestriction(5, 4, 3);

assertPath(calcPath(0, 6, right0, left6), 64.2, 1070, 64200, nodes(0, 1, 2, 3, 4, 5, 2, 1, 6));
// if the u-turn cost is finite it depends on its value if we rather do the p-turn or do an immediate u-turn at node 2
Expand Down Expand Up @@ -535,4 +535,12 @@ private void assertNotFound(Path path) {
assertEquals(0, path.getTime());
assertEquals(nodes(), path.calcNodes());
}

private void setRestriction(int fromNode, int node, int toNode) {
setTurnCost(fromNode, node, toNode, Double.POSITIVE_INFINITY);
}

private void setTurnCost(int fromNode, int node, int toNode, double turnCost) {
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, fromNode, node).getEdge(), node, GHUtility.getEdge(graph, node, toNode).getEdge(), turnCost);
}
}

0 comments on commit aa97389

Please sign in to comment.