use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class MiniGraphUI method main.
public static void main(String[] strs) {
PMap args = PMap.read(strs);
args.putObject("datareader.file", args.getString("datareader.file", "core/files/monaco.osm.gz"));
args.putObject("graph.location", args.getString("graph.location", "tools/target/mini-graph-ui-gh"));
args.putObject("graph.flag_encoders", args.getString("graph.flag_encoders", "car"));
GraphHopperConfig ghConfig = new GraphHopperConfig(args);
ghConfig.setProfiles(Arrays.asList(new Profile("profile").setVehicle("car").setWeighting("fastest")));
ghConfig.setCHProfiles(Arrays.asList(new CHProfile("profile")));
ghConfig.setLMProfiles(Arrays.asList(new LMProfile("profile")));
GraphHopper hopper = new GraphHopper().init(ghConfig).importOrLoad();
boolean debug = args.getBool("minigraphui.debug", false);
boolean useCH = args.getBool("minigraphui.useCH", false);
new MiniGraphUI(hopper, debug, useCH).visualize();
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class DefaultWeightingFactory method createWeighting.
@Override
public Weighting createWeighting(Profile profile, PMap requestHints, boolean disableTurnCosts) {
// Merge profile hints with request hints, the request hints take precedence.
// Note that so far we do not check if overwriting the profile hints actually works with the preparation
// for LM/CH. Later we should also limit the number of parameters that can be used to modify the profile.
// todo: since we are not dealing with block_area here yet we cannot really apply any merging rules
// for it, see discussion here: https://github.com/graphhopper/graphhopper/pull/1958#discussion_r395462901
PMap hints = new PMap();
hints.putAll(profile.getHints());
hints.putAll(requestHints);
FlagEncoder encoder = encodingManager.getEncoder(profile.getVehicle());
TurnCostProvider turnCostProvider;
if (profile.isTurnCosts() && !disableTurnCosts) {
if (!encoder.supportsTurnCosts())
throw new IllegalArgumentException("Encoder " + encoder + " does not support turn costs");
int uTurnCosts = hints.getInt(Parameters.Routing.U_TURN_COSTS, INFINITE_U_TURN_COSTS);
turnCostProvider = new DefaultTurnCostProvider(encoder, ghStorage.getTurnCostStorage(), uTurnCosts);
} else {
turnCostProvider = NO_TURN_COST_PROVIDER;
}
String weightingStr = toLowerCase(profile.getWeighting());
if (weightingStr.isEmpty())
throw new IllegalArgumentException("You have to specify a weighting");
Weighting weighting = null;
if (CustomWeighting.NAME.equalsIgnoreCase(weightingStr)) {
if (!(profile instanceof CustomProfile))
throw new IllegalArgumentException("custom weighting requires a CustomProfile but was profile=" + profile.getName());
CustomModel queryCustomModel = requestHints.getObject(CustomModel.KEY, null);
CustomProfile customProfile = (CustomProfile) profile;
if (queryCustomModel != null)
queryCustomModel.checkLMConstraints(customProfile.getCustomModel());
queryCustomModel = CustomModel.merge(customProfile.getCustomModel(), queryCustomModel);
weighting = CustomModelParser.createWeighting(encoder, encodingManager, turnCostProvider, queryCustomModel);
} else if ("shortest".equalsIgnoreCase(weightingStr)) {
weighting = new ShortestWeighting(encoder, turnCostProvider);
} else if ("fastest".equalsIgnoreCase(weightingStr)) {
if (encoder.supports(PriorityWeighting.class))
weighting = new PriorityWeighting(encoder, hints, turnCostProvider);
else
weighting = new FastestWeighting(encoder, hints, turnCostProvider);
} else if ("curvature".equalsIgnoreCase(weightingStr)) {
if (encoder.supports(CurvatureWeighting.class))
weighting = new CurvatureWeighting(encoder, hints, turnCostProvider);
} else if ("short_fastest".equalsIgnoreCase(weightingStr)) {
weighting = new ShortFastestWeighting(encoder, hints, turnCostProvider);
}
if (weighting == null)
throw new IllegalArgumentException("Weighting '" + weightingStr + "' not supported");
return weighting;
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class LowLevelAPIExample method useContractionHierarchiesToMakeQueriesFaster.
public static void useContractionHierarchiesToMakeQueriesFaster() {
// Creating and saving the graph
FlagEncoder encoder = new CarFlagEncoder();
EncodingManager em = EncodingManager.create(encoder);
Weighting weighting = new FastestWeighting(encoder);
CHConfig chConfig = CHConfig.nodeBased("my_profile", weighting);
GraphHopperStorage graph = new GraphBuilder(em).setRAM(graphLocation, true).create();
graph.flush();
// Set node coordinates and build location index
NodeAccess na = graph.getNodeAccess();
graph.edge(0, 1).set(encoder.getAccessEnc(), true).set(encoder.getAverageSpeedEnc(), 10).setDistance(1020);
na.setNode(0, 15.15, 20.20);
na.setNode(1, 15.25, 20.21);
// Prepare the graph for fast querying ...
graph.freeze();
PrepareContractionHierarchies pch = PrepareContractionHierarchies.fromGraphHopperStorage(graph, chConfig);
PrepareContractionHierarchies.Result pchRes = pch.doWork();
RoutingCHGraph chGraph = graph.createCHGraph(pchRes.getCHStorage(), pchRes.getCHConfig());
// create location index
LocationIndexTree index = new LocationIndexTree(graph, graph.getDirectory());
index.prepareIndex();
// calculate a path with location index
Snap fromSnap = index.findClosest(15.15, 20.20, EdgeFilter.ALL_EDGES);
Snap toSnap = index.findClosest(15.25, 20.21, EdgeFilter.ALL_EDGES);
QueryGraph queryGraph = QueryGraph.create(graph, fromSnap, toSnap);
BidirRoutingAlgorithm algo = new CHRoutingAlgorithmFactory(chGraph, queryGraph).createAlgo(new PMap());
Path path = algo.calcPath(fromSnap.getClosestNode(), toSnap.getClosestNode());
assert Helper.round(path.getDistance(), -2) == 1000;
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class EncodingManager method parseEncoderString.
static FlagEncoder parseEncoderString(FlagEncoderFactory factory, String encoderString) {
if (!encoderString.equals(toLowerCase(encoderString)))
throw new IllegalArgumentException("An upper case name for the FlagEncoder is not allowed: " + encoderString);
encoderString = encoderString.trim();
if (encoderString.isEmpty())
throw new IllegalArgumentException("FlagEncoder cannot be empty. " + encoderString);
String entryVal = "";
if (encoderString.contains("|")) {
entryVal = encoderString;
encoderString = encoderString.split("\\|")[0];
}
PMap configuration = new PMap(entryVal);
return factory.createFlagEncoder(encoderString, configuration);
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class EncodingManager method parseEncodedValueString.
static EncodedValue parseEncodedValueString(EncodedValueFactory factory, String encodedValueString) {
if (!encodedValueString.equals(toLowerCase(encodedValueString)))
throw new IllegalArgumentException("Use lower case for EncodedValues: " + encodedValueString);
encodedValueString = encodedValueString.trim();
if (encodedValueString.isEmpty())
throw new IllegalArgumentException("EncodedValue cannot be empty. " + encodedValueString);
EncodedValue evObject = factory.create(encodedValueString);
PMap map = new PMap(encodedValueString);
if (!map.has("version"))
throw new IllegalArgumentException("EncodedValue must have a version specified but it was " + encodedValueString);
return evObject;
}
Aggregations