use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class ProfileResolverTest method missingProfiles.
@Test
public void missingProfiles() {
ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("car,bike"), Arrays.asList(new Profile("fast_bike").setVehicle("bike").setWeighting("fastest"), new Profile("short_bike").setVehicle("bike").setWeighting("shortest")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
// there is a car encoder but no associated profile
assertProfileNotFound(profileResolver, new PMap().putObject("vehicle", "car"));
// if we do not specify a vehicle or weighting we even have multiple matches
assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
// if we specify the weighting its clear which profile we want
assertEquals("short_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "shortest")).getName());
// setting the vehicle to bike is not enough
assertMultiMatchError(profileResolver, new PMap().putObject("vehicle", "bike"), "There are multiple profiles matching your request");
// if we set the weighting as well it works
assertEquals("fast_bike", profileResolver.resolveProfile(new PMap().putObject("vehicle", "bike").putObject("weighting", "fastest")).getName());
assertEquals("short_bike", profileResolver.resolveProfile(new PMap().putObject("vehicle", "bike").putObject("weighting", "shortest")).getName());
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class ProfileResolverTest method defaultVehicleAllAlgos.
@Test
public void defaultVehicleAllAlgos() {
final String profile1 = "foot_profile";
final String profile2 = "car_profile";
final String vehicle1 = "foot";
final String vehicle2 = "car";
final String weighting = "shortest";
ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create(vehicle1 + "," + vehicle2), Arrays.asList(new Profile(profile1).setVehicle(vehicle1).setWeighting(weighting), new Profile(profile2).setVehicle(vehicle2).setWeighting(weighting)), Arrays.asList(new CHProfile(profile1), new CHProfile(profile2)), Arrays.asList(new LMProfile(profile1), new LMProfile(profile2)));
// when we do not specify vehicle/weighting, we get an error because there are multiple matches
PMap hints = new PMap();
assertMultiMatchError(profileResolver, hints, "There are multiple CH profiles matching your request");
assertMultiMatchError(profileResolver, hints.putObject(Parameters.CH.DISABLE, true), "There are multiple LM profiles matching your request");
assertMultiMatchError(profileResolver, hints.putObject(Parameters.Landmark.DISABLE, true), "There are multiple profiles matching your request");
// using the weighting is not enough, because its the same for both profiles
hints = new PMap().putObject("weighting", "shortest");
assertMultiMatchError(profileResolver, hints, "There are multiple CH profiles matching your request");
assertMultiMatchError(profileResolver, hints.putObject(Parameters.CH.DISABLE, true), "There are multiple LM profiles matching your request");
assertMultiMatchError(profileResolver, hints.putObject(Parameters.Landmark.DISABLE, true), "There are multiple profiles matching your request");
// using the vehicle to select one of the profiles works
hints = new PMap().putObject("vehicle", vehicle1);
assertEquals(profile1, profileResolver.resolveProfile(hints).getName());
assertEquals(profile1, profileResolver.resolveProfile(hints.putObject(Parameters.CH.DISABLE, true)).getName());
assertEquals(profile1, profileResolver.resolveProfile(hints.putObject(Parameters.Landmark.DISABLE, true)).getName());
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class LMPreparationHandlerTest method testEnabled.
@Test
public void testEnabled() {
LMPreparationHandler instance = new LMPreparationHandler();
assertFalse(instance.isEnabled());
instance.setLMProfiles(new LMProfile("myconfig"));
assertTrue(instance.isEnabled());
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class LMPreparationHandlerTest method testPrepareWeightingNo.
@Test
public void testPrepareWeightingNo() {
GraphHopperConfig ghConfig = new GraphHopperConfig();
ghConfig.setProfiles(Collections.singletonList(new Profile("profile")));
ghConfig.setLMProfiles(Collections.singletonList(new LMProfile("profile")));
LMPreparationHandler handler = new LMPreparationHandler();
handler.init(ghConfig);
assertTrue(handler.isEnabled());
// See #1076
ghConfig.setLMProfiles(Collections.emptyList());
handler = new LMPreparationHandler();
handler.init(ghConfig);
assertFalse(handler.isEnabled());
}
use of com.graphhopper.config.LMProfile 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));
}
Aggregations