use of com.graphhopper.storage.RoutingCHGraph in project graphhopper by graphhopper.
the class AlternativeRouteCHTest method testRelaxMaximumStretch.
@Test
public void testRelaxMaximumStretch() {
GraphHopperStorage g = createTestGraph(em);
PMap hints = new PMap();
hints.putObject("alternative_route.max_weight_factor", 4);
hints.putObject("alternative_route.local_optimality_factor", 0.5);
hints.putObject("alternative_route.max_paths", 4);
RoutingCHGraph routingCHGraph = prepareCH(g);
AlternativeRouteCH altDijkstra = new AlternativeRouteCH(routingCHGraph, hints);
List<AlternativeRouteCH.AlternativeInfo> pathInfos = altDijkstra.calcAlternatives(5, 10);
assertEquals(4, pathInfos.size());
// 4 -> 11 -> 12 is shorter than 4 -> 10 -> 12 (11 is an admissible via node), AND
// 4 -> 11 -> 12 -> 10 is not too long compared to 4 -> 10
}
use of com.graphhopper.storage.RoutingCHGraph in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testMultipleCHPreparationsInParallel.
@Test
public void testMultipleCHPreparationsInParallel() {
HashMap<String, Integer> shortcutCountMap = new HashMap<>();
// try all parallelization modes
for (int threadCount = 1; threadCount < 6; threadCount++) {
GraphHopper hopper = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile("car_profile").setVehicle("car").setWeighting("fastest"), new Profile("moto_profile").setVehicle("motorcycle").setWeighting("fastest"), new Profile("mtb_profile").setVehicle("mtb").setWeighting("fastest"), new Profile("bike_profile").setVehicle("racingbike").setWeighting("fastest"), new Profile("foot_profile").setVehicle("foot").setWeighting("fastest")).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car_profile"), new CHProfile("moto_profile"), new CHProfile("mtb_profile"), new CHProfile("bike_profile"), new CHProfile("foot_profile")).setPreparationThreads(threadCount);
hopper.importOrLoad();
assertEquals(5, hopper.getCHGraphs().size());
for (Map.Entry<String, RoutingCHGraph> chGraph : hopper.getCHGraphs().entrySet()) {
String name = chGraph.getKey();
Integer shortcutCount = shortcutCountMap.get(name);
if (shortcutCount == null)
shortcutCountMap.put(name, chGraph.getValue().getShortcuts());
else
assertEquals((long) shortcutCount, chGraph.getValue().getShortcuts());
String keyError = Parameters.CH.PREPARE + "error." + name;
String valueError = hopper.getGraphHopperStorage().getProperties().get(keyError);
assertTrue(valueError.isEmpty(), "Properties for " + name + " should NOT contain error " + valueError + " [" + threadCount + "]");
String key = Parameters.CH.PREPARE + "date." + name;
String value = hopper.getGraphHopperStorage().getProperties().get(key);
assertFalse(value.isEmpty(), "Properties for " + name + " did NOT contain finish date [" + threadCount + "]");
}
hopper.close();
}
}
use of com.graphhopper.storage.RoutingCHGraph in project graphhopper by graphhopper.
the class MiniGraphUI method createAlgo.
private RoutingAlgorithm createAlgo(GraphHopper hopper) {
Profile profile = hopper.getProfiles().iterator().next();
if (useCH) {
RoutingCHGraph chGraph = hopper.getCHGraphs().get(profile.getName());
logger.info("CH algo, profile: " + profile.getName());
QueryGraph qGraph = QueryGraph.create(hopper.getGraphHopperStorage(), fromRes, toRes);
QueryRoutingCHGraph queryRoutingCHGraph = new QueryRoutingCHGraph(chGraph, qGraph);
return new CHDebugAlgo(queryRoutingCHGraph, mg);
} else {
LandmarkStorage landmarks = hopper.getLandmarks().get(profile.getName());
RoutingAlgorithmFactory algoFactory = (g, w, opts) -> {
RoutingAlgorithm algo = new LMRoutingAlgorithmFactory(landmarks).createAlgo(g, w, opts);
if (algo instanceof AStarBidirection) {
return new DebugAStarBi(g, w, opts.getTraversalMode(), mg).setApproximation(((AStarBidirection) algo).getApproximation());
} else if (algo instanceof AStar) {
return new DebugAStar(g, w, opts.getTraversalMode(), mg);
} else if (algo instanceof DijkstraBidirectionRef) {
return new DebugDijkstraBidirection(g, w, opts.getTraversalMode(), mg);
} else if (algo instanceof Dijkstra) {
return new DebugDijkstraSimple(g, w, opts.getTraversalMode(), mg);
}
return algo;
};
AlgorithmOptions algoOpts = new AlgorithmOptions().setAlgorithm(Algorithms.ASTAR_BI);
logger.info("algoOpts:" + algoOpts + ", weighting: " + landmarks.getWeighting() + ", profile: " + profile.getName());
QueryGraph qGraph = QueryGraph.create(graph, fromRes, toRes);
return algoFactory.createAlgo(qGraph, landmarks.getWeighting(), algoOpts);
}
}
use of com.graphhopper.storage.RoutingCHGraph in project graphhopper by graphhopper.
the class CHPreparationHandler method load.
public Map<String, RoutingCHGraph> load(GraphHopperStorage ghStorage, List<CHConfig> chConfigs) {
Map<String, RoutingCHGraph> loaded = Collections.synchronizedMap(new LinkedHashMap<>());
List<Callable<String>> callables = chConfigs.stream().map(c -> (Callable<String>) () -> {
CHStorage chStorage = ghStorage.loadCHStorage(c.getName(), c.isEdgeBased());
if (chStorage != null)
loaded.put(c.getName(), ghStorage.createCHGraph(chStorage, c));
else {
// todo: this is ugly, see comments in LMPreparationHandler
ghStorage.getDirectory().remove("nodes_ch_" + c.getName());
ghStorage.getDirectory().remove("shortcuts_" + c.getName());
}
return c.getName();
}).collect(Collectors.toList());
GHUtility.runConcurrently(callables, preparationThreads);
return loaded;
}
use of com.graphhopper.storage.RoutingCHGraph in project graphhopper by graphhopper.
the class AlternativeRouteCHTest method testCalcAlternatives.
@Test
public void testCalcAlternatives() {
GraphHopperStorage g = createTestGraph(em);
PMap hints = new PMap();
hints.putObject("alternative_route.max_weight_factor", 2.3);
hints.putObject("alternative_route.local_optimality_factor", 0.5);
hints.putObject("alternative_route.max_paths", 4);
RoutingCHGraph routingCHGraph = prepareCH(g);
AlternativeRouteCH altDijkstra = new AlternativeRouteCH(routingCHGraph, hints);
List<AlternativeRouteCH.AlternativeInfo> pathInfos = altDijkstra.calcAlternatives(5, 10);
assertEquals(3, pathInfos.size());
// 4 -> 11 -> 12 is shorter than 4 -> 10 -> 12 (11 is an admissible via node), BUT
// 4 -> 11 -> 12 -> 10 is too long compared to 4 -> 10
}
Aggregations