Search in sources :

Example 1 with CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopper method loadOrPrepareCH.

protected void loadOrPrepareCH(boolean closeEarly) {
    for (CHProfile profile : chPreparationHandler.getCHProfiles()) if (!getCHProfileVersion(profile.getProfile()).isEmpty() && !getCHProfileVersion(profile.getProfile()).equals("" + profilesByName.get(profile.getProfile()).getVersion()))
        throw new IllegalArgumentException("CH preparation of " + profile.getProfile() + " already exists in storage and doesn't match configuration");
    // we load ch graphs that already exist and prepare the other ones
    List<CHConfig> chConfigs = createCHConfigs(chPreparationHandler.getCHProfiles());
    Map<String, RoutingCHGraph> loaded = chPreparationHandler.load(ghStorage, chConfigs);
    List<CHConfig> configsToPrepare = chConfigs.stream().filter(c -> !loaded.containsKey(c.getName())).collect(Collectors.toList());
    Map<String, PrepareContractionHierarchies.Result> prepared = prepareCH(closeEarly, configsToPrepare);
    // we map all profile names for which there is CH support to the according CH graphs
    chGraphs = new LinkedHashMap<>();
    for (CHProfile profile : chPreparationHandler.getCHProfiles()) {
        if (loaded.containsKey(profile.getProfile()) && prepared.containsKey(profile.getProfile()))
            throw new IllegalStateException("CH graph should be either loaded or prepared, but not both: " + profile.getProfile());
        else if (prepared.containsKey(profile.getProfile())) {
            setCHProfileVersion(profile.getProfile(), profilesByName.get(profile.getProfile()).getVersion());
            PrepareContractionHierarchies.Result res = prepared.get(profile.getProfile());
            chGraphs.put(profile.getProfile(), ghStorage.createCHGraph(res.getCHStorage(), res.getCHConfig()));
        } else if (loaded.containsKey(profile.getProfile())) {
            chGraphs.put(profile.getProfile(), loaded.get(profile.getProfile()));
        } else
            throw new IllegalStateException("CH graph should be either loaded or prepared: " + profile.getProfile());
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) com.graphhopper.routing.ev(com.graphhopper.routing.ev) RoundTrip(com.graphhopper.util.Parameters.Algorithms.RoundTrip) com.graphhopper.routing(com.graphhopper.routing) LoggerFactory(org.slf4j.LoggerFactory) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) DirectoryStream(java.nio.file.DirectoryStream) JtsModule(com.bedatadriven.jackson.datatype.jts.JtsModule) LMConfig(com.graphhopper.routing.lm.LMConfig) Path(java.nio.file.Path) DateFormat(java.text.DateFormat) DefaultTagParserFactory(com.graphhopper.routing.util.parsers.DefaultTagParserFactory) PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) Landmark(com.graphhopper.util.Parameters.Landmark) Helper(com.graphhopper.util.Helper) PrepareRoutingSubnetworks(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) com.graphhopper.reader.dem(com.graphhopper.reader.dem) UncheckedIOException(java.io.UncheckedIOException) GHUtility.readCountries(com.graphhopper.util.GHUtility.readCountries) com.graphhopper.routing.util(com.graphhopper.routing.util) LMProfile(com.graphhopper.config.LMProfile) java.util(java.util) CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Routing(com.graphhopper.util.Parameters.Routing) PrepareJob(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepareJob) CHPreparationHandler(com.graphhopper.routing.ch.CHPreparationHandler) Profile(com.graphhopper.config.Profile) OSMReader(com.graphhopper.reader.osm.OSMReader) com.graphhopper.storage(com.graphhopper.storage) DateRangeParser(com.graphhopper.reader.osm.conditional.DateRangeParser) com.graphhopper.util(com.graphhopper.util) Logger(org.slf4j.Logger) LocationIndex(com.graphhopper.storage.index.LocationIndex) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) CHProfile(com.graphhopper.config.CHProfile) File(java.io.File) TagParserFactory(com.graphhopper.routing.util.parsers.TagParserFactory) LMPreparationHandler(com.graphhopper.routing.lm.LMPreparationHandler) Paths(java.nio.file.Paths) PrepareLandmarks(com.graphhopper.routing.lm.PrepareLandmarks) Weighting(com.graphhopper.routing.weighting.Weighting) CustomWeighting(com.graphhopper.routing.weighting.custom.CustomWeighting) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) BufferedReader(java.io.BufferedReader)

