Skip to content

Commit

Permalink
Replace AtomicReference with a wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
otbutz committed May 6, 2024
1 parent f6c7fbd commit 3994993
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import com.graphhopper.util.EdgeIterator;
import com.graphhopper.util.EdgeIteratorState;

import java.util.concurrent.atomic.AtomicReference;

/**
* Whenever a {@link QueryGraph} is used for shortest path calculations including turn costs we need to wrap the
* {@link Weighting} we want to use with this class. Otherwise turn costs at virtual nodes and/or including virtual
Expand Down Expand Up @@ -77,27 +75,27 @@ public double calcTurnWeight(int inEdge, int viaNode, int outEdge) {
if (isVirtualEdge(inEdge) && isVirtualEdge(outEdge)) {
EdgeIteratorState inEdgeState = graph.getEdgeIteratorState(getOriginalEdge(inEdge), Integer.MIN_VALUE);
EdgeIteratorState outEdgeState = graph.getEdgeIteratorState(getOriginalEdge(outEdge), Integer.MIN_VALUE);
AtomicReference<Double> minTurnWeight = new AtomicReference<>(Double.POSITIVE_INFINITY);
var minTurnWeight = new Object() { double value = Double.POSITIVE_INFINITY; };
graph.forEdgeAndCopiesOfEdge(graph.createEdgeExplorer(), inEdgeState, p -> {
graph.forEdgeAndCopiesOfEdge(graph.createEdgeExplorer(), outEdgeState, q -> {
minTurnWeight.set(Math.min(minTurnWeight.get(), weighting.calcTurnWeight(p.getEdge(), viaNode, q.getEdge())));
minTurnWeight.value = Math.min(minTurnWeight.value, weighting.calcTurnWeight(p.getEdge(), viaNode, q.getEdge()));
});
});
return minTurnWeight.get();
return minTurnWeight.value;
} else if (isVirtualEdge(inEdge)) {
EdgeIteratorState inEdgeState = graph.getEdgeIteratorState(getOriginalEdge(inEdge), Integer.MIN_VALUE);
AtomicReference<Double> minTurnWeight = new AtomicReference<>(Double.POSITIVE_INFINITY);
var minTurnWeight = new Object() { double value = Double.POSITIVE_INFINITY; };
graph.forEdgeAndCopiesOfEdge(graph.createEdgeExplorer(), inEdgeState, p -> {
minTurnWeight.set(Math.min(minTurnWeight.get(), weighting.calcTurnWeight(p.getEdge(), viaNode, outEdge)));
minTurnWeight.value = Math.min(minTurnWeight.value, weighting.calcTurnWeight(p.getEdge(), viaNode, outEdge));
});
return minTurnWeight.get();
return minTurnWeight.value;
} else if (isVirtualEdge(outEdge)) {
EdgeIteratorState outEdgeState = graph.getEdgeIteratorState(getOriginalEdge(outEdge), Integer.MIN_VALUE);
AtomicReference<Double> minTurnWeight = new AtomicReference<>(Double.POSITIVE_INFINITY);
var minTurnWeight = new Object() { double value = Double.POSITIVE_INFINITY; };
graph.forEdgeAndCopiesOfEdge(graph.createEdgeExplorer(), outEdgeState, p -> {
minTurnWeight.set(Math.min(minTurnWeight.get(), weighting.calcTurnWeight(inEdge, viaNode, p.getEdge())));
minTurnWeight.value = Math.min(minTurnWeight.value, weighting.calcTurnWeight(inEdge, viaNode, p.getEdge()));
});
return minTurnWeight.get();
return minTurnWeight.value;
} else {
return weighting.calcTurnWeight(inEdge, viaNode, outEdge);
}
Expand Down

0 comments on commit 3994993

Please sign in to comment.