Repository navigation
Refactor unfavoring of virtual edges (#885) #909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,7 +141,10 @@ public double getEle(int nodeId) { | |
| return getElevation(nodeId); | ||
| } | ||
| }; | ||
| private List<VirtualEdgeIteratorState> modifiedEdges = new ArrayList<VirtualEdgeIteratorState>(5); | ||
|
|
||
| // Use LinkedHashSet for predictable iteration order. | ||
| private final Set<VirtualEdgeIteratorState> unfavoredEdges = new LinkedHashSet<>(5); | ||
|
|
||
| private boolean useEdgeExplorerCache = false; | ||
|
|
||
| public QueryGraph(Graph graph) { | ||
|
|
@@ -407,7 +410,7 @@ private void createEdges(int origTraversalKey, int origRevTraversalKey, | |
|
|
||
| /** | ||
| * Set those edges at the virtual node (nodeId) to 'unfavored' that require at least a turn of | ||
| * 100° from favoredHeading | ||
| * 100° from favoredHeading. | ||
| * <p> | ||
| * | ||
| * @param nodeId VirtualNode at which edges get unfavored | ||
|
|
@@ -451,11 +454,11 @@ public boolean enforceHeading(int nodeId, double favoredHeading, boolean incomin | |
| if (Math.abs(delta) > 1.74) // penalize if a turn of more than 100° | ||
| { | ||
| edge.setUnfavored(true); | ||
| modifiedEdges.add(edge); | ||
| unfavoredEdges.add(edge); | ||
| //also apply to opposite edge for reverse routing | ||
| VirtualEdgeIteratorState reverseEdge = virtualEdges.get(virtNodeIDintern * 4 + getPosOfReverseEdge(edgePos)); | ||
| reverseEdge.setUnfavored(true); | ||
| modifiedEdges.add(reverseEdge); | ||
| unfavoredEdges.add(reverseEdge); | ||
| enforcementOccurred = true; | ||
| } | ||
|
|
||
|
|
@@ -464,35 +467,49 @@ public boolean enforceHeading(int nodeId, double favoredHeading, boolean incomin | |
| } | ||
|
|
||
| /** | ||
| * Set one specific edge at the virtual node with nodeId to 'unfavored' to enforce routing along | ||
| * other edges | ||
| * Sets the virtual edge with virtualEdgeId and its reverse edge to 'unfavored', which | ||
| * effectively penalizes both virtual edges towards an adjacent node of virtualNodeId. | ||
| * This makes it more likely (but does not guarantee) that the router chooses a route towards | ||
| * the other adjacent node of virtualNodeId. | ||
| * <p> | ||
| * | ||
| * @param nodeId VirtualNode at which edges get unfavored | ||
| * @param edgeId edge to become unfavored | ||
| * @param incoming if true, incoming edge is unfavored, else outgoing edge | ||
| * @return boolean indicating if enforcement took place | ||
| * @param virtualNodeId virtual node at which edges get unfavored | ||
| * @param virtualEdgeId this edge and the reverse virtual edge become unfavored | ||
| */ | ||
| public boolean enforceHeadingByEdgeId(int nodeId, int edgeId, boolean incoming) { | ||
| if (!isVirtualNode(nodeId)) | ||
| return false; | ||
| public void unfavorVirtualEdgePair(int virtualNodeId, int virtualEdgeId) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intention was to make the semantics of enforceHeadingByEdgeId more clear by renaming this method to unfavorVirtualEdgePair. |
||
| if (!isVirtualNode(virtualNodeId)) { | ||
| throw new IllegalArgumentException("Node id " + virtualNodeId | ||
| + " must be a virtual node."); | ||
| } | ||
|
|
||
| VirtualEdgeIteratorState incomingEdge = (VirtualEdgeIteratorState) getEdgeIteratorState(edgeId, nodeId); | ||
| VirtualEdgeIteratorState reverseEdge = (VirtualEdgeIteratorState) getEdgeIteratorState(edgeId, incomingEdge.getBaseNode()); | ||
| VirtualEdgeIteratorState incomingEdge = | ||
| (VirtualEdgeIteratorState) getEdgeIteratorState(virtualEdgeId, virtualNodeId); | ||
| VirtualEdgeIteratorState reverseEdge = (VirtualEdgeIteratorState) getEdgeIteratorState( | ||
| virtualEdgeId, incomingEdge.getBaseNode()); | ||
| incomingEdge.setUnfavored(true); | ||
| modifiedEdges.add(incomingEdge); | ||
| unfavoredEdges.add(incomingEdge); | ||
| reverseEdge.setUnfavored(true); | ||
| modifiedEdges.add(reverseEdge); | ||
| return true; | ||
| unfavoredEdges.add(reverseEdge); | ||
| } | ||
|
|
||
| /** | ||
| * Returns all virtual edges that have been unfavored via | ||
| * {@link #enforceHeading(int, double, boolean)} or {@link #unfavorVirtualEdgePair(int, int)}. | ||
| */ | ||
| public Set<EdgeIteratorState> getUnfavoredVirtualEdges() { | ||
| // Need to create a new set to convert Set<VirtualEdgeIteratorState> to | ||
| // Set<EdgeIteratorState>. | ||
| return new LinkedHashSet<EdgeIteratorState>(unfavoredEdges); | ||
| } | ||
|
|
||
| /** | ||
| * Removes the 'unfavored' status of all virtual edges. | ||
| */ | ||
| public void clearUnfavoredStatus() { | ||
| for (VirtualEdgeIteratorState edge : modifiedEdges) { | ||
| for (VirtualEdgeIteratorState edge : unfavoredEdges) { | ||
| edge.setUnfavored(false); | ||
| } | ||
| unfavoredEdges.clear(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed bug.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a test case showing this bug?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bug was that multiple invocations of However, this bug was not observable before because modifiedEdges could not be accessed from outside this class. |
||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now using Set instead of List to store unfavoredEdges.