/** * This method adds the traversal IDs of the specified path as set to the specified map. */ AtomicInteger addToMap(GHIntObjectHashMap<IntSet> map, Path path) { IntSet set = new GHIntHashSet(); final AtomicInteger startTID = new AtomicInteger(-1); for (EdgeIteratorState iterState : path.calcEdges()) { int tid = traversalMode.createTraversalId(iterState, false); set.add(tid); if (startTID.get() < 0) { // for node based traversal we need to explicitely add base node as starting node and to list if (!traversalMode.isEdgeBased()) { tid = iterState.getBaseNode(); set.add(tid); } startTID.set(tid); } } map.put(startTID.get(), set); return startTID; } }
@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; }
/** * Returns the path length plus a penalty if the starting/ending edge is unfavored. */ private double penalizedPathDistance(Path path, Set<EdgeIteratorState> penalizedVirtualEdges) { double totalPenalty = 0; // Unfavored edges in the middle of the path should not be penalized because we are // only concerned about the direction at the start/end. final List<EdgeIteratorState> edges = path.calcEdges(); if (!edges.isEmpty()) { if (penalizedVirtualEdges.contains(edges.get(0))) { totalPenalty += uTurnDistancePenalty; } } if (edges.size() > 1) { if (penalizedVirtualEdges.contains(edges.get(edges.size() - 1))) { totalPenalty += uTurnDistancePenalty; } } return path.getDistance() + totalPenalty; }
/** * Returns the path length plus a penalty if the starting/ending edge is unfavored. */ private double penalizedPathDistance(Path path, Set<EdgeIteratorState> penalizedVirtualEdges) { double totalPenalty = 0; // Unfavored edges in the middle of the path should not be penalized because we are // only concerned about the direction at the start/end. final List<EdgeIteratorState> edges = path.calcEdges(); if (!edges.isEmpty()) { if (penalizedVirtualEdges.contains(edges.get(0))) { totalPenalty += uTurnDistancePenalty; } } if (edges.size() > 1) { if (penalizedVirtualEdges.contains(edges.get(edges.size() - 1))) { totalPenalty += uTurnDistancePenalty; } } return path.getDistance() + totalPenalty; }
/** * This method adds the traversal IDs of the specified path as set to the specified map. */ AtomicInteger addToMap(GHIntObjectHashMap<IntSet> map, Path path) { IntSet set = new GHIntHashSet(); final AtomicInteger startTID = new AtomicInteger(-1); for (EdgeIteratorState iterState : path.calcEdges()) { int tid = traversalMode.createTraversalId(iterState, false); set.add(tid); if (startTID.get() < 0) { // for node based traversal we need to explicitely add base node as starting node and to list if (!traversalMode.isEdgeBased()) { tid = iterState.getBaseNode(); set.add(tid); } startTID.set(tid); } } map.put(startTID.get(), set); return startTID; } }
/** * This method adds the traversal IDs of the specified path as set to the specified map. */ AtomicInteger addToMap(GHIntObjectHashMap<IntSet> map, Path path) { IntSet set = new GHIntHashSet(); final AtomicInteger startTID = new AtomicInteger(-1); for (EdgeIteratorState iterState : path.calcEdges()) { int tid = traversalMode.createTraversalId(iterState, false); set.add(tid); if (startTID.get() < 0) { // for node based traversal we need to explicitely add base node as starting node and to list if (!traversalMode.isEdgeBased()) { tid = iterState.getBaseNode(); set.add(tid); } startTID.set(tid); } } map.put(startTID.get(), set); return startTID; } }
/** * This method adds the traversal IDs of the specified path as set to the specified map. */ AtomicInteger addToMap( TIntObjectHashMap<TIntSet> map, Path path ) { TIntSet set = new TIntHashSet(); final AtomicInteger startTID = new AtomicInteger(-1); for (EdgeIteratorState iterState : path.calcEdges()) { int tid = traversalMode.createTraversalId(iterState, false); set.add(tid); if (startTID.get() < 0) { // for node based traversal we need to explicitely add base node as starting node and to list if (!traversalMode.isEdgeBased()) { tid = iterState.getBaseNode(); set.add(tid); } startTID.set(tid); } } map.put(startTID.get(), set); return startTID; } }
public class GraphHopperWithPaths extends GraphHopper { public List<Integer> routePaths(double startY, double startX, double endY, double endX){ //Examine a route and return edgeIDs that GraphHopper uses LocationIndex index = this.getLocationIndex(); GHRequest request = new GHRequest(startY, startX, endY, endX); GHResponse response = new GHResponse(); List<Path> paths = getPaths(request, response); List<Integer> edges = new ArrayList<Integer>(); for(Path p:paths){ for(EdgeIteratorState e:p.calcEdges()){ edges.add(e.getEdge()); } } if (response.hasErrors()) return null; //Get edges for start and end point as well QueryResult qr = index.findClosest(startY, startX, EdgeFilter.ALL_EDGES ); edges.add(qr.getClosestEdge().getEdge()); qr = index.findClosest(endY, endX, EdgeFilter.ALL_EDGES ); edges.add(qr.getClosestEdge().getEdge()); return edges; } }
for (EdgeIteratorState edge : transitionAndState.transitionDescriptor.calcEdges()) { EdgeIteratorState newDirectedRealEdge = resolveToRealEdge(virtualEdgesMap, edge); if (currentDirectedRealEdge != null) {
for (EdgeIteratorState edge : transitionAndState.transitionDescriptor.calcEdges()) { EdgeIteratorState newDirectedRealEdge = resolveToRealEdge(virtualEdgesMap, edge); if (currentDirectedRealEdge != null) {
@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.ASTAR_BI + ".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; }
avoidPathWeighting.addEdges(path.calcEdges());
@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; }
List<EdgeIteratorState> pathEdgeList = path.calcEdges();
for (SequenceState<GPXExtension, GPXEntry, Path> ss : seq) { logger.debug("{}: {}, path: {}", i, ss.state, ss.transitionDescriptor != null ? ss.transitionDescriptor.calcEdges() : null); i++;
for (SequenceState<GPXExtension, GPXEntry, Path> ss : seq) { logger.debug("{}: {}, path: {}", i, ss.state, ss.transitionDescriptor != null ? ss.transitionDescriptor.calcEdges() : null); i++;
private MatchResult computeMatchResult(List<SequenceState<GPXExtension, GPXEntry, Path>> seq, Map<String, EdgeIteratorState> virtualEdgesMap, List<GPXEntry> gpxList, QueryGraph queryGraph) { double distance = 0.0; long time = 0; for (SequenceState<GPXExtension, GPXEntry, Path> transitionAndState : seq) { if (transitionAndState.transitionDescriptor != null) { distance += transitionAndState.transitionDescriptor.getDistance(); time += transitionAndState.transitionDescriptor.getTime(); } } List<EdgeIteratorState> edges = new ArrayList<>(); for (SequenceState<GPXExtension, GPXEntry, Path> state : seq) { if (state.transitionDescriptor != null) { edges.addAll(state.transitionDescriptor.calcEdges()); } } Path mergedPath = new MapMatchedPath(queryGraph.getBaseGraph(), weighting, edges); List<EdgeMatch> edgeMatches = computeEdgeMatches(seq, virtualEdgesMap); MatchResult matchResult = new MatchResult(edgeMatches); matchResult.setMergedPath(mergedPath); matchResult.setMatchMillis(time); matchResult.setMatchLength(distance); matchResult.setGPXEntriesMillis(durationMillis(gpxList)); matchResult.setGPXEntriesLength(gpxLength(gpxList)); return matchResult; }
private MatchResult computeMatchResult(List<SequenceState<GPXExtension, GPXEntry, Path>> seq, Map<String, EdgeIteratorState> virtualEdgesMap, List<GPXEntry> gpxList, QueryGraph queryGraph) { double distance = 0.0; long time = 0; for (SequenceState<GPXExtension, GPXEntry, Path> transitionAndState : seq) { if (transitionAndState.transitionDescriptor != null) { distance += transitionAndState.transitionDescriptor.getDistance(); time += transitionAndState.transitionDescriptor.getTime(); } } List<EdgeIteratorState> edges = new ArrayList<>(); for (SequenceState<GPXExtension, GPXEntry, Path> state : seq) { if (state.transitionDescriptor != null) { edges.addAll(state.transitionDescriptor.calcEdges()); } } Path mergedPath = new MapMatchedPath(queryGraph.getBaseGraph(), weighting, edges); List<EdgeMatch> edgeMatches = computeEdgeMatches(seq, virtualEdgesMap); MatchResult matchResult = new MatchResult(edgeMatches); matchResult.setMergedPath(mergedPath); matchResult.setMatchMillis(time); matchResult.setMatchLength(distance); matchResult.setGPXEntriesMillis(durationMillis(gpxList)); matchResult.setGPXEntriesLength(gpxLength(gpxList)); return matchResult; }