public String export(GHRequest ghRequest) { String str = "Creating request failed"; try { Request okRequest = createRequest(ghRequest); str = getClientForRequest(ghRequest).newCall(okRequest).execute().body().string(); return str; } catch (Exception ex) { throw new RuntimeException("Problem while fetching export " + ghRequest.getPoints() + ", error: " + ex.getMessage() + " response: " + str, ex); } } }
@Override public boolean isReady(PathMerger pathMerger, Translation tr) { if (ghRequest.getPoints().size() - 1 != pathList.size()) throw new RuntimeException("There should be exactly one more points than paths. points:" + ghRequest.getPoints().size() + ", paths:" + pathList.size()); altResponse.setWaypoints(getWaypoints()); ghResponse.add(altResponse); pathMerger.doWork(altResponse, pathList, tr); return true; }
@Override public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) { if (points.size() != 1 || ghRequest.getPoints().size() != 1) throw new IllegalArgumentException("For round trip calculation exactly one point is required"); final double distanceInMeter = ghRequest.getHints().getDouble(RoundTrip.DISTANCE, 10000); final long seed = ghRequest.getHints().getLong(RoundTrip.SEED, 0L); double initialHeading = ghRequest.getFavoredHeading(0); final int roundTripPointCount = Math.min(20, ghRequest.getHints().getInt(RoundTrip.POINTS, 2 + (int) (distanceInMeter / 50000))); final GHPoint start = points.get(0); TourStrategy strategy = new MultiPointTour(new Random(seed), distanceInMeter, roundTripPointCount, initialHeading); queryResults = new ArrayList<>(2 + strategy.getNumberOfGeneratedPoints()); EdgeFilter edgeFilter = DefaultEdgeFilter.allEdges(encoder); QueryResult startQR = locationIndex.findClosest(start.lat, start.lon, edgeFilter); if (!startQR.isValid()) throw new PointNotFoundException("Cannot find point 0: " + start, 0); queryResults.add(startQR); GHPoint last = start; for (int i = 0; i < strategy.getNumberOfGeneratedPoints(); i++) { double heading = strategy.getHeadingForIteration(i); QueryResult result = generateValidPoint(last, strategy.getDistanceForIteration(i), heading, edgeFilter); if (result == null) { ghResponse.addError(new IllegalStateException("Could not find a valid point after " + maxRetries + " tries, for the point:" + last)); return Collections.emptyList(); } last = result.getSnappedPoint(); queryResults.add(result); } queryResults.add(startQR); return queryResults; }
@Override public GHResponse route(GHRequest request) { ResponseBody rspBody = null; try { Request okRequest = createRequest(request); rspBody = getClientForRequest(request).newCall(okRequest).execute().body(); JsonNode json = objectMapper.reader().readTree(rspBody.byteStream()); GHResponse res = new GHResponse(); res.addErrors(readErrors(json)); if (res.hasErrors()) return res; JsonNode paths = json.get("paths"); boolean tmpElevation = request.getHints().getBool("elevation", elevation); boolean tmpTurnDescription = request.getHints().getBool("turn_description", true); for (JsonNode path : paths) { PathWrapper altRsp = createPathWrapper(path, tmpElevation, tmpTurnDescription); res.add(altRsp); } return res; } catch (Exception ex) { throw new RuntimeException("Problem while fetching path " + request.getPoints() + ": " + ex.getMessage(), ex); } finally { Helper.close(rspBody); } }
for (GHPoint p : request.getPoints()) { places += "point=" + round6(p.lat) + "," + round6(p.lon) + "&";
long visitedNodesSum = 0L; boolean viaTurnPenalty = ghRequest.getHints().getBool(Routing.PASS_THROUGH, false); int pointCounts = ghRequest.getPoints().size(); pathList = new ArrayList<>(pointCounts - 1); QueryResult fromQResult = queryResults.get(0);
algoStr = chFactoryDecorator.isEnabled() && !disableCH ? DIJKSTRA_BI : ASTAR_BI; List<GHPoint> points = request.getPoints();
@Test public void testLookupAndCalcPaths_simpleSquareGraph() { Graph g = createSquareGraph(); // start at node 0 and head south, make sure the round trip is long enough to reach most southern node 6 GHPoint start = new GHPoint(1, -1); double heading = 180.0; int numPoints = 2; double roundTripDistance = 670000; GHRequest ghRequest = new GHRequest(Collections.singletonList(start), Collections.singletonList(heading)); ghRequest.getHints().put(Parameters.Algorithms.RoundTrip.POINTS, numPoints); ghRequest.getHints().put(Parameters.Algorithms.RoundTrip.DISTANCE, roundTripDistance); LocationIndex locationIndex = new LocationIndexTree(g, new RAMDirectory()).prepareIndex(); RoundTripRoutingTemplate routingTemplate = new RoundTripRoutingTemplate(ghRequest, new GHResponse(), locationIndex, 1); List<QueryResult> stagePoints = routingTemplate.lookup(ghRequest.getPoints(), carFE); assertEquals(3, stagePoints.size()); assertEquals(0, stagePoints.get(0).getClosestNode()); assertEquals(6, stagePoints.get(1).getClosestNode()); assertEquals(0, stagePoints.get(2).getClosestNode()); QueryGraph queryGraph = new QueryGraph(g); queryGraph.lookup(stagePoints); Weighting weighting = new FastestWeighting(carFE); List<Path> paths = routingTemplate.calcPaths( queryGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); // make sure the resulting paths are connected and form a round trip starting and ending at the start node 0 assertEquals(2, paths.size()); assertEquals(IntArrayList.from(new int[]{0, 7, 6, 5}), paths.get(0).calcNodes()); assertEquals(IntArrayList.from(new int[]{5, 4, 3, 2, 1, 0}), paths.get(1).calcNodes()); }
@Override public boolean isReady( PathMerger pathMerger, Translation tr ) { if (ghRequest.getPoints().size() - 1 != pathList.size()) throw new RuntimeException("There should be exactly one more points than paths. points:" + ghRequest.getPoints().size() + ", paths:" + pathList.size()); altResponse.setWaypoints(getWaypoints()); ghResponse.add(altResponse); pathMerger.doWork(altResponse, pathList, tr); return true; }
@Override public boolean isReady(PathMerger pathMerger, Translation tr) { if (ghRequest.getPoints().size() - 1 != pathList.size()) throw new RuntimeException("There should be exactly one more points than paths. points:" + ghRequest.getPoints().size() + ", paths:" + pathList.size()); altResponse.setWaypoints(getWaypoints()); ghResponse.add(altResponse); pathMerger.doWork(altResponse, pathList, tr); return true; }
@Override public boolean isReady(PathMerger pathMerger, Translation tr) { if (ghRequest.getPoints().size() - 1 != pathList.size()) throw new RuntimeException("There should be exactly one more points than paths. points:" + ghRequest.getPoints().size() + ", paths:" + pathList.size()); altResponse.setWaypoints(getWaypoints()); ghResponse.add(altResponse); pathMerger.doWork(altResponse, pathList, tr); return true; }
@Override public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) { if (points.size() != 1 || ghRequest.getPoints().size() != 1) throw new IllegalArgumentException("For round trip calculation exactly one point is required"); final double distanceInMeter = ghRequest.getHints().getDouble(RoundTrip.DISTANCE, 10000); final long seed = ghRequest.getHints().getLong(RoundTrip.SEED, 0L); double initialHeading = ghRequest.getFavoredHeading(0); final int roundTripPointCount = Math.min(20, ghRequest.getHints().getInt(RoundTrip.POINTS, 2 + (int) (distanceInMeter / 50000))); final GHPoint start = points.get(0); TourStrategy strategy = new MultiPointTour(new Random(seed), distanceInMeter, roundTripPointCount, initialHeading); queryResults = new ArrayList<>(2 + strategy.getNumberOfGeneratedPoints()); EdgeFilter edgeFilter = DefaultEdgeFilter.allEdges(encoder); QueryResult startQR = locationIndex.findClosest(start.lat, start.lon, edgeFilter); if (!startQR.isValid()) throw new PointNotFoundException("Cannot find point 0: " + start, 0); queryResults.add(startQR); GHPoint last = start; for (int i = 0; i < strategy.getNumberOfGeneratedPoints(); i++) { double heading = strategy.getHeadingForIteration(i); QueryResult result = generateValidPoint(last, strategy.getDistanceForIteration(i), heading, edgeFilter); if (result == null) { ghResponse.addError(new IllegalStateException("Could not find a valid point after " + maxRetries + " tries, for the point:" + last)); return Collections.emptyList(); } last = result.getSnappedPoint(); queryResults.add(result); } queryResults.add(startQR); return queryResults; }
final double initialHeading = ghRequest.getHints().getDouble(RoundTrip.HEADING, Double.NaN); final int roundTripPointCount = Math.min(20, ghRequest.getHints().getInt(Algorithms.ROUND_TRIP + ".points", 2 + (int) (distanceInMeter / 50000))); final GHPoint start = ghRequest.getPoints().get(0);
@Override public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) { if (points.isEmpty()) throw new IllegalStateException("For round trip calculation one point is required"); final double distanceInMeter = ghRequest.getHints().getDouble(RoundTrip.DISTANCE, 10000); final long seed = ghRequest.getHints().getLong(RoundTrip.SEED, 0L); final double initialHeading = ghRequest.getHints().getDouble(RoundTrip.HEADING, Double.NaN); final int roundTripPointCount = Math.min(20, ghRequest.getHints().getInt(Algorithms.ROUND_TRIP + ".points", 2 + (int) (distanceInMeter / 50000))); final GHPoint start = ghRequest.getPoints().get(0); TourStrategy strategy = new MultiPointTour(new Random(seed), distanceInMeter, roundTripPointCount, initialHeading); queryResults = new ArrayList<>(2 + strategy.getNumberOfGeneratedPoints()); EdgeFilter edgeFilter = new DefaultEdgeFilter(encoder); QueryResult startQR = locationIndex.findClosest(start.lat, start.lon, edgeFilter); if (!startQR.isValid()) throw new PointNotFoundException("Cannot find point 0: " + start, 0); queryResults.add(startQR); GHPoint last = points.get(0); for (int i = 0; i < strategy.getNumberOfGeneratedPoints(); i++) { double heading = strategy.getHeadingForIteration(i); QueryResult result = generateValidPoint(last, strategy.getDistanceForIteration(i), heading, edgeFilter); if (result == null) { ghResponse.addError(new IllegalStateException("Could not find a valid point after " + maxRetries + " tries, for the point:" + last)); return Collections.emptyList(); } last = result.getSnappedPoint(); queryResults.add(result); } queryResults.add(startQR); return queryResults; }
int pointCounts = ghRequest.getPoints().size(); pathList = new ArrayList<>(pointCounts - 1); QueryResult fromQResult = queryResults.get(0);
long visitedNodesSum = 0L; boolean viaTurnPenalty = ghRequest.getHints().getBool(Routing.PASS_THROUGH, false); int pointCounts = ghRequest.getPoints().size(); pathList = new ArrayList<>(pointCounts - 1); QueryResult fromQResult = queryResults.get(0);
long visitedNodesSum = 0L; boolean viaTurnPenalty = ghRequest.getHints().getBool(Routing.PASS_THROUGH, false); int pointCounts = ghRequest.getPoints().size(); pathList = new ArrayList<>(pointCounts - 1); QueryResult fromQResult = queryResults.get(0);
!(lmFactoryDecorator.isEnabled() && !hints.getBool(Landmark.DISABLE, false)) ? DIJKSTRA_BI : ASTAR_BI; List<GHPoint> points = request.getPoints();
algoStr = chFactoryDecorator.isEnabled() && !disableCH ? DIJKSTRA_BI : ASTAR_BI; List<GHPoint> points = request.getPoints();
List<GHPoint> points = request.getPoints(); String algoStr = request.getAlgorithm().isEmpty() ? DIJKSTRA_BI : request.getAlgorithm();