Skip to content

Commit

Permalink
Move stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
michaz committed Mar 20, 2020
1 parent bcf7c78 commit 2fd6cb5
Showing 1 changed file with 73 additions and 73 deletions.
146 changes: 73 additions & 73 deletions core/src/main/java/com/graphhopper/routing/AlternativeRouteCH.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class AlternativeRouteCH extends DijkstraBidirectionCHNoSOD {
private final double maxShareFactor;
private final double localOptimalityFactor;
private int extraVisitedNodes = 0;
private List<AlternativeInfo> alternatives = new ArrayList<>();

public AlternativeRouteCH(RoutingCHGraph graph, PMap hints) {
super(graph);
Expand Down Expand Up @@ -77,7 +78,6 @@ List<AlternativeInfo> calcAlternatives(final int s, final int t) {
return Collections.emptyList();
}

final List<AlternativeInfo> alternatives = new ArrayList<>();
alternatives.add(new AlternativeInfo(bestPath, 0));

bestWeightMapFrom.forEach(new IntObjectPredicate<SPTEntry>() {
Expand Down Expand Up @@ -135,90 +135,90 @@ public boolean apply(final int v, final SPTEntry fromSPTEntry) {
return true;
}

private double calculateShare(final Path path) {
double sharedDistance = sharedDistance(path);
return sharedDistance / path.getDistance();
});
Collections.sort(alternatives, new Comparator<AlternativeInfo>() {
@Override
public int compare(AlternativeInfo o1, AlternativeInfo o2) {
return Double.compare(o1.path.getWeight(), o2.path.getWeight());
}
});
return alternatives;
}

private double sharedDistance(Path path) {
double sharedDistance = 0.0;
List<EdgeIteratorState> edges = path.calcEdges();
for (EdgeIteratorState edge : edges) {
if (nodesInCurrentAlternativeSetContains(edge.getBaseNode()) && nodesInCurrentAlternativeSetContains(edge.getAdjNode())) {
sharedDistance += edge.getDistance();
}
}
return sharedDistance;
}
private double calculateShare(final Path path) {
double sharedDistance = sharedDistance(path);
return sharedDistance / path.getDistance();
}

private double sharedDistanceWithShortest(Path path) {
double sharedDistance = 0.0;
List<EdgeIteratorState> edges = path.calcEdges();
for (EdgeIteratorState edge : edges) {
if (alternatives.get(0).nodes.contains(edge.getBaseNode()) && alternatives.get(0).nodes.contains(edge.getAdjNode())) {
sharedDistance += edge.getDistance();
}
}
return sharedDistance;
private double sharedDistance(Path path) {
double sharedDistance = 0.0;
List<EdgeIteratorState> edges = path.calcEdges();
for (EdgeIteratorState edge : edges) {
if (nodesInCurrentAlternativeSetContains(edge.getBaseNode()) && nodesInCurrentAlternativeSetContains(edge.getAdjNode())) {
sharedDistance += edge.getDistance();
}
}
return sharedDistance;
}

private boolean nodesInCurrentAlternativeSetContains(int v) {
for (AlternativeInfo alternative : alternatives) {
if (alternative.nodes.contains(v)) {
return true;
}
}
return false;
private double sharedDistanceWithShortest(Path path) {
double sharedDistance = 0.0;
List<EdgeIteratorState> edges = path.calcEdges();
for (EdgeIteratorState edge : edges) {
if (alternatives.get(0).nodes.contains(edge.getBaseNode()) && alternatives.get(0).nodes.contains(edge.getAdjNode())) {
sharedDistance += edge.getDistance();
}
}
return sharedDistance;
}

private boolean tTest(Path path, int vIndex) {
if (path.getEdgeCount() == 0) return true;
double detourDistance = detourDistance(path);
double T = 0.5 * localOptimalityFactor * detourDistance;
int fromNode = getPreviousNodeTMetersAway(path, vIndex, T);
int toNode = getNextNodeTMetersAway(path, vIndex, T);
DijkstraBidirectionCHNoSOD tRouter = new DijkstraBidirectionCHNoSOD(graph);
Path tPath = tRouter.calcPath(fromNode, toNode);
extraVisitedNodes += tRouter.getVisitedNodes();
IntIndexedContainer tNodes = tPath.calcNodes();
int v = path.calcNodes().get(vIndex);
return tNodes.contains(v);
private boolean nodesInCurrentAlternativeSetContains(int v) {
for (AlternativeInfo alternative : alternatives) {
if (alternative.nodes.contains(v)) {
return true;
}
}
return false;
}

private double detourDistance(Path path) {
return path.getDistance() - sharedDistanceWithShortest(path);
}
private boolean tTest(Path path, int vIndex) {
if (path.getEdgeCount() == 0) return true;
double detourDistance = detourDistance(path);
double T = 0.5 * localOptimalityFactor * detourDistance;
int fromNode = getPreviousNodeTMetersAway(path, vIndex, T);
int toNode = getNextNodeTMetersAway(path, vIndex, T);
DijkstraBidirectionCHNoSOD tRouter = new DijkstraBidirectionCHNoSOD(graph);
Path tPath = tRouter.calcPath(fromNode, toNode);
extraVisitedNodes += tRouter.getVisitedNodes();
IntIndexedContainer tNodes = tPath.calcNodes();
int v = path.calcNodes().get(vIndex);
return tNodes.contains(v);
}

private int getPreviousNodeTMetersAway(Path path, int vIndex, double T) {
List<EdgeIteratorState> edges = path.calcEdges();
double distance = 0.0;
int i = vIndex;
while (i > 0 && distance < T) {
distance += edges.get(i - 1).getDistance();
i--;
}
return edges.get(i).getBaseNode();
}
private double detourDistance(Path path) {
return path.getDistance() - sharedDistanceWithShortest(path);
}

private int getNextNodeTMetersAway(Path path, int vIndex, double T) {
List<EdgeIteratorState> edges = path.calcEdges();
double distance = 0.0;
int i = vIndex;
while (i < edges.size() - 1 && distance < T) {
distance += edges.get(i).getDistance();
i++;
}
return edges.get(i - 1).getAdjNode();
}
private int getPreviousNodeTMetersAway(Path path, int vIndex, double T) {
List<EdgeIteratorState> edges = path.calcEdges();
double distance = 0.0;
int i = vIndex;
while (i > 0 && distance < T) {
distance += edges.get(i - 1).getDistance();
i--;
}
return edges.get(i).getBaseNode();
}

});
Collections.sort(alternatives, new Comparator<AlternativeInfo>() {
@Override
public int compare(AlternativeInfo o1, AlternativeInfo o2) {
return Double.compare(o1.path.getWeight(), o2.path.getWeight());
}
});
return alternatives;
private int getNextNodeTMetersAway(Path path, int vIndex, double T) {
List<EdgeIteratorState> edges = path.calcEdges();
double distance = 0.0;
int i = vIndex;
while (i < edges.size() - 1 && distance < T) {
distance += edges.get(i).getDistance();
i++;
}
return edges.get(i - 1).getAdjNode();
}

private static Path concat(Graph graph, Path svPath, Path vtPath) {
Expand Down

0 comments on commit 2fd6cb5

Please sign in to comment.