Skip to content

Commit

Permalink
Minor method reordering.
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 04ab605 commit c619922
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,59 @@ public ArrayWitnessPathFinder(GraphHopperStorage graph, CHGraph chGraph, TurnWei
initCollections();
}

@Override
protected void setInitialEntries(int centerNode, int fromNode, int sourceEdge) {
EdgeIterator outIter = outEdgeExplorer.setBaseNode(fromNode);
while (outIter.next()) {
if (isContracted(outIter.getAdjNode())) {
continue;
}
double turnWeight = calcTurnWeight(sourceEdge, fromNode, outIter.getFirstOrigEdge());
if (isInfinite(turnWeight)) {
continue;
}
double edgeWeight = turnWeighting.calcWeight(outIter, false, EdgeIterator.NO_EDGE);
double weight = turnWeight + edgeWeight;
boolean onOrigPath = outIter.getAdjNode() == centerNode;
int incEdge = outIter.getLastOrigEdge();
int adjNode = outIter.getAdjNode();
int key = getEdgeKey(incEdge, adjNode);
int parentKey = -key - 1;
WitnessSearchEntry parent = new WitnessSearchEntry(
EdgeIterator.NO_EDGE,
outIter.getFirstOrigEdge(),
fromNode, turnWeight, false);
if (edges[key] == -1) {
edges[key] = outIter.getEdge();
incEdges[key] = incEdge;
adjNodes[key] = adjNode;
weights[key] = weight;
parents[key] = parentKey;
onOrigPaths[key] = onOrigPath;
rootParents.put(parentKey, parent);
changedEdges.add(key);
} else if (weight < weights[key]) {
// there may be entries with the same adjNode and last original edge, but we only need the one with
// the lowest weight
edges[key] = outIter.getEdge();
weights[key] = weight;
parents[key] = parentKey;
onOrigPaths[key] = onOrigPath;
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++;
}
heap.insert_(weights[key], key);
}
}

@Override
public WitnessSearchEntry runSearch(int toNode, int targetEdge) {
// todo: write a test for this case to make it clear
bestWeight = fromNode == toNode
Expand Down Expand Up @@ -195,58 +248,6 @@ private void updateBestPath(int toNode, int targetEdge, int edgeKey) {
}
}

@Override
protected void setInitialEntries(int centerNode, int fromNode, int sourceEdge) {
EdgeIterator outIter = outEdgeExplorer.setBaseNode(fromNode);
while (outIter.next()) {
if (isContracted(outIter.getAdjNode())) {
continue;
}
double turnWeight = calcTurnWeight(sourceEdge, fromNode, outIter.getFirstOrigEdge());
if (isInfinite(turnWeight)) {
continue;
}
double edgeWeight = turnWeighting.calcWeight(outIter, false, EdgeIterator.NO_EDGE);
double weight = turnWeight + edgeWeight;
boolean onOrigPath = outIter.getAdjNode() == centerNode;
int incEdge = outIter.getLastOrigEdge();
int adjNode = outIter.getAdjNode();
int key = getEdgeKey(incEdge, adjNode);
int parentKey = -key - 1;
WitnessSearchEntry parent = new WitnessSearchEntry(
EdgeIterator.NO_EDGE,
outIter.getFirstOrigEdge(),
fromNode, turnWeight, false);
if (edges[key] == -1) {
edges[key] = outIter.getEdge();
incEdges[key] = incEdge;
adjNodes[key] = adjNode;
weights[key] = weight;
parents[key] = parentKey;
onOrigPaths[key] = onOrigPath;
rootParents.put(parentKey, parent);
changedEdges.add(key);
} else if (weight < weights[key]) {
// there may be entries with the same adjNode and last original edge, but we only need the one with
// the lowest weight
edges[key] = outIter.getEdge();
weights[key] = weight;
parents[key] = parentKey;
onOrigPaths[key] = onOrigPath;
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++;
}
heap.insert_(weights[key], key);
}
}

@Override
void doReset() {
for (int i = 0; i < changedEdges.size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,39 @@ public MapWitnessPathFinder(GraphHopperStorage graph, CHGraph chGraph, TurnWeigh
doReset();
}

@Override
protected void setInitialEntries(int centerNode, int fromNode, int sourceEdge) {
EdgeIterator outIter = outEdgeExplorer.setBaseNode(fromNode);
while (outIter.next()) {
if (isContracted(outIter.getAdjNode())) {
continue;
}
double turnWeight = calcTurnWeight(sourceEdge, fromNode, outIter.getFirstOrigEdge());
if (isInfinite(turnWeight)) {
continue;
}
double weight = turnWeighting.calcWeight(outIter, false, EdgeIterator.NO_EDGE);
boolean onOrigPath = outIter.getAdjNode() == centerNode;
WitnessSearchEntry entry = new WitnessSearchEntry(
outIter.getEdge(),
outIter.getLastOrigEdge(),
outIter.getAdjNode(), turnWeight + weight, onOrigPath);
entry.parent = new WitnessSearchEntry(
EdgeIterator.NO_EDGE,
outIter.getFirstOrigEdge(),
fromNode, turnWeight, false);
addOrUpdateInitialEntry(entry);
}

// now that we know which entries are actually needed we add them to the priority queue
for (IntObjectCursor<WitnessSearchEntry> e : entries) {
if (e.value.onOrigPath) {
numOnOrigPath++;
}
priorityQueue.add(e.value);
}
}

@Override
public WitnessSearchEntry runSearch(int toNode, int targetEdge) {
// todo: write a test for this case where it becomes clear
Expand Down Expand Up @@ -155,39 +188,6 @@ private void updateBestPath(int toNode, int targetEdge, WitnessSearchEntry entry
}
}

@Override
protected void setInitialEntries(int centerNode, int fromNode, int sourceEdge) {
EdgeIterator outIter = outEdgeExplorer.setBaseNode(fromNode);
while (outIter.next()) {
if (isContracted(outIter.getAdjNode())) {
continue;
}
double turnWeight = calcTurnWeight(sourceEdge, fromNode, outIter.getFirstOrigEdge());
if (isInfinite(turnWeight)) {
continue;
}
double weight = turnWeighting.calcWeight(outIter, false, EdgeIterator.NO_EDGE);
boolean onOrigPath = outIter.getAdjNode() == centerNode;
WitnessSearchEntry entry = new WitnessSearchEntry(
outIter.getEdge(),
outIter.getLastOrigEdge(),
outIter.getAdjNode(), turnWeight + weight, onOrigPath);
entry.parent = new WitnessSearchEntry(
EdgeIterator.NO_EDGE,
outIter.getFirstOrigEdge(),
fromNode, turnWeight, false);
addOrUpdateInitialEntry(entry);
}

// now that we know which entries are actually needed we add them to the priority queue
for (IntObjectCursor<WitnessSearchEntry> e : entries) {
if (e.value.onOrigPath) {
numOnOrigPath++;
}
priorityQueue.add(e.value);
}
}

@Override
void doReset() {
// todo: tune initial collection sizes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public int init(int centerNode, int fromNode, int sourceEdge) {
return numEntries;
}

abstract void setInitialEntries(int centerNode, int fromNode, int sourceEdge);

public abstract WitnessSearchEntry runSearch(int toNode, int targetEdge);

public int getNumPolledEdges() {
Expand All @@ -101,8 +103,6 @@ public void resetStats() {
stats.reset();
}

abstract void setInitialEntries(int centerNode, int fromNode, int sourceEdge);

abstract void doReset();

abstract int getNumEntries();
Expand Down

0 comments on commit c619922

Please sign in to comment.