use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class RoutingExample method createGraphHopperInstance.
static GraphHopper createGraphHopperInstance(String ghLoc) {
GraphHopper hopper = new GraphHopper();
hopper.setOSMFile(ghLoc);
// specify where to store graphhopper files
hopper.setGraphHopperLocation("target/routing-graph-cache");
// see docs/core/profiles.md to learn more about profiles
hopper.setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(false));
// this enables speed mode for the profile we called car
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
// now this can take minutes if it imports or a few seconds for loading of course this is dependent on the area you import
hopper.importOrLoad();
return hopper;
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method beforeClass.
@BeforeAll
public static void beforeClass() {
// make sure we are using fresh files with correct vehicle
Helper.removeDir(new File(graphFolder));
hopper = new GraphHopper().setOSMFile(osmFile).setStoreOnFlush(true).setGraphHopperLocation(graphFolder).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting("fastest").setTurnCosts(false)).importOrLoad();
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class CHMeasurement method testPerformanceAutomaticNodeOrdering.
/**
* Parses a given osm file, contracts the graph and runs random routing queries on it. This is useful to test
* the node contraction heuristics with regards to the performance of the automatic graph contraction (the node
* contraction order determines how many and which shortcuts will be introduced) and the resulting query speed.
* The queries are compared with a normal AStar search for comparison and to ensure correctness.
*/
private static void testPerformanceAutomaticNodeOrdering(String[] args) {
// example args:
// map=berlin.pbf stats_file=stats.dat period_updates=0 lazy_updates=100 neighbor_updates=50 max_neighbor_updatse=3 contract_nodes=100 log_messages=20 edge_quotient_weight=100.0 orig_edge_quotient_weight=100.0 hierarchy_depth_weight=20.0 landmarks=0 cleanup=true turncosts=true threshold=0.1 seed=456 comp_iterations=10 perf_iterations=100 quick=false
long start = nanoTime();
PMap map = PMap.read(args);
GraphHopperConfig ghConfig = new GraphHopperConfig(map);
LOGGER.info("Running analysis with parameters {}", ghConfig);
String osmFile = ghConfig.getString("map", "map-matching/files/leipzig_germany.osm.pbf");
ghConfig.putObject("datareader.file", osmFile);
final String statsFile = ghConfig.getString("stats_file", null);
final int periodicUpdates = ghConfig.getInt("period_updates", 0);
final int lazyUpdates = ghConfig.getInt("lazy_updates", 100);
final int neighborUpdates = ghConfig.getInt("neighbor_updates", 50);
final int maxNeighborUpdates = ghConfig.getInt("max_neighbor_updates", 3);
final int contractedNodes = ghConfig.getInt("contract_nodes", 100);
final int logMessages = ghConfig.getInt("log_messages", 20);
final float edgeQuotientWeight = ghConfig.getFloat("edge_quotient_weight", 100.0f);
final float origEdgeQuotientWeight = ghConfig.getFloat("orig_edge_quotient_weight", 100.0f);
final float hierarchyDepthWeight = ghConfig.getFloat("hierarchy_depth_weight", 20.0f);
final int pollFactorHeuristic = ghConfig.getInt("poll_factor_heur", 5);
final int pollFactorContraction = ghConfig.getInt("poll_factor_contr", 200);
final int landmarks = ghConfig.getInt("landmarks", 0);
final boolean cleanup = ghConfig.getBool("cleanup", true);
final boolean withTurnCosts = ghConfig.getBool("turncosts", true);
final int uTurnCosts = ghConfig.getInt(Parameters.Routing.U_TURN_COSTS, 80);
final double errorThreshold = ghConfig.getDouble("threshold", 0.1);
final long seed = ghConfig.getLong("seed", 456);
final int compIterations = ghConfig.getInt("comp_iterations", 100);
final int perfIterations = ghConfig.getInt("perf_iterations", 1000);
final boolean quick = ghConfig.getBool("quick", false);
final GraphHopper graphHopper = new GraphHopper();
String profile = "car_profile";
if (withTurnCosts) {
ghConfig.putObject("graph.flag_encoders", "car|turn_costs=true");
ghConfig.setProfiles(Collections.singletonList(new Profile(profile).setVehicle("car").setWeighting("fastest").setTurnCosts(true).putHint(Parameters.Routing.U_TURN_COSTS, uTurnCosts)));
ghConfig.setCHProfiles(Collections.singletonList(new CHProfile(profile)));
if (landmarks > 0) {
ghConfig.setLMProfiles(Collections.singletonList(new LMProfile(profile)));
ghConfig.putObject("prepare.lm.landmarks", landmarks);
}
} else {
ghConfig.putObject("graph.flag_encoders", "car");
ghConfig.setProfiles(Collections.singletonList(new Profile(profile).setVehicle("car").setWeighting("fastest").setTurnCosts(false)));
}
ghConfig.putObject(PERIODIC_UPDATES, periodicUpdates);
ghConfig.putObject(LAST_LAZY_NODES_UPDATES, lazyUpdates);
ghConfig.putObject(NEIGHBOR_UPDATES, neighborUpdates);
ghConfig.putObject(NEIGHBOR_UPDATES_MAX, maxNeighborUpdates);
ghConfig.putObject(CONTRACTED_NODES, contractedNodes);
ghConfig.putObject(LOG_MESSAGES, logMessages);
if (withTurnCosts) {
ghConfig.putObject(EDGE_QUOTIENT_WEIGHT, edgeQuotientWeight);
ghConfig.putObject(ORIGINAL_EDGE_QUOTIENT_WEIGHT, origEdgeQuotientWeight);
ghConfig.putObject(HIERARCHY_DEPTH_WEIGHT, hierarchyDepthWeight);
ghConfig.putObject(MAX_POLL_FACTOR_HEURISTIC_EDGE, pollFactorHeuristic);
ghConfig.putObject(MAX_POLL_FACTOR_CONTRACTION_EDGE, pollFactorContraction);
} else {
ghConfig.putObject(MAX_POLL_FACTOR_HEURISTIC_NODE, pollFactorHeuristic);
ghConfig.putObject(MAX_POLL_FACTOR_CONTRACTION_NODE, pollFactorContraction);
}
LOGGER.info("Initializing graph hopper with args: {}", ghConfig);
graphHopper.init(ghConfig);
if (cleanup) {
graphHopper.clean();
}
PMap results = new PMap(ghConfig.asPMap());
StopWatch sw = new StopWatch();
sw.start();
graphHopper.importOrLoad();
sw.stop();
results.putObject("_prepare_time", sw.getSeconds());
LOGGER.info("Import and preparation took {}s", sw.getMillis() / 1000);
if (!quick) {
runCompareTest(DIJKSTRA_BI, graphHopper, withTurnCosts, uTurnCosts, seed, compIterations, errorThreshold, results);
runCompareTest(ASTAR_BI, graphHopper, withTurnCosts, uTurnCosts, seed, compIterations, errorThreshold, results);
}
if (!quick) {
runPerformanceTest(DIJKSTRA_BI, graphHopper, withTurnCosts, seed, perfIterations, results);
}
runPerformanceTest(ASTAR_BI, graphHopper, withTurnCosts, seed, perfIterations, results);
if (!quick && landmarks > 0) {
runPerformanceTest("lm", graphHopper, withTurnCosts, seed, perfIterations, results);
}
graphHopper.close();
Map<String, Object> resultMap = results.toMap();
TreeSet<String> sortedKeys = new TreeSet<>(resultMap.keySet());
for (String key : sortedKeys) {
LOGGER.info(key + "=" + resultMap.get(key));
}
if (statsFile != null) {
File f = new File(statsFile);
boolean writeHeader = !f.exists();
try (OutputStream os = new FileOutputStream(f, true);
Writer writer = new OutputStreamWriter(os, StandardCharsets.UTF_8)) {
if (writeHeader)
writer.write(getHeader(sortedKeys));
writer.write(getStatLine(sortedKeys, resultMap));
} catch (IOException e) {
LOGGER.error("Could not write summary to file '{}'", statsFile, e);
}
}
// output to be used by external caller
StringBuilder sb = new StringBuilder();
for (String key : sortedKeys) {
sb.append(key).append(":").append(resultMap.get(key)).append(";");
}
sb.deleteCharAt(sb.lastIndexOf(";"));
System.out.println(sb);
LOGGER.info("Total time: {}s", fmt((nanoTime() - start) * 1.e-9));
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperMultimodalIT method init.
@BeforeAll
public static void init() {
GraphHopperConfig ghConfig = new GraphHopperConfig();
ghConfig.putObject("datareader.file", "files/beatty.osm");
ghConfig.putObject("gtfs.file", "files/sample-feed");
ghConfig.putObject("graph.location", GRAPH_LOC);
ghConfig.setProfiles(Arrays.asList(new Profile("foot").setVehicle("foot").setWeighting("fastest"), new Profile("car").setVehicle("car").setWeighting("fastest")));
Helper.removeDir(new File(GRAPH_LOC));
graphHopperGtfs = new GraphHopperGtfs(ghConfig);
graphHopperGtfs.init(ghConfig);
graphHopperGtfs.importOrLoad();
locationIndex = graphHopperGtfs.getLocationIndex();
graphHopper = new PtRouterImpl.Factory(ghConfig, new TranslationMap().doImport(), graphHopperGtfs.getGraphHopperStorage(), locationIndex, graphHopperGtfs.getGtfsStorage()).createWithoutRealtimeFeed();
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class CHImportTest method main.
public static void main(String[] args) {
System.out.println("running for args: " + Arrays.toString(args));
PMap map = PMap.read(args);
String vehicle = map.getString("vehicle", "car");
GraphHopperConfig config = new GraphHopperConfig(map);
config.putObject("datareader.file", map.getString("pbf", "map-matching/files/leipzig_germany.osm.pbf"));
config.putObject("graph.location", map.getString("gh", "ch-import-test-gh"));
config.setProfiles(Arrays.asList(new Profile(vehicle).setVehicle(vehicle).setWeighting("fastest")));
config.setCHProfiles(Collections.singletonList(new CHProfile(vehicle)));
config.putObject(CHParameters.PERIODIC_UPDATES, map.getInt("periodic", 0));
config.putObject(CHParameters.LAST_LAZY_NODES_UPDATES, map.getInt("lazy", 100));
config.putObject(CHParameters.NEIGHBOR_UPDATES, map.getInt("neighbor", 100));
config.putObject(CHParameters.NEIGHBOR_UPDATES_MAX, map.getInt("neighbor_max", 2));
config.putObject(CHParameters.CONTRACTED_NODES, map.getInt("contracted", 100));
config.putObject(CHParameters.LOG_MESSAGES, map.getInt("logs", 20));
config.putObject(CHParameters.EDGE_DIFFERENCE_WEIGHT, map.getDouble("edge_diff", 10));
config.putObject(CHParameters.ORIGINAL_EDGE_COUNT_WEIGHT, map.getDouble("orig_edge", 1));
config.putObject(CHParameters.MAX_POLL_FACTOR_HEURISTIC_NODE, map.getDouble("mpf_heur", 5));
config.putObject(CHParameters.MAX_POLL_FACTOR_CONTRACTION_NODE, map.getDouble("mpf_contr", 200));
GraphHopper hopper = new GraphHopper();
hopper.init(config);
if (map.getBool("use_country_rules", false))
// note that using this requires a new import of the base graph!
hopper.setCountryRuleFactory(new CountryRuleFactory());
hopper.importOrLoad();
runQueries(hopper, vehicle);
}
Aggregations