use of com.graphhopper.routing.weighting.AvoidEdgesWeighting in project graphhopper by graphhopper.
the class DirectedBidirectionalDijkstraTest method createAvoidEdgeWeighting.
private AvoidEdgesWeighting createAvoidEdgeWeighting(EdgeIteratorState edgeOut) {
AvoidEdgesWeighting avoidEdgesWeighting = new AvoidEdgesWeighting(weighting);
avoidEdgesWeighting.setEdgePenaltyFactor(Double.POSITIVE_INFINITY);
avoidEdgesWeighting.setAvoidedEdges(IntHashSet.from(edgeOut.getEdge()));
return avoidEdgesWeighting;
}
use of com.graphhopper.routing.weighting.AvoidEdgesWeighting in project graphhopper by graphhopper.
the class RoundTripRoutingTemplate method calcPaths.
@Override
public List<Path> calcPaths(QueryGraph queryGraph, RoutingAlgorithmFactory algoFactory, AlgorithmOptions algoOpts) {
pathList = new ArrayList<>(queryResults.size() - 1);
AvoidEdgesWeighting avoidPathWeighting = new AvoidEdgesWeighting(algoOpts.getWeighting());
avoidPathWeighting.setEdgePenaltyFactor(5);
algoOpts = AlgorithmOptions.start(algoOpts).algorithm(Parameters.Algorithms.ASTAR_BI).weighting(avoidPathWeighting).build();
algoOpts.getHints().put(Algorithms.AStarBi.EPSILON, 2);
long visitedNodesSum = 0L;
QueryResult start = queryResults.get(0);
for (int qrIndex = 1; qrIndex < queryResults.size(); qrIndex++) {
RoutingAlgorithm algo = algoFactory.createAlgo(queryGraph, algoOpts);
// instead getClosestNode (which might be a virtual one and introducing unnecessary tails of the route)
// use next tower node -> getBaseNode or getAdjNode
// Later: remove potential route tail
QueryResult startQR = queryResults.get(qrIndex - 1);
int startNode = (startQR == start) ? startQR.getClosestNode() : startQR.getClosestEdge().getBaseNode();
QueryResult endQR = queryResults.get(qrIndex);
int endNode = (endQR == start) ? endQR.getClosestNode() : endQR.getClosestEdge().getBaseNode();
Path path = algo.calcPath(startNode, endNode);
visitedNodesSum += algo.getVisitedNodes();
pathList.add(path);
// it is important to avoid previously visited nodes for future paths
avoidPathWeighting.addEdges(path.calcEdges());
}
ghResponse.getHints().put("visited_nodes.sum", visitedNodesSum);
ghResponse.getHints().put("visited_nodes.average", (float) visitedNodesSum / (queryResults.size() - 1));
return pathList;
}
Aggregations