Skip to content

Commit

Permalink
missing renames for Path.setEdgeEntry -> setSPTEntry and AbstractAlgo…
Browse files Browse the repository at this point in the history
…rithm.createEdgeEntry -> createSPTEntry
  • Loading branch information
Peter committed Feb 12, 2016
1 parent cabcb67 commit c0105cd
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 85 deletions.
3 changes: 3 additions & 0 deletions core/files/changelog.txt
@@ -1,3 +1,6 @@
0.7
missing renames for Path.setEdgeEntry -> setSPTEntry and AbstractAlgorithm.createEdgeEntry -> createSPTEntry

0.6
removed methods deprecated in 0.4 and 0.5
renamed EdgeEntry to SPTEntry and AStar.AStarEdge to AStar.AStarEntry
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/graphhopper/routing/AStar.java
Expand Up @@ -158,11 +158,11 @@ private Path runAlgo()
@Override
protected Path extractPath()
{
return new Path(graph, flagEncoder).setWeight(currEdge.weight).setEdgeEntry(currEdge).extract();
return new Path(graph, flagEncoder).setWeight(currEdge.weight).setSPTEntry(currEdge).extract();
}

@Override
protected SPTEntry createEdgeEntry( int node, double weight )
protected SPTEntry createSPTEntry( int node, double weight )
{
throw new IllegalStateException("use AStarEdge constructor directly");
}
Expand Down
Expand Up @@ -94,7 +94,7 @@ public AStarBidirection setApproximation( WeightApproximator approx )
}

