Skip to content

Commit

Permalink
Renames WitnessSearchEntry#onOrigPath.
Browse files Browse the repository at this point in the history
Signed-off-by: ammagamma <contactammagamma@gmail.com>
  • Loading branch information
easbar committed May 13, 2018
1 parent c619922 commit f68885f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 76 deletions.
Expand Up @@ -38,7 +38,7 @@ public ArrayBasedLegacyWitnessPathFinder(CHGraph graph, Weighting weighting, Tra
protected void initEntries(IntObjectMap<WitnessSearchEntry> initialEntries) {
int parentId = -1;
for (IntObjectCursor<WitnessSearchEntry> e : initialEntries) {
if (e.value.onOrigPath) {
if (e.value.isDirectCenterNodePath) {
numOnOrigPath++;
avoidNode = e.value.adjNode;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ private void setInitEntry(int key, WitnessSearchEntry entry, int parentId) {
weights[key] = entry.weight;
parents[key] = parentId;
rootParents.add(entry.getParent());
onOrigPaths[key] = entry.onOrigPath;
onOrigPaths[key] = entry.isDirectCenterNodePath;
}

private void setEntry(int key, EdgeIteratorState iter, double weight, int parent, boolean onOrigPath) {
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class ArrayWitnessPathFinder extends WitnessPathFinder {
private int[] incEdges;
private int[] parents;
private int[] adjNodes;
private boolean[] onOrigPaths;
private boolean[] isDirectCenterNodePaths;

private IntObjectMap<WitnessSearchEntry> rootParents;
private IntDoubleBinaryHeap heap;
Expand All @@ -47,7 +47,7 @@ protected void setInitialEntries(int centerNode, int fromNode, int sourceEdge) {
}
double edgeWeight = turnWeighting.calcWeight(outIter, false, EdgeIterator.NO_EDGE);
double weight = turnWeight + edgeWeight;
boolean onOrigPath = outIter.getAdjNode() == centerNode;
boolean isDirectCenterNodePath = outIter.getAdjNode() == centerNode;
int incEdge = outIter.getLastOrigEdge();
int adjNode = outIter.getAdjNode();
int key = getEdgeKey(incEdge, adjNode);
Expand All @@ -62,7 +62,7 @@ protected void setInitialEntries(int centerNode, int fromNode, int sourceEdge) {
adjNodes[key] = adjNode;
weights[key] = weight;
parents[key] = parentKey;
onOrigPaths[key] = onOrigPath;
isDirectCenterNodePaths[key] = isDirectCenterNodePath;
rootParents.put(parentKey, parent);
changedEdges.add(key);
} else if (weight < weights[key]) {
Expand All @@ -71,16 +71,16 @@ protected void setInitialEntries(int centerNode, int fromNode, int sourceEdge) {
edges[key] = outIter.getEdge();
weights[key] = weight;
parents[key] = parentKey;
onOrigPaths[key] = onOrigPath;
isDirectCenterNodePaths[key] = isDirectCenterNodePath;
rootParents.put(parentKey, parent);
}
}

// now that we know which entries are actually needed we add them to the heap
for (int i = 0; i < changedEdges.size(); ++i) {
int key = changedEdges.get(i);
if (onOrigPaths[key]) {
numOnOrigPath++;
if (isDirectCenterNodePaths[key]) {
numDirectCenterNodePaths++;
}
heap.insert_(weights[key], key);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public WitnessSearchEntry runSearch(int toNode, int targetEdge) {

// run dijkstra to find the optimal path
while (!heap.isEmpty()) {
if (numOnOrigPath < 1 && (!resViaCenter || isInfinite(bestWeight))) {
if (numDirectCenterNodePaths < 1 && (!resViaCenter || isInfinite(bestWeight))) {
// we have not found a connection to the target edge yet and there are no entries
// in the priority queue anymore that are part of the direct path via the center node
// -> we will not need a shortcut
Expand All @@ -125,13 +125,13 @@ public WitnessSearchEntry runSearch(int toNode, int targetEdge) {
numPolledEdges++;
pollCount++;

if (onOrigPaths[currKey]) {
numOnOrigPath--;
if (isDirectCenterNodePaths[currKey]) {
numDirectCenterNodePaths--;
}

// after a certain amount of edges has been settled we no longer expand entries
// that are not on a path via the center node
if (numSettledEdges > maxSettledEdges && !onOrigPaths[currKey]) {
if (numSettledEdges > maxSettledEdges && !isDirectCenterNodePaths[currKey]) {
continue;
}

Expand All @@ -148,17 +148,17 @@ public WitnessSearchEntry runSearch(int toNode, int targetEdge) {
if (isInfinite(weight)) {
continue;
}
boolean onOrigPath = onOrigPaths[currKey] && iter.getAdjNode() == centerNode;
boolean isDirectCenterNodePath = isDirectCenterNodePaths[currKey] && iter.getAdjNode() == centerNode;

// dijkstra expansion: add or update current entries
int key = getEdgeKey(iter.getLastOrigEdge(), iter.getAdjNode());
if (edges[key] == -1) {
setEntry(key, iter, weight, currKey, onOrigPath);
setEntry(key, iter, weight, currKey, isDirectCenterNodePath);
changedEdges.add(key);
heap.insert_(weight, key);
updateBestPath(toNode, targetEdge, key);
} else if (weight < weights[key]) {
updateEntry(key, iter, weight, currKey, onOrigPath);
updateEntry(key, iter, weight, currKey, isDirectCenterNodePath);
heap.update_(weight, key);
updateBestPath(toNode, targetEdge, key);
}
Expand Down Expand Up @@ -190,35 +190,35 @@ public WitnessSearchEntry runSearch(int toNode, int targetEdge) {
}

private WitnessSearchEntry getEntryForKey(int edgeKey) {
return new WitnessSearchEntry(edges[edgeKey], incEdges[edgeKey], adjNodes[edgeKey], weights[edgeKey], onOrigPaths[edgeKey]);
return new WitnessSearchEntry(edges[edgeKey], incEdges[edgeKey], adjNodes[edgeKey], weights[edgeKey], isDirectCenterNodePaths[edgeKey]);
}

private void setEntry(int key, EdgeIteratorState iter, double weight, int parent, boolean onOrigPath) {
private void setEntry(int key, EdgeIteratorState iter, double weight, int parent, boolean isDirectCenterNodePath) {
edges[key] = iter.getEdge();
incEdges[key] = iter.getLastOrigEdge();
adjNodes[key] = iter.getAdjNode();
weights[key] = weight;
parents[key] = parent;
if (onOrigPath) {
onOrigPaths[key] = true;
numOnOrigPath++;
if (isDirectCenterNodePath) {
isDirectCenterNodePaths[key] = true;
numDirectCenterNodePaths++;
}
}

private void updateEntry(int key, EdgeIteratorState iter, double weight, int currKey, boolean onOrigPath) {
private void updateEntry(int key, EdgeIteratorState iter, double weight, int currKey, boolean isDirectCenterNodePath) {
edges[key] = iter.getEdge();
weights[key] = weight;
parents[key] = currKey;
if (onOrigPath) {
if (!onOrigPaths[key]) {
numOnOrigPath++;
if (isDirectCenterNodePath) {
if (!isDirectCenterNodePaths[key]) {
numDirectCenterNodePaths++;
}
} else {
if (onOrigPaths[key]) {
numOnOrigPath--;
if (isDirectCenterNodePaths[key]) {
numDirectCenterNodePaths--;
}
}
onOrigPaths[key] = onOrigPath;
isDirectCenterNodePaths[key] = isDirectCenterNodePath;
}


Expand All @@ -228,7 +228,7 @@ private void resetEntry(int key) {
incEdges[key] = EdgeIterator.NO_EDGE;
parents[key] = -1;
adjNodes[key] = -1;
onOrigPaths[key] = false;
isDirectCenterNodePaths[key] = false;
}

private void updateBestPath(int toNode, int targetEdge, int edgeKey) {
Expand All @@ -237,7 +237,7 @@ private void updateBestPath(int toNode, int targetEdge, int edgeKey) {
double totalWeight = weights[edgeKey] + calcTurnWeight(incEdges[edgeKey], toNode, targetEdge);
// we know that there must be some parent so a negative parent key is a real
// key in the root parents collection --> in this case we did not go via the center
boolean viaCenter = parents[edgeKey] >= 0 && onOrigPaths[parents[edgeKey]];
boolean viaCenter = parents[edgeKey] >= 0 && isDirectCenterNodePaths[parents[edgeKey]];
// when in doubt prefer a witness path over an original path
double tolerance = viaCenter ? 0 : 1.e-6;
if (totalWeight - tolerance < bestWeight) {
Expand Down Expand Up @@ -286,8 +286,8 @@ private void initStorage(int numEntries) {
adjNodes = new int[numEntries];
Arrays.fill(adjNodes, -1);

onOrigPaths = new boolean[numEntries];
Arrays.fill(onOrigPaths, false);
isDirectCenterNodePaths = new boolean[numEntries];
Arrays.fill(isDirectCenterNodePaths, false);
}

}
Expand Up @@ -368,7 +368,7 @@ private void runExhaustiveWitnessSearch(int node, LongSet witnessedPairs) {

EdgeIterator origInIter = fromNodeOrigInEdgeExplorer.setBaseNode(fromNode);
while (origInIter.next()) {
IntObjectMap<WitnessSearchEntry> initialEntries = getInitialEntriesAggressive(fromNode, node, incomingEdges, origInIter);
IntObjectMap<WitnessSearchEntry> initialEntries = getInitialEntriesLegacyAggressive(fromNode, node, incomingEdges, origInIter);
if (initialEntries.isEmpty()) {
continue;
}
Expand Down Expand Up @@ -452,7 +452,7 @@ private void runExhaustiveWitnessSearch(int node, LongSet witnessedPairs) {
}
}

private IntObjectMap<WitnessSearchEntry> getInitialEntriesAggressive(int fromNode, int node, EdgeIteratorState origPath, EdgeIteratorState origSourceEdge) {
private IntObjectMap<WitnessSearchEntry> getInitialEntriesLegacyAggressive(int fromNode, int node, EdgeIteratorState origPath, EdgeIteratorState origSourceEdge) {
IntObjectMap<WitnessSearchEntry> initialEntries = new IntObjectHashMap<>();
int numOnOrigPath = 0;
final double origPathWeight = turnWeighting.calcWeight(origPath, false, EdgeIterator.NO_EDGE);
Expand Down Expand Up @@ -700,7 +700,7 @@ private static boolean bestPathIsValidAndRequiresNode(
LOGGER.trace("Found a witness path using alternative target edge -> no shortcut");
return false;
}
return bestPath.getParent().onOrigPath;
return bestPath.getParent().isDirectCenterNodePath;
}

/**
Expand All @@ -712,7 +712,7 @@ private int insertOrUpdateInitialEntry(IntObjectMap<WitnessSearchEntry> initialE
if (index < 0) {
LOGGER.trace("Adding/Updating initial entry {}", entry);
initialEntries.indexInsert(index, edgeKey, entry);
if (entry.onOrigPath) {
if (entry.isDirectCenterNodePath) {
return 1;
}
} else {
Expand All @@ -721,10 +721,10 @@ private int insertOrUpdateInitialEntry(IntObjectMap<WitnessSearchEntry> initialE
// the lowest weight
if (entry.weight < currEntry.weight) {
int difference = 0;
if (currEntry.onOrigPath) {
if (currEntry.isDirectCenterNodePath) {
difference--;
}
if (entry.onOrigPath) {
if (entry.isDirectCenterNodePath) {
difference++;
}
initialEntries.indexReplace(index, entry);
Expand Down
Expand Up @@ -67,7 +67,7 @@ public void setInitialEntries(IntObjectMap<WitnessSearchEntry> initialEntries) {
initEntries(initialEntries);
stats.onInitEntries(initialEntries.size());
if (numOnOrigPath != 1) {
throw new IllegalStateException("There should be exactly one initial entry with onOrigPath = true, but given: " + numOnOrigPath);
throw new IllegalStateException("There should be exactly one initial entry with isDirectCenterNodePath = true, but given: " + numOnOrigPath);
}
}

Expand Down
Expand Up @@ -43,7 +43,7 @@ public MapBasedLegacyWitnessPathFinder(CHGraph graph, Weighting weighting, Trave
@Override
protected void initEntries(IntObjectMap<WitnessSearchEntry> initialEntries) {
for (IntObjectCursor<WitnessSearchEntry> e : initialEntries) {
if (e.value.onOrigPath) {
if (e.value.isDirectCenterNodePath) {
numOnOrigPath++;
avoidNode = e.value.adjNode;
}
Expand Down Expand Up @@ -81,18 +81,18 @@ public void findTarget(int targetEdge, int targetNode) {
numEntriesPolled++;
pollCount++;

if (currEdge.onOrigPath) {
if (currEdge.isDirectCenterNodePath) {
numOnOrigPath--;
}

if (numSettledEdges > maxSettledEdges && !currEdge.onOrigPath) {
if (numSettledEdges > maxSettledEdges && !currEdge.isDirectCenterNodePath) {
continue;
}

EdgeIterator iter = outEdgeExplorer.setBaseNode(currEdge.adjNode);
while (iter.next()) {
// todo: increases number of shortcuts and not sure if needed
// if (!currEdge.onOrigPath && iter.getAdjNode() == avoidNode) {
// if (!currEdge.isDirectCenterNodePath && iter.getAdjNode() == avoidNode) {
// continue;
// }
if ((!traversalMode.hasUTurnSupport() && iter.getFirstOrigEdge() == currEdge.incEdge) ||
Expand All @@ -104,7 +104,7 @@ public void findTarget(int targetEdge, int targetNode) {
continue;
}

boolean onOrigPath = currEdge.onOrigPath && iter.getBaseNode() == iter.getAdjNode();
boolean onOrigPath = currEdge.isDirectCenterNodePath && iter.getBaseNode() == iter.getAdjNode();
int key = getEdgeKey(iter.getLastOrigEdge(), iter.getAdjNode());
WitnessSearchEntry entry = chEntries.get(key);
if (entry == null) {
Expand Down Expand Up @@ -151,19 +151,19 @@ private void updateEntry(WitnessSearchEntry entry, EdgeIteratorState iter, doubl
entry.weight = weight;
entry.parent = parent;
if (onOrigPath) {
if (!entry.onOrigPath) {
if (!entry.isDirectCenterNodePath) {
numOnOrigPath++;
}
} else {
if (entry.onOrigPath) {
if (entry.isDirectCenterNodePath) {
numOnOrigPath--;
}
}
entry.onOrigPath = onOrigPath;
entry.isDirectCenterNodePath = onOrigPath;
}

private boolean targetDiscoveredByOrigPath(int targetEdge, int targetNode, WitnessSearchEntry currEdge, EdgeIteratorState iter) {
return currEdge.onOrigPath && iter.getLastOrigEdge() == targetEdge && iter.getAdjNode() == targetNode;
return currEdge.isDirectCenterNodePath && iter.getLastOrigEdge() == targetEdge && iter.getAdjNode() == targetNode;
}

private void initCollections() {
Expand Down

0 comments on commit f68885f

Please sign in to comment.