Skip to content

Commit e7b6789

Browse files
Peterb3nn0
Peter
authored andcommitted
minor refactoring; removed traversal mode support from dijkstraoneToMany as we need a more severe change
1 parent deda28e commit e7b6789

File tree

9 files changed

+32
-31
lines changed

9 files changed

+32
-31
lines changed

core/src/main/java/com/graphhopper/routing/AStar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private Path runAlgo()
111111
continue;
112112

113113
int neighborNode = iter.getAdjNode();
114-
int iterationKey = traversalMode.createIdentifier(iter, false);
114+
int iterationKey = traversalMode.createTraversalId(iter, false);
115115
double alreadyVisitedWeight = weighting.calcWeight(iter, false, currEdge.edge) + currEdge.weightToCompare;
116116
if (Double.isInfinite(alreadyVisitedWeight))
117117
continue;

core/src/main/java/com/graphhopper/routing/AStarBidirection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private void fillEdges( AStarEdge currEdge, GHPoint goal,
243243
continue;
244244

245245
int neighborNode = iter.getAdjNode();
246-
int iterationKey = traversalMode.createIdentifier(iter, reverse);
246+
int iterationKey = traversalMode.createTraversalId(iter, reverse);
247247
// TODO performance: check if the node is already existent in the opposite direction
248248
// then we could avoid the approximation as we already know the exact complete path!
249249
double alreadyVisitedWeight = weighting.calcWeight(iter, reverse, currEdge.edge) + currEdge.weightToCompare;

core/src/main/java/com/graphhopper/routing/Dijkstra.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private Path runAlgo()
8585
if (!accept(iter, currEdge.edge))
8686
continue;
8787

88-
int iterationKey = traversalMode.createIdentifier(iter, false);
88+
int iterationKey = traversalMode.createTraversalId(iter, false);
8989
double tmpWeight = weighting.calcWeight(iter, false, currEdge.edge) + currEdge.weight;
9090
if (Double.isInfinite(tmpWeight))
9191
continue;

core/src/main/java/com/graphhopper/routing/DijkstraBidirectionRef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void fillEdges( EdgeEntry currEdge, PriorityQueue<EdgeEntry> prioQueue,
181181
if (!accept(iter, currEdge.edge))
182182
continue;
183183

184-
int iterationKey = traversalMode.createIdentifier(iter, reverse);
184+
int iterationKey = traversalMode.createTraversalId(iter, reverse);
185185
double tmpWeight = weighting.calcWeight(iter, reverse, currEdge.edge) + currEdge.weight;
186186
if (Double.isInfinite(tmpWeight))
187187
continue;

core/src/main/java/com/graphhopper/routing/DijkstraOneToMany.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ public DijkstraOneToMany( Graph graph, FlagEncoder encoder, Weighting weighting,
6060
edgeIds = new int[graph.getNodes()];
6161
Arrays.fill(edgeIds, EdgeIterator.NO_EDGE);
6262

63-
if (tMode.isEdgeBased())
64-
weights = new double[graph.getAllEdges().getMaxId() * 2];
65-
else
66-
weights = new double[graph.getNodes()];
63+
weights = new double[graph.getNodes()];
6764

6865
Arrays.fill(weights, Double.MAX_VALUE);
6966

@@ -173,29 +170,28 @@ public int findEndNode( int from, int to )
173170
EdgeIterator iter = outEdgeExplorer.setBaseNode(currNode);
174171
while (iter.next())
175172
{
176-
int adjNode = iter.getAdjNode();
177-
int iterationKey = traversalMode.createIdentifier(iter, false);
173+
int adjNode = iter.getAdjNode();
178174
int prevEdgeId = edgeIds[adjNode];
179175
if (!accept(iter, prevEdgeId))
180176
continue;
181177

182-
double tmpWeight = weighting.calcWeight(iter, false, prevEdgeId) + weights[/*TODO key?*/ currNode];
178+
double tmpWeight = weighting.calcWeight(iter, false, prevEdgeId) + weights[currNode];
183179
if (Double.isInfinite(tmpWeight))
184180
continue;
185181

186-
double w = weights[iterationKey];
182+
double w = weights[adjNode];
187183
if (w == Double.MAX_VALUE)
188184
{
189185
parents[adjNode] = currNode;
190-
weights[iterationKey] = tmpWeight;
186+
weights[adjNode] = tmpWeight;
191187
heap.insert_(tmpWeight, adjNode);
192188
changedNodes.add(adjNode);
193189
edgeIds[adjNode] = iter.getEdge();
194190

195191
} else if (w > tmpWeight)
196192
{
197193
parents[adjNode] = currNode;
198-
weights[iterationKey] = tmpWeight;
194+
weights[adjNode] = tmpWeight;
199195
heap.update_(tmpWeight, adjNode);
200196
changedNodes.add(adjNode);
201197
edgeIds[adjNode] = iter.getEdge();

core/src/main/java/com/graphhopper/routing/PathNative.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
*/
2929
public class PathNative extends Path
3030
{
31-
int[] parents;
32-
int[] pathEdgeIds;
31+
private final int[] parentNodes;
32+
private final int[] parentEdges;
3333

34-
public PathNative( Graph g, FlagEncoder encoder, int[] parents, int[] pathEdgeIds )
34+
public PathNative( Graph g, FlagEncoder encoder, int[] parentNodes, int[] parentEdges )
3535
{
3636
super(g, encoder);
37-
this.parents = parents;
38-
this.pathEdgeIds = pathEdgeIds;
37+
this.parentNodes = parentNodes;
38+
this.parentEdges = parentEdges;
3939
}
4040

4141
/**
@@ -49,12 +49,12 @@ public Path extract()
4949

5050
while (true)
5151
{
52-
int edgeId = pathEdgeIds[endNode];
52+
int edgeId = parentEdges[endNode];
5353
if (!EdgeIterator.Edge.isValid(edgeId))
5454
break;
5555

5656
processEdge(edgeId, endNode);
57-
endNode = parents[endNode];
57+
endNode = parentNodes[endNode];
5858
}
5959
reverseOrder();
6060
return setFound(true);

core/src/main/java/com/graphhopper/routing/util/TraversalMode.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ public enum TraversalMode
5353
EDGE_BASED_2DIR_UTURN(true, 2, true);
5454

5555
private final boolean edgeBased;
56-
private final int noOfStatus;
56+
private final int noOfStates;
5757
private final boolean uTurnSupport;
5858

59-
TraversalMode( boolean edgeBased, int noOfStatus, boolean uTurnSupport )
59+
TraversalMode( boolean edgeBased, int noOfStates, boolean uTurnSupport )
6060
{
6161
this.edgeBased = edgeBased;
62-
this.noOfStatus = noOfStatus;
62+
this.noOfStates = noOfStates;
6363
this.uTurnSupport = uTurnSupport;
6464

65-
if (noOfStatus != 1 && noOfStatus != 2)
66-
throw new IllegalArgumentException("Currently only statuses of 1 or 2 are allowed");
65+
if (noOfStates != 1 && noOfStates != 2)
66+
throw new IllegalArgumentException("Currently only 1 or 2 states allowed");
6767
}
6868

6969
/**
@@ -76,11 +76,11 @@ public enum TraversalMode
7676
* backward searches in bidirectional algorithms.
7777
* @return the identifier to access the shortest path tree
7878
*/
79-
public final int createIdentifier( EdgeIteratorState iterState, boolean reverse )
79+
public final int createTraversalId( EdgeIteratorState iterState, boolean reverse )
8080
{
8181
if (edgeBased)
8282
{
83-
if (noOfStatus == 1)
83+
if (noOfStates == 1)
8484
return iterState.getEdge();
8585

8686
return GHUtility.createEdgeKey(iterState.getAdjNode(), iterState.getBaseNode(), iterState.getEdge(), reverse);
@@ -89,6 +89,11 @@ public final int createIdentifier( EdgeIteratorState iterState, boolean reverse
8989
return iterState.getAdjNode();
9090
}
9191

92+
public int getNoOfStates()
93+
{
94+
return noOfStates;
95+
}
96+
9297
public boolean isEdgeBased()
9398
{
9499
return edgeBased;

core/src/test/java/com/graphhopper/routing/AbstractRoutingAlgorithmTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testCalcShortestPath()
6464
Graph graph = createTestGraph();
6565
Path p = prepareGraph(graph).createAlgo().calcPath(0, 7);
6666
assertEquals(p.toString(), 13, p.getDistance(), 1e-4);
67-
assertEquals(p.toString(), 5, p.calcNodes().size());
67+
assertEquals(p.toString(), Helper.createTList(0, 4, 6, 5, 7), p.calcNodes());
6868
}
6969

7070
// see calc-fastest-graph.svg

core/src/test/java/com/graphhopper/routing/DijkstraOneToManyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public DijkstraOneToManyTest( TraversalMode tMode )
5757
{
5858
this.traversalmode = tMode;
5959
}
60-
60+
6161
@Override
6262
public AlgorithmPreparation prepareGraph( Graph defaultGraph, final FlagEncoder encoder, final Weighting w )
6363
{
@@ -66,7 +66,7 @@ public AlgorithmPreparation prepareGraph( Graph defaultGraph, final FlagEncoder
6666
@Override
6767
public RoutingAlgorithm createAlgo()
6868
{
69-
return new DijkstraOneToMany(_graph, encoder, w, traversalmode);
69+
return new DijkstraOneToMany(_graph, encoder, w, traversalmode);
7070
}
7171
}.setGraph(defaultGraph);
7272
}

0 commit comments

Comments
 (0)