Skip to content

Commit

Permalink
Rename addTurnCost/Restriction -> setTurnCost/Restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
easbar committed Nov 24, 2019
1 parent 42a541c commit 967f536
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private NodeContractor createNodeContractor(Graph graph, TraversalMode traversal
}

private TurnWeighting createTurnWeightingForEdgeBased(Graph graph) {
// important: do not simply take the turn cost storage from ghStorage, because we need the wrapped extension from
// important: do not simply take the turn cost storage from ghStorage, because we need the wrapped storage from
// query graph!
TurnCostStorage turnCostStorage = graph.getTurnCostStorage();
if (turnCostStorage == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,7 @@ private VirtualEdgeIteratorState getVirtualEdge(int edgeId) {

private int getPosOfReverseEdge(int edgeId) {
// find reverse edge via convention. see virtualEdges comment above
if (edgeId % 2 == 0)
edgeId++;
else
edgeId--;

return edgeId;
return edgeId % 2 == 0 ? edgeId + 1 : edgeId - 1;
}

@Override
Expand Down Expand Up @@ -394,5 +389,4 @@ List<VirtualEdgeIteratorState> getVirtualEdges() {
private UnsupportedOperationException exc() {
return new UnsupportedOperationException("QueryGraph cannot be modified.");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testFindPathWithTurnCosts_bidirected_no_shortcuts_smallGraph() {
// 1 -- 0 -- 2
graph.edge(1, 0, 3, true);
graph.edge(0, 2, 5, true);
addTurnCost(1, 0, 2, 3);
setTurnCost(1, 0, 2, 3);
graph.freeze();

// contraction yields no shortcuts for edge based case (at least without u-turns).
Expand All @@ -100,10 +100,10 @@ public void testFindPathWithTurnCosts_bidirected_no_shortcuts() {
graph.edge(6, 5, 9, true);
graph.edge(5, 3, 1, true);
graph.edge(3, 1, 4, true);
addTurnCost(0, 2, 4, 3);
addTurnCost(4, 6, 5, 6);
addTurnCost(5, 6, 4, 2);
addTurnCost(5, 3, 1, 5);
setTurnCost(0, 2, 4, 3);
setTurnCost(4, 6, 5, 6);
setTurnCost(5, 6, 4, 2);
setTurnCost(5, 3, 1, 5);
graph.freeze();

// contraction yields no shortcuts
Expand Down Expand Up @@ -141,9 +141,9 @@ public void testFindPathWithTurnCosts_loopShortcutBwdSearch() {
graph.edge(2, 4, 1, false);
graph.edge(4, 6, 1, false);
graph.edge(6, 5, 1, false);
addRestriction(8, 4, 6);
addRestriction(8, 4, 2);
addRestriction(1, 4, 6);
setRestriction(8, 4, 6);
setRestriction(8, 4, 2);
setRestriction(1, 4, 6);

graph.freeze();

Expand Down Expand Up @@ -178,9 +178,9 @@ public void testFindPathWithTurnCosts_loopShortcutFwdSearch() {
graph.edge(4, 7, 1, false);
graph.edge(7, 8, 1, false);
graph.edge(8, 0, 1, false);
addRestriction(6, 4, 7);
addRestriction(6, 4, 2);
addRestriction(1, 4, 7);
setRestriction(6, 4, 7);
setRestriction(6, 4, 2);
setRestriction(1, 4, 7);
graph.freeze();

// from contracting node 1
Expand All @@ -207,9 +207,9 @@ public void testFindPathWithTurnCosts_directed_single_shortcut() {
graph.edge(2, 0, 2, false);
graph.edge(0, 3, 3, false);
graph.edge(3, 4, 2, false);
addTurnCost(1, 2, 0, 5);
addTurnCost(2, 0, 3, 2);
addTurnCost(0, 3, 4, 1);
setTurnCost(1, 2, 0, 5);
setTurnCost(2, 0, 3, 2);
setTurnCost(0, 3, 4, 1);
graph.freeze();

// only when node 0 is contracted a shortcut is added
Expand Down Expand Up @@ -237,8 +237,8 @@ public void testFindPathWithTurnCosts_directed_single_shortcut_fwdSearchStopsQui
graph.edge(2, 4, 3, false);
graph.freeze();

addTurnCost(1, 3, 0, 2);
addTurnCost(0, 2, 4, 4);
setTurnCost(1, 3, 0, 2);
setTurnCost(0, 2, 4, 4);

// from contracting node 0
addShortcut(3, 2, 1, 2, 1, 2, 4);
Expand All @@ -257,9 +257,9 @@ public void testFindPathWithTurnCosts_directed_two_shortcuts() {
graph.edge(3, 1, 2, false);
graph.edge(1, 0, 3, false);
graph.edge(0, 4, 2, false);
addTurnCost(2, 3, 1, 5);
addTurnCost(3, 1, 0, 2);
addTurnCost(1, 0, 4, 1);
setTurnCost(2, 3, 1, 5);
setTurnCost(3, 1, 0, 2);
setTurnCost(1, 0, 4, 1);
graph.freeze();

// contraction of node 0 and 1 each yield a single shortcut
Expand All @@ -286,7 +286,7 @@ public void testFindPath_directConnectionIsNotTheBestPath() {
graph.edge(2, 3, 2, false);
graph.edge(3, 1, 9, false);
graph.edge(0, 1, 50, false);
addTurnCost(2, 3, 1, 4);
setTurnCost(2, 3, 1, 4);
graph.freeze();

// no shortcuts here
Expand All @@ -308,7 +308,7 @@ public void testFindPath_upwardSearchRunsIntoTarget() {
graph.edge(3, 4, 4, false);
graph.edge(5, 4, 6, false);
graph.edge(4, 2, 3, false);
addTurnCost(1, 3, 4, 3);
setTurnCost(1, 3, 4, 3);
graph.freeze();

// no shortcuts here
Expand Down Expand Up @@ -357,10 +357,10 @@ public void testFindPathWithTurnCosts_fwdBwdSearchesMeetWithUTurn() {
graph.edge(0, 2, 1, false);
graph.edge(2, 3, 2, true);
graph.edge(2, 1, 3, false);
addRestriction(0, 2, 1);
addTurnCost(0, 2, 3, 5);
addTurnCost(2, 3, 2, 4);
addTurnCost(3, 2, 1, 7);
setRestriction(0, 2, 1);
setTurnCost(0, 2, 3, 5);
setTurnCost(2, 3, 2, 4);
setTurnCost(3, 2, 1, 7);
graph.freeze();

// contraction yields no shortcuts
Expand Down Expand Up @@ -402,7 +402,7 @@ private void checkUTurnNotBeingUsed(boolean toLowerLevelNode) {
final EdgeIteratorState e3toB = graph.edge(3, nodeB, 2, false);
final EdgeIteratorState e3toA = graph.edge(3, nodeA, 1, true);
graph.freeze();
addRestriction(0, 3, nodeB);
setRestriction(0, 3, nodeB);

// one shortcut when contracting node 3
addShortcut(nodeA, nodeB, e3toA.getEdge(), e3toB.getEdge(), e3toA.getEdge(), e3toB.getEdge(), 2);
Expand All @@ -422,8 +422,8 @@ public void testFindPathWithTurnCosts_loop() {
final EdgeIteratorState edge3 = graph.edge(3, 2, 7, false);
final EdgeIteratorState edge4 = graph.edge(2, 1, 3, false);
// need to specify edges explicitly because there are two edges between nodes 2 and 3
addRestriction(edge1, edge4, 2);
addTurnCost(edge1, edge2, 2, 3);
setRestriction(edge1, edge4, 2);
setTurnCost(edge1, edge2, 2, 3);
graph.freeze();

// no shortcuts
Expand All @@ -449,9 +449,9 @@ public void testFindPathWithTurnCosts_multiple_bridge_nodes() {
graph.edge(2, 1, 1, false);
graph.edge(3, 1, 2, false);
graph.edge(4, 1, 6, false);
addTurnCost(0, 2, 1, 9);
addTurnCost(0, 3, 1, 2);
addTurnCost(0, 4, 1, 1);
setTurnCost(0, 2, 1, 9);
setTurnCost(0, 3, 1, 2);
setTurnCost(0, 4, 1, 1);
graph.freeze();

// contraction yields no shortcuts
Expand All @@ -471,7 +471,7 @@ public void testFindPath_loopIsRecognizedAsIncomingEdge() {
EdgeIteratorState edge1 = graph.edge(3, 3, 1, false);
EdgeIteratorState edge2 = graph.edge(3, 2, 1, true);
EdgeIteratorState edge3 = graph.edge(2, 1, 1, false);
addRestriction(edge0, edge2, 3);
setRestriction(edge0, edge2, 3);
graph.freeze();

// contraction yields no shortcuts
Expand All @@ -494,7 +494,7 @@ public void testFindPath_shortcutLoopIsRecognizedAsIncomingEdge() {
EdgeIteratorState edge2 = graph.edge(2, 0, 1, false);
EdgeIteratorState edge3 = graph.edge(0, 2, 1, false);
EdgeIteratorState edge4 = graph.edge(2, 1, 1, false);
addRestriction(edge1, edge4, 2);
setRestriction(edge1, edge4, 2);
graph.freeze();

// contracting node 0 yields (the only) shortcut - and its a loop
Expand Down Expand Up @@ -524,7 +524,7 @@ public void testFindPathWithTurnRestriction_single_loop() {
graph.edge(0, 1, 3, false);
graph.edge(4, 1, 5, true);
graph.edge(4, 2, 4, false);
addRestriction(3, 4, 2);
setRestriction(3, 4, 2);
graph.freeze();

// contracting node 0
Expand Down Expand Up @@ -570,7 +570,7 @@ private void runTestWithSingleLoop(boolean loopInFwdSearch) {
graph.edge(1, 5, 1, false);
graph.edge(5, nodeB, 1, false);
graph.edge(nodeB, 7, 2, false);
addRestriction(nodeA, 5, nodeB);
setRestriction(nodeA, 5, nodeB);
graph.freeze();
addShortcut(3, 5, 4, 5, 4, 5, 3);
addShortcut(5, 3, 2, 3, 2, 3, 3);
Expand Down Expand Up @@ -602,15 +602,15 @@ public void testFindPathWithTurnRestriction_double_loop() {
final EdgeIteratorState e4to7 = graph.edge(7, 4, 3, true);
final EdgeIteratorState e5to7 = graph.edge(7, 5, 2, true);

addRestriction(e6to7, e1to6, 6);
addRestriction(e6to7, e2to6, 6);
addRestriction(e6to7, e3to6, 6);
addRestriction(e1to6, e3to6, 6);
addRestriction(e1to6, e6to7, 6);
addRestriction(e1to6, e0to6, 6);
setRestriction(e6to7, e1to6, 6);
setRestriction(e6to7, e2to6, 6);
setRestriction(e6to7, e3to6, 6);
setRestriction(e1to6, e3to6, 6);
setRestriction(e1to6, e6to7, 6);
setRestriction(e1to6, e0to6, 6);

addRestriction(e4to7, e5to7, 7);
addRestriction(e5to7, e4to7, 7);
setRestriction(e4to7, e5to7, 7);
setRestriction(e5to7, e4to7, 7);
graph.freeze();

// contracting node 0 and 1
Expand Down Expand Up @@ -652,7 +652,7 @@ public void testFindPathWithTurnRestriction_two_different_loops() {

graph.edge(3, 6, 3, false);
graph.edge(6, 2, 4, false);
addRestriction(3, 6, 2);
setRestriction(3, 6, 2);
graph.freeze();

// contracting node 0
Expand Down Expand Up @@ -727,19 +727,19 @@ private void setLevelEqualToNodeIdForAllNodes() {
}
}

private void addTurnCost(EdgeIteratorState edge1, EdgeIteratorState edge2, int viaNode, double costs) {
turnCostStorage.addTurnInfo(edge1.getEdge(), viaNode, edge2.getEdge(), encoder.getTurnFlags(false, costs));
private void setTurnCost(EdgeIteratorState edge1, EdgeIteratorState edge2, int viaNode, double cost) {
turnCostStorage.addTurnInfo(edge1.getEdge(), viaNode, edge2.getEdge(), encoder.getTurnFlags(false, cost));
}

private void addTurnCost(int from, int via, int to, int cost) {
addTurnCost(getEdge(from, via), getEdge(via, to), via, cost);
private void setTurnCost(int from, int via, int to, int cost) {
setTurnCost(getEdge(from, via), getEdge(via, to), via, cost);
}

private void addRestriction(int from, int via, int to) {
addRestriction(getEdge(from, via), getEdge(via, to), via);
private void setRestriction(int from, int via, int to) {
setRestriction(getEdge(from, via), getEdge(via, to), via);
}

private void addRestriction(EdgeIteratorState edge1, EdgeIteratorState edge2, int viaNode) {
private void setRestriction(EdgeIteratorState edge1, EdgeIteratorState edge2, int viaNode) {
turnCostStorage.addTurnInfo(edge1.getEdge(), viaNode, edge2.getEdge(), encoder.getTurnFlags(true, 0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,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
addTurnCost(7, 2, 3, 1);
addTurnCost(7, 2, 6, 3);
addTurnCost(1, 2, 3, 5);
addTurnCost(1, 2, 6, 7);
addTurnCost(1, 2, 7, 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 @@ -319,7 +319,7 @@ public void worksWithTurnCosts() {
graph.edge(5, 2, 1, true);

addRestriction(0, 3, 4);
addTurnCost(4, 5, 2, 6);
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 @@ -520,7 +520,7 @@ private void addRestriction(int fromNode, int node, int toNode) {
);
}

private void addTurnCost(int fromNode, int node, int toNode, double turnCost) {
private void setTurnCost(int fromNode, int node, int toNode, double turnCost) {
turnCostStorage.addTurnInfo(
GHUtility.getEdge(graph, fromNode, node).getEdge(),
node,
Expand Down
Loading

0 comments on commit 967f536

Please sign in to comment.