Search in sources :

Example 1 with RoutingCHGraph

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
}
Also used : PMap(com.graphhopper.util.PMap) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 2 with RoutingCHGraph

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();
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Example 3 with RoutingCHGraph

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);
    }
}
Also used : RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) Arrays(java.util.Arrays) GraphHopperConfig(com.graphhopper.GraphHopperConfig) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) com.graphhopper.routing(com.graphhopper.routing) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) StopWatch(com.graphhopper.util.StopWatch) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) MouseWheelEvent(java.awt.event.MouseWheelEvent) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) Profile(com.graphhopper.config.Profile) MouseAdapter(java.awt.event.MouseAdapter) Graph(com.graphhopper.storage.Graph) GraphHopper(com.graphhopper.GraphHopper) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Logger(org.slf4j.Logger) BBox(com.graphhopper.util.shapes.BBox) PMap(com.graphhopper.util.PMap) Algorithms(com.graphhopper.util.Parameters.Algorithms) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) CHProfile(com.graphhopper.config.CHProfile) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) PointList(com.graphhopper.util.PointList) MouseEvent(java.awt.event.MouseEvent) GHBitSet(com.graphhopper.coll.GHBitSet) java.awt(java.awt) GHTBitSet(com.graphhopper.coll.GHTBitSet) NodeAccess(com.graphhopper.storage.NodeAccess) MouseWheelListener(java.awt.event.MouseWheelListener) Snap(com.graphhopper.storage.index.Snap) FetchMode(com.graphhopper.util.FetchMode) LMProfile(com.graphhopper.config.LMProfile) AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) javax.swing(javax.swing) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph)

Example 4 with RoutingCHGraph

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;
}
Also used : RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) java.util(java.util) Logger(org.slf4j.Logger) GraphHopperConfig(com.graphhopper.GraphHopperConfig) Helper.createFormatter(com.graphhopper.util.Helper.createFormatter) PMap(com.graphhopper.util.PMap) LoggerFactory(org.slf4j.LoggerFactory) CHConfig(com.graphhopper.storage.CHConfig) CHStorage(com.graphhopper.storage.CHStorage) Callable(java.util.concurrent.Callable) GHUtility(com.graphhopper.util.GHUtility) CHProfile(com.graphhopper.config.CHProfile) Collectors(java.util.stream.Collectors) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Helper.getMemInfo(com.graphhopper.util.Helper.getMemInfo) CH(com.graphhopper.util.Parameters.CH) CHStorage(com.graphhopper.storage.CHStorage) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) Callable(java.util.concurrent.Callable)

Example 5 with RoutingCHGraph

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
}
Also used : PMap(com.graphhopper.util.PMap) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Aggregations

RoutingCHGraph (com.graphhopper.storage.RoutingCHGraph)5 PMap (com.graphhopper.util.PMap)4 CHProfile (com.graphhopper.config.CHProfile)3 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)3 Test (org.junit.jupiter.api.Test)3 GraphHopperConfig (com.graphhopper.GraphHopperConfig)2 LMProfile (com.graphhopper.config.LMProfile)2 Profile (com.graphhopper.config.Profile)2 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)1 GraphHopper (com.graphhopper.GraphHopper)1 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHTBitSet (com.graphhopper.coll.GHTBitSet)1 com.graphhopper.routing (com.graphhopper.routing)1 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)1 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)1 LMRoutingAlgorithmFactory (com.graphhopper.routing.lm.LMRoutingAlgorithmFactory)1 LandmarkStorage (com.graphhopper.routing.lm.LandmarkStorage)1 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)1 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)1 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)1