use of im.tny.segvault.subway.IEdgeWeighter in project underlx by underlx.
the class Route method getShortestPath.
public static GraphPath getShortestPath(Network network, List<Stop> possibleSources, List<Stop> possibleTargets, @Nullable IEdgeWeighter weighter) {
AStarShortestPath as = new AStarShortestPath(network);
AStarAdmissibleHeuristic heuristic = new AStarAdmissibleHeuristic<Stop>() {
@Override
public double getCostEstimate(Stop sourceVertex, Stop targetVertex) {
return 0;
}
};
List<GraphPath> paths = new ArrayList<>();
// lock on class so that if this method is called concurrently the annotations won't be messed up
synchronized (Route.class) {
IEdgeWeighter prevWeighter = network.getEdgeWeighter();
if (weighter != null) {
network.setEdgeWeighter(weighter);
}
for (Stop pSource : possibleSources) {
for (Stop pTarget : possibleTargets) {
// hackish "annotations" for the connection weighter
pSource.putMeta("is_route_source", true);
pTarget.putMeta("is_route_target", true);
paths.add(as.getShortestPath(pSource, pTarget, heuristic));
pSource.putMeta("is_route_source", null);
pTarget.putMeta("is_route_target", null);
}
}
network.setEdgeWeighter(prevWeighter);
}
GraphPath path = null;
for (GraphPath p : paths) {
if (path == null || p.getWeight() < path.getWeight()) {
path = p;
}
}
return path;
}
Aggregations