@Override
protected SPTEntry createEdgeEntry( int node, double weight )
protected SPTEntry createSPTEntry( int node, double weight )
{
throw new IllegalStateException("use AStarEdge constructor directly");
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public void initFrom( int from, double weight )
if (currTo != null && currTo.adjNode == from)
{
// special case of identical start and end
bestPath.edgeEntry = currFrom;
bestPath.sptEntry = currFrom;
bestPath.edgeTo = currTo;
finishedFrom = true;
finishedTo = true;
Expand Down Expand Up @@ -159,7 +159,7 @@ public void initTo( int to, double weight )
if (currFrom != null && currFrom.adjNode == to)
{
// special case of identical start and end
bestPath.edgeEntry = currFrom;
bestPath.sptEntry = currFrom;
bestPath.edgeTo = currTo;
finishedFrom = true;
finishedTo = true;
Expand Down Expand Up @@ -314,7 +314,7 @@ public void updateBestPath( EdgeIteratorState edgeState, AStarEntry entryCurrent
if (newWeight < bestPath.getWeight())
{
bestPath.setSwitchToFrom(reverse);
bestPath.edgeEntry = entryCurrent;
bestPath.sptEntry = entryCurrent;
bestPath.edgeTo = entryOther;
bestPath.setWeight(newWeight);
}
Expand Down
Expand Up @@ -80,7 +80,7 @@ protected boolean accept( EdgeIterator iter, int prevOrNextEdgeId )
return additionalEdgeFilter == null || additionalEdgeFilter.accept(iter);
}

protected void updateBestPath( EdgeIteratorState edgeState, SPTEntry bestEdgeEntry, int traversalId )
protected void updateBestPath( EdgeIteratorState edgeState, SPTEntry bestSPTEntry, int traversalId )
{
}

Expand All @@ -92,7 +92,7 @@ protected void checkAlreadyRun()
alreadyRun = true;
}

protected SPTEntry createEdgeEntry( int node, double weight )
protected SPTEntry createSPTEntry( int node, double weight )
{
return new SPTEntry(EdgeIterator.NO_EDGE, node, weight);
}
Expand Down
86 changes: 43 additions & 43 deletions core/src/main/java/com/graphhopper/routing/AlternativeRoute.java
Expand Up @@ -355,49 +355,49 @@ public List<AlternativeInfo> calcAlternatives( final int maxPaths,
plateauInfluence, bestPlateau);

final AlternativeInfo bestAlt = new AlternativeInfo(sortBy, bestPath,
bestPath.edgeEntry, bestPath.edgeTo, bestShare, getAltNames(graph, bestPath.edgeEntry));
bestPath.sptEntry, bestPath.edgeTo, bestShare, getAltNames(graph, bestPath.sptEntry));
alternatives.add(bestAlt);
final List<SPTEntry> bestPathEntries = new ArrayList<SPTEntry>(2);

bestWeightMapFrom.forEachEntry(new TIntObjectProcedure<SPTEntry>()
{
@Override
public boolean execute( final int traversalId, final SPTEntry fromEdgeEntry )
public boolean execute( final int traversalId, final SPTEntry fromSPTEntry )
{
SPTEntry toEdgeEntry = bestWeightMapTo.get(traversalId);
if (toEdgeEntry == null)
SPTEntry toSPTEntry = bestWeightMapTo.get(traversalId);
if (toSPTEntry == null)
return true;

if (traversalMode.isEdgeBased())
{
if (toEdgeEntry.parent != null)
if (toSPTEntry.parent != null)
// move to parent for two reasons:
// 1. make only turn costs missing in 'weight' and not duplicating current edge.weight
// 2. to avoid duplicate edge in Path
toEdgeEntry = toEdgeEntry.parent;
// TODO else if fromEdgeEntry.parent != null fromEdgeEntry = fromEdgeEntry.parent;
toSPTEntry = toSPTEntry.parent;
// TODO else if fromSPTEntry.parent != null fromSPTEntry = fromSPTEntry.parent;

} else
{
// The alternative path is suboptimal when both entries are parallel
if (fromEdgeEntry.edge == toEdgeEntry.edge)
if (fromSPTEntry.edge == toSPTEntry.edge)
return true;
}

// (1) skip too long paths
final double weight = fromEdgeEntry.getWeightOfVisitedPath() + toEdgeEntry.getWeightOfVisitedPath();
final double weight = fromSPTEntry.getWeightOfVisitedPath() + toSPTEntry.getWeightOfVisitedPath();
if (weight > maxWeight)
return true;

// (2) Use the start traversal ID of a plateau as ID for the alternative path.
// Accept from-EdgeEntries only if such a start of a plateau
// i.e. discard if its parent has the same edgeId as the next to-EdgeEntry.
// i.e. discard if its parent has the same edgeId as the next to-SPTEntry.
// Ignore already added best path
if (isBestPath(fromEdgeEntry, bestPath))
if (isBestPath(fromSPTEntry, bestPath))
return true;

// For edge based traversal we need the next entry to find out the plateau start
SPTEntry tmpFromEntry = traversalMode.isEdgeBased() ? fromEdgeEntry.parent : fromEdgeEntry;
SPTEntry tmpFromEntry = traversalMode.isEdgeBased() ? fromSPTEntry.parent : fromSPTEntry;
if (tmpFromEntry == null || tmpFromEntry.parent == null)
{
// we can be here only if edge based and only if entry is not part of the best path
Expand All @@ -407,14 +407,14 @@ public boolean execute( final int traversalId, final SPTEntry fromEdgeEntry )
{
int nextToTraversalId = traversalMode.createTraversalId(tmpFromEntry.adjNode,
tmpFromEntry.parent.adjNode, tmpFromEntry.edge, true);
SPTEntry tmpNextToEdgeEntry = bestWeightMapTo.get(nextToTraversalId);
if (tmpNextToEdgeEntry == null)
SPTEntry tmpNextToSPTEntry = bestWeightMapTo.get(nextToTraversalId);
if (tmpNextToSPTEntry == null)
return true;

if (traversalMode.isEdgeBased())
tmpNextToEdgeEntry = tmpNextToEdgeEntry.parent;
tmpNextToSPTEntry = tmpNextToSPTEntry.parent;
// skip if on plateau
if (fromEdgeEntry.edge == tmpNextToEdgeEntry.edge)
if (fromSPTEntry.edge == tmpNextToSPTEntry.edge)
return true;
}

Expand All @@ -427,44 +427,44 @@ public boolean execute( final int traversalId, final SPTEntry fromEdgeEntry )
// start end
//
// extend plateau in only one direction necessary (A to B to ...) as we know
// that the from-EdgeEntry is the start of the plateau or there is no plateau at all
// that the from-SPTEntry is the start of the plateau or there is no plateau at all
//
double plateauWeight = 0;
SPTEntry prevToEdgeEntry = toEdgeEntry;
SPTEntry prevToSPTEntry = toSPTEntry;
// List<Integer> plateauEdges = new ArrayList<Integer>();
while (prevToEdgeEntry.parent != null)
while (prevToSPTEntry.parent != null)
{
int nextFromTraversalId = traversalMode.createTraversalId(prevToEdgeEntry.adjNode, prevToEdgeEntry.parent.adjNode,
prevToEdgeEntry.edge, false);
int nextFromTraversalId = traversalMode.createTraversalId(prevToSPTEntry.adjNode, prevToSPTEntry.parent.adjNode,
prevToSPTEntry.edge, false);

SPTEntry nextFromEdgeEntry = bestWeightMapFrom.get(nextFromTraversalId);
SPTEntry nextFromSPTEntry = bestWeightMapFrom.get(nextFromTraversalId);
// end of a plateau
if (nextFromEdgeEntry == null)
if (nextFromSPTEntry == null)
break;

// is the next from-EdgeEntry on the plateau?
if (prevToEdgeEntry.edge != nextFromEdgeEntry.edge)
// is the next from-SPTEntry on the plateau?
if (prevToSPTEntry.edge != nextFromSPTEntry.edge)
break;

// plateauEdges.add(prevToEdgeEntry.edge);
plateauWeight += (prevToEdgeEntry.getWeightOfVisitedPath() - prevToEdgeEntry.parent.getWeightOfVisitedPath());
prevToEdgeEntry = prevToEdgeEntry.parent;
// plateauEdges.add(prevToSPTEntry.edge);
plateauWeight += (prevToSPTEntry.getWeightOfVisitedPath() - prevToSPTEntry.parent.getWeightOfVisitedPath());
prevToSPTEntry = prevToSPTEntry.parent;
}

if (plateauWeight <= 0 || plateauWeight / weight < minPlateauFactor)
return true;

if (fromEdgeEntry.parent == null)
throw new IllegalStateException("not implemented yet. in case of an edge based traversal the parent of fromEdgeEntry could be null");
if (fromSPTEntry.parent == null)
throw new IllegalStateException("not implemented yet. in case of an edge based traversal the parent of fromSPTEntry could be null");

// (3b) calculate share
SPTEntry fromEE = getFirstShareEE(fromEdgeEntry.parent, true);
SPTEntry toEE = getFirstShareEE(toEdgeEntry.parent, false);
SPTEntry fromEE = getFirstShareEE(fromSPTEntry.parent, true);
SPTEntry toEE = getFirstShareEE(toSPTEntry.parent, false);
double shareWeight = fromEE.getWeightOfVisitedPath() + toEE.getWeightOfVisitedPath();
boolean smallShare = shareWeight / bestPath.getWeight() < maxShareFactor;
if (smallShare)
{
List<String> altNames = getAltNames(graph, fromEdgeEntry);
List<String> altNames = getAltNames(graph, fromSPTEntry);

double sortBy = calcSortBy(weightInfluence, weight, shareInfluence, shareWeight, plateauInfluence, plateauWeight);
double worstSortBy = getWorstSortBy();
Expand All @@ -473,7 +473,7 @@ public boolean execute( final int traversalId, final SPTEntry fromEdgeEntry )
if (sortBy < worstSortBy || alternatives.size() < maxPaths)
{
Path path = new PathBidirRef(graph, flagEncoder).
setEdgeEntryTo(toEdgeEntry).setEdgeEntry(fromEdgeEntry).
setSPTEntryTo(toSPTEntry).setSPTEntry(fromSPTEntry).
setWeight(weight);
path.extract();

Expand Down Expand Up @@ -538,30 +538,30 @@ public boolean execute( TIntSet set )
return alternatives.get(alternatives.size() - 1).sortBy;
}

// returns true if fromEdgeEntry is identical to the specified best path
boolean isBestPath( SPTEntry fromEdgeEntry, Path bestPath )
// returns true if fromSPTEntry is identical to the specified best path
boolean isBestPath( SPTEntry fromSPTEntry, Path bestPath )
{
if (traversalMode.isEdgeBased())
{
if (GHUtility.getEdgeFromEdgeKey(startTID.get()) == fromEdgeEntry.edge)
if (GHUtility.getEdgeFromEdgeKey(startTID.get()) == fromSPTEntry.edge)
{
if (fromEdgeEntry.parent == null)
throw new IllegalStateException("best path must have no parent but was non-null: " + fromEdgeEntry);
if (fromSPTEntry.parent == null)
throw new IllegalStateException("best path must have no parent but was non-null: " + fromSPTEntry);

return true;
}

} else
{
if (fromEdgeEntry.parent == null)
if (fromSPTEntry.parent == null)
{
bestPathEntries.add(fromEdgeEntry);
bestPathEntries.add(fromSPTEntry);
if (bestPathEntries.size() > 1)
throw new IllegalStateException("There is only one best path but was: " + bestPathEntries);

if (startTID.get() != fromEdgeEntry.adjNode)
if (startTID.get() != fromSPTEntry.adjNode)
throw new IllegalStateException("Start traversal ID has to be identical to root edge entry "
+ "which is the plateau start of the best path but was: " + startTID + " vs. adjNode: " + fromEdgeEntry.adjNode);
+ "which is the plateau start of the best path but was: " + startTID + " vs. adjNode: " + fromSPTEntry.adjNode);

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/graphhopper/routing/Dijkstra.java
Expand Up @@ -61,7 +61,7 @@ public Path calcPath( int from, int to )
{
checkAlreadyRun();
this.to = to;
currEdge = createEdgeEntry(from, 0);
currEdge = createSPTEntry(from, 0);
if (!traversalMode.isEdgeBased())
{
fromMap.put(from, currEdge);
Expand Down Expand Up @@ -132,7 +132,7 @@ protected Path extractPath()
if (currEdge == null || isWeightLimitExceeded() || !finished())
return createEmptyPath();

return new Path(graph, flagEncoder).setWeight(currEdge.weight).setEdgeEntry(currEdge).extract();
return new Path(graph, flagEncoder).setWeight(currEdge.weight).setSPTEntry(currEdge).extract();
}

@Override
Expand Down
Expand Up @@ -69,7 +69,7 @@ protected void initCollections( int nodes )
@Override
public void initFrom( int from, double weight )
{
currFrom = createEdgeEntry(from, weight);
currFrom = createSPTEntry(from, weight);
openSetFrom.add(currFrom);
if (!traversalMode.isEdgeBased())
{
Expand All @@ -84,7 +84,7 @@ public void initFrom( int from, double weight )
if (currTo != null && currTo.adjNode == from)
{
// special case of identical start and end
bestPath.edgeEntry = currFrom;
bestPath.sptEntry = currFrom;
bestPath.edgeTo = currTo;
finishedFrom = true;
finishedTo = true;
Expand All @@ -95,7 +95,7 @@ public void initFrom( int from, double weight )
@Override
public void initTo( int to, double weight )
{
currTo = createEdgeEntry(to, weight);
currTo = createSPTEntry(to, weight);
openSetTo.add(currTo);
if (!traversalMode.isEdgeBased())
{
Expand All @@ -110,7 +110,7 @@ public void initTo( int to, double weight )
if (currFrom != null && currFrom.adjNode == to)
{
// special case of identical start and end
bestPath.edgeEntry = currFrom;
bestPath.sptEntry = currFrom;
bestPath.edgeTo = currTo;
finishedFrom = true;
finishedTo = true;
Expand Down Expand Up @@ -258,9 +258,9 @@ protected void updateBestPath( EdgeIteratorState edgeState, SPTEntry entryCurren
if (newWeight < bestPath.getWeight())
{
bestPath.setSwitchToFrom(reverse);
bestPath.setEdgeEntry(entryCurrent);
bestPath.setSPTEntry(entryCurrent);
bestPath.setWeight(newWeight);
bestPath.setEdgeEntryTo(entryOther);
bestPath.setSPTEntryTo(entryOther);
}
}

Expand Down
17 changes: 10 additions & 7 deletions core/src/main/java/com/graphhopper/routing/Path.java
Expand Up @@ -46,11 +46,14 @@ public class Path
protected Graph graph;
private FlagEncoder encoder;
protected double distance;
// we go upwards (via EdgeEntry.parent) from the goal node to the origin node
// we go upwards (via SPTEntry.parent) from the goal node to the origin node
protected boolean reverseOrder = true;
protected long time;
private boolean found;
protected SPTEntry edgeEntry;
/**
* Shortest path tree entry
*/
protected SPTEntry sptEntry;
final StopWatch extractSW = new StopWatch("extract");
private int fromNode = -1;
protected int endNode = -1;
Expand All @@ -75,7 +78,7 @@ public Path( Graph graph, FlagEncoder encoder )
this(p.graph, p.encoder);
weight = p.weight;
edgeIds = new TIntArrayList(p.edgeIds);
edgeEntry = p.edgeEntry;
sptEntry = p.sptEntry;
}

/**
Expand All @@ -95,9 +98,9 @@ public Path setDescription( List<String> description )
return this;
}

public Path setEdgeEntry( SPTEntry edgeEntry )
public Path setSPTEntry( SPTEntry sptEntry )
{
this.edgeEntry = edgeEntry;
this.sptEntry = sptEntry;
return this;
}

Expand Down Expand Up @@ -183,15 +186,15 @@ public Path setWeight( double w )
}

/**
* Extracts the Path from the shortest-path-tree determined by edgeEntry.
* Extracts the Path from the shortest-path-tree determined by sptEntry.
*/
public Path extract()
{
if (isFound())
throw new IllegalStateException("Extract can only be called once");

extractSW.start();
SPTEntry goalEdge = edgeEntry;
SPTEntry goalEdge = sptEntry;
setEndNode(goalEdge.adjNode);
while (EdgeIterator.Edge.isValid(goalEdge.edge))
{
Expand Down

0 comments on commit c0105cd

Please sign in to comment.