@Test public void testRoadAttributeRestriction() { EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1); Weighting instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 4.0)); assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8); instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0)); assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8); }
@Override public boolean matches(HintsMap reqMap) { return getName().equals(reqMap.getWeighting()) && flagEncoder.toString().equals(reqMap.getVehicle()); }
/** * Specify car, bike or foot. Or specify empty to use default. */ public GHRequest setVehicle(String vehicle) { hints.setVehicle(vehicle); return this; }
private OkHttpClient getClientForRequest(GHRequest request) { OkHttpClient client = this.downloader; if (request.getHints().has(TIMEOUT)) { long timeout = request.getHints().getLong(TIMEOUT, DEFAULT_TIMEOUT); client = client.newBuilder() .connectTimeout(timeout, TimeUnit.MILLISECONDS) .readTimeout(timeout, TimeUnit.MILLISECONDS) .build(); } return client; }
@Override public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory defaultAlgoFactory, HintsMap map) { boolean disableCH = map.getBool(DISABLE, false); if (!isEnabled() || disablingAllowed && disableCH) return defaultAlgoFactory; if (preparations.isEmpty()) throw new IllegalStateException("No preparations added to this decorator"); if (map.getWeighting().isEmpty()) map.setWeighting(getDefaultWeighting()); String entriesStr = ""; for (PrepareContractionHierarchies p : preparations) { if (p.getWeighting().matches(map)) return p; entriesStr += p.getWeighting() + ", "; } throw new IllegalArgumentException("Cannot find CH RoutingAlgorithmFactory for weighting map " + map + " in entries " + entriesStr); }
HintsMap hints = new HintsMap(); for (Entry<String, String> entry : algoOptions.getHints().toMap().entrySet()) { hints.put(entry.getKey(), entry.getValue()); if (!hints.has(Parameters.CH.DISABLE)) { hints.put(Parameters.CH.DISABLE, true); String vehicle = hints.getVehicle(); if (vehicle.isEmpty()) { if (algoOptions.hasWeighting()) { vehicle = graphHopper.getEncodingManager().fetchEdgeEncoders().get(0).toString(); hints.setVehicle(vehicle);
addStr = "turn|"; FlagEncoder encoder = hopper.getEncodingManager().getEncoder(hints.getVehicle()); Weighting weighting = hopper.createWeighting(hints, encoder, hopper.getGraphHopperStorage()); HintsMap defaultHints = new HintsMap().put(Parameters.CH.DISABLE, true).put(Parameters.Landmark.DISABLE, true) .setVehicle(hints.getVehicle()).setWeighting(hints.getWeighting()); final HintsMap lmHints = new HintsMap(defaultHints).put(Parameters.Landmark.DISABLE, false); prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(astarbiOpts).hints(lmHints).build(), idx, "astarbi|landmarks|" + weighting) { @Override final HintsMap chHints = new HintsMap(defaultHints).put(Parameters.CH.DISABLE, false); Weighting pickedWeighting = null; for (Weighting tmpWeighting : hopper.getCHFactoryDecorator().getWeightings()) { throw new IllegalStateException("Didn't find weighting " + hints.getWeighting() + " in " + hopper.getCHFactoryDecorator().getWeightings()); AlgorithmOptions.start(dijkstrabiOpts).hints(chHints).build(), idx, "dijkstrabi|ch|prepare|" + hints.getWeighting()) { @Override public RoutingAlgorithmFactory createRoutingFactory() { AlgorithmOptions.start(astarbiOpts).hints(chHints).build(), idx, "astarbi|ch|prepare|" + hints.getWeighting()) { @Override public RoutingAlgorithmFactory createRoutingFactory() {
String tModeStr = hints.get("traversal_mode", traversalMode.toString()); TraversalMode tMode = TraversalMode.fromString(tModeStr); if (hints.has(Routing.EDGE_BASED)) tMode = hints.getBool(Routing.EDGE_BASED, false) ? TraversalMode.EDGE_BASED_2DIR : TraversalMode.NODE_BASED; boolean disableCH = hints.getBool(CH.DISABLE, false); if (!chFactoryDecorator.isDisablingAllowed() && disableCH) throw new IllegalArgumentException("Disabling CH not allowed on the server-side"); boolean disableLM = hints.getBool(Landmark.DISABLE, false); if (!lmFactoryDecorator.isDisablingAllowed() && disableLM) throw new IllegalArgumentException("Disabling LM not allowed on the server-side"); boolean forceCHHeading = hints.getBool(CH.FORCE_HEADING, false); if (!forceCHHeading && request.hasFavoredHeading(0)) throw new IllegalArgumentException("Heading is not (fully) supported for CHGraph. See issue #483"); int maxVisitedNodesForRequest = hints.getInt(Routing.MAX_VISITED_NODES, maxVisitedNodes); if (maxVisitedNodesForRequest > maxVisitedNodes) throw new IllegalArgumentException("The max_visited_nodes parameter has to be below or equal to:" + maxVisitedNodes); boolean tmpEnableInstructions = hints.getBool(Routing.INSTRUCTIONS, enableInstructions); boolean tmpCalcPoints = hints.getBool(Routing.CALC_POINTS, calcPoints); double wayPointMaxDistance = hints.getDouble(Routing.WAY_POINT_MAX_DISTANCE, 1d);
public FastestWeighting(FlagEncoder encoder) { this(encoder, new HintsMap(0)); }
this.na = graph.getNodeAccess(); encoder = hopper.getEncodingManager().getEncoder("car"); HintsMap map = new HintsMap("fastest"). setVehicle("car"); map.put(Parameters.Landmark.DISABLE, true); weighting = hopper.getCHFactoryDecorator().getWeightings().get(0); routingGraph = hopper.getGraphHopperStorage().getGraph(CHGraph.class, weighting); map.put(Parameters.CH.DISABLE, true);
static void initHints(HintsMap m, MultivaluedMap<String, String> parameterMap) { for (Map.Entry<String, List<String>> e : parameterMap.entrySet()) { if (e.getValue().size() == 1) { m.put(e.getKey(), e.getValue().get(0)); } else { // Do nothing. // TODO: this is dangerous: I can only silently swallow // the forbidden multiparameter. If I comment-in the line below, // I get an exception, because "point" regularly occurs // multiple times. // I think either unknown parameters (hints) should be allowed // to be multiparameters, too, or we shouldn't use them for // known parameters either, _or_ known parameters // must be filtered before they come to this code point, // _or_ we stop passing unknown parameters alltogether.. // // throw new WebApplicationException(String.format("This query parameter (hint) is not allowed to occur multiple times: %s", e.getKey())); } } }
String weightingStr = toLowerCase(hintsMap.getWeighting()); Weighting weighting = null; throw new IllegalArgumentException("weighting " + weightingStr + " not supported"); if (hintsMap.has(Routing.BLOCK_AREA)) { String blockAreaStr = hintsMap.get(Parameters.Routing.BLOCK_AREA, ""); GraphEdgeIdFinder.BlockArea blockArea = new GraphEdgeIdFinder(graph, locationIndex). parseBlockArea(blockAreaStr, DefaultEdgeFilter.allEdges(encoder), hintsMap.getDouble("block_area.edge_id_max_area", 1000 * 1000)); return new BlockAreaWeighting(weighting, blockArea);
Collection<AlgoHelperEntry> prepares = createAlgos(hopper, new HintsMap().setWeighting("shortest").setVehicle("car"), TraversalMode.NODE_BASED);
@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; }
String weighting = hintsMap.getWeighting().toLowerCase(); String blockedAreasFromRequest = hintsMap.get(Parameters.Routing.BLOCK_AREA, ""); if (!blockedAreasFromRequest.isEmpty()) val += ";" + blockedAreasFromRequest; hintsMap.put(Parameters.Routing.BLOCK_AREA, val);
/** * Convenient constructor if only one parameter is provided */ public HintsMap(String weighting) { super(5); setWeighting(weighting); }
@Override public List<Path> calcPaths(QueryGraph queryGraph, RoutingAlgorithmFactory algoFactory, AlgorithmOptions algoOpts) { boolean withViaTurnPenalty = ghRequest.getHints().getBool(Routing.PASS_THROUGH, false); if (withViaTurnPenalty) throw new IllegalArgumentException("Alternative paths and " + PASS_THROUGH + " at the same time is currently not supported"); return super.calcPaths(queryGraph, algoFactory, algoOpts); }
private Request createRequest(GHRequest request) { boolean tmpInstructions = request.getHints().getBool("instructions", instructions); boolean tmpCalcPoints = request.getHints().getBool("calc_points", calcPoints); String tmpOptimize = request.getHints().get("optimize", optimize); boolean tmpElevation = request.getHints().getBool("elevation", elevation); String type = request.getHints().get("type", "json"); for (Map.Entry<String, String> entry : request.getHints().toMap().entrySet()) { String urlKey = entry.getKey(); String urlValue = entry.getValue();
public String getVehicle() { return hints.getVehicle(); }
public String getWeighting() { return hints.getWeighting(); }