Example 2 with CHProfile

use of com.graphhopper.config.CHProfile 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 CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testLoadingLMAndCHProfiles.

@Test
public void testLoadingLMAndCHProfiles() {
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(ghLoc).setOSMFile(testOsm).setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
    hopper.importOrLoad();
    hopper.close();
    // load without problem
    hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
    hopper.setGraphHopperLocation(ghLoc);
    assertTrue(hopper.load());
    hopper.close();
    // problem: changed weighting in profile although LM preparation was enabled
    hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
    hopper.setGraphHopperLocation(ghLoc);
    // do not load CH
    try {
        assertFalse(hopper.load());
        fail("load should fail");
    } catch (Exception ex) {
        assertEquals("LM preparation of car already exists in storage and doesn't match configuration", ex.getMessage());
    } finally {
        hopper.close();
    }
    // problem: changed weighting in profile although CH preparation was enabled
    hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
    hopper.setGraphHopperLocation(ghLoc);
    // do not load LM
    try {
        assertFalse(hopper.load());
        fail("load should fail");
    } catch (Exception ex) {
        assertEquals("CH preparation of car already exists in storage and doesn't match configuration", ex.getMessage());
    } finally {
        hopper.close();
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) 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 4 with CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testPrepare.

@Test
public void testPrepare() {
    final String profile = "profile";
    final String vehicle = "car";
    final String weighting = "shortest";
    instance = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
    instance.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    instance.importOrLoad();
    GHResponse rsp = instance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile).setAlgorithm(DIJKSTRA_BI));
    assertFalse(rsp.hasErrors());
    assertEquals(Helper.createPointList(51.249215, 9.431716, 52.0, 9.0, 51.2, 9.4), rsp.getBest().getPoints());
    assertEquals(3, rsp.getBest().getPoints().size());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) 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 5 with CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testFootOnly.

@Test
public void testFootOnly() {
    // now only footable ways are imported => no A D C and B D E => the other both ways have pillar nodes!
    final String profile = "foot_profile";
    final String vehicle = "foot";
    final String weighting = "fastest";
    instance = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm3);
    instance.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    instance.importOrLoad();
    ((LocationIndexTree) instance.getLocationIndex()).setMaxRegionSearch(300);
    assertEquals(2, instance.getGraphHopperStorage().getNodes());
    assertEquals(2, instance.getGraphHopperStorage().getAllEdges().length());
    // A to E only for foot
    GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.19, 52).setProfile(profile));
    assertFalse(grsp.hasErrors());
    ResponsePath rsp = grsp.getBest();
    // the last points snaps to the edge
    assertEquals(Helper.createPointList(11.1, 50, 10, 51, 11.194015, 51.995013), rsp.getPoints());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Test(org.junit.jupiter.api.Test)

Aggregations

CHProfile (com.graphhopper.config.CHProfile)66 Profile (com.graphhopper.config.Profile)63 LMProfile (com.graphhopper.config.LMProfile)58 Test (org.junit.jupiter.api.Test)39 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 PMap (com.graphhopper.util.PMap)10 GHPoint (com.graphhopper.util.shapes.GHPoint)9 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)8 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)8 GraphHopper (com.graphhopper.GraphHopper)6 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 CountryRuleFactory (com.graphhopper.routing.util.countryrules.CountryRuleFactory)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 JtsModule (com.bedatadriven.jackson.datatype.jts.JtsModule)1 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1