Search in sources :

Example 36 with CHProfile

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

the class GraphHopperOSMTest method testLoadingWithDifferentCHConfig_issue471_pr1488.

@Test
public void testLoadingWithDifferentCHConfig_issue471_pr1488() {
    // when there is a single CH profile we can also load GraphHopper without it
    // in #471 this was forbidden, but later it was allowed again, see #1488
    final String profile = "profile";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper gh = new GraphHopper().setStoreOnFlush(true).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
    gh.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    gh.importOrLoad();
    GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().size());
    gh.close();
    // now load GH without CH profile
    gh = new GraphHopper().setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).setGraphHopperLocation(ghLoc);
    gh.load();
    // no error
    Helper.removeDir(new File(ghLoc));
    // when there is no CH preparation yet it will be added (CH delta import)
    gh = new GraphHopper().setStoreOnFlush(true).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
    gh.importOrLoad();
    rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().size());
    gh.close();
    gh = new GraphHopper().setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
    gh.getCHPreparationHandler().setCHProfiles(new CHProfile("profile"));
    gh.setGraphHopperLocation(ghLoc);
    gh.importOrLoad();
    rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().size());
// no error
}
Also used : CHProfile(com.graphhopper.config.CHProfile) File(java.io.File) 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 37 with CHProfile

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

the class GraphHopperOSMTest method testVia.

@Test
public void testVia() {
    final String profile = "profile";
    final String vehicle = "car";
    final String weighting = "fastest";
    instance = new GraphHopper().setStoreOnFlush(true).init(new GraphHopperConfig().putObject("datareader.file", testOsm3).putObject("prepare.min_network_size", 0).putObject("graph.flag_encoders", vehicle).setProfiles(Collections.singletonList(new Profile(profile).setVehicle(vehicle).setWeighting(weighting))).setCHProfiles(Collections.singletonList(new CHProfile(profile)))).setGraphHopperLocation(ghLoc);
    instance.importOrLoad();
    // A -> B -> C
    GHPoint first = new GHPoint(11.1, 50);
    GHPoint second = new GHPoint(12, 51);
    GHPoint third = new GHPoint(11.2, 51.9);
    GHResponse rsp12 = instance.route(new GHRequest(first, second).setProfile(profile));
    assertFalse(rsp12.hasErrors(), "should find 1->2");
    assertEquals(147930.5, rsp12.getBest().getDistance(), .1);
    GHResponse rsp23 = instance.route(new GHRequest(second, third).setProfile(profile));
    assertFalse(rsp23.hasErrors(), "should find 2->3");
    assertEquals(176608.9, rsp23.getBest().getDistance(), .1);
    GHResponse grsp = instance.route(new GHRequest(Arrays.asList(first, second, third)).setProfile(profile));
    assertFalse(grsp.hasErrors(), "should find 1->2->3");
    ResponsePath rsp = grsp.getBest();
    assertEquals(rsp12.getBest().getDistance() + rsp23.getBest().getDistance(), rsp.getDistance(), 1e-6);
    assertEquals(4, rsp.getPoints().size());
    assertEquals(5, rsp.getInstructions().size());
    assertEquals(Instruction.REACHED_VIA, rsp.getInstructions().get(1).getSign());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) 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 38 with CHProfile

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

the class GraphHopperOSMTest method testGetMultipleWeightingsForCH.

@Test
public void testGetMultipleWeightingsForCH() {
    GraphHopper hopper = new GraphHopper().setProfiles(new Profile("profile1").setVehicle("car").setWeighting("fastest"), new Profile("profile2").setVehicle("car").setWeighting("shortest")).setStoreOnFlush(false).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("profile1"), new CHProfile("profile2"));
    hopper.importOrLoad();
    assertEquals(2, hopper.getCHGraphs().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 39 with CHProfile

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

the class ProfileResolverTest method defaultWeighting.

@Test
public void defaultWeighting() {
    ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("bike,car,foot"), Arrays.asList(new Profile("fast_bike").setVehicle("bike").setWeighting("fastest"), new Profile("short_bike").setVehicle("bike").setWeighting("shortest")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
    // without specifying the weighting we get an error, because there are multiple matches
    assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
    // use weighting to specify profile
    assertEquals("short_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "shortest")).getName());
    assertEquals("fast_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "fastest")).getName());
}
Also used : PMap(com.graphhopper.util.PMap) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) CHProfileSelectorTest(com.graphhopper.routing.ch.CHProfileSelectorTest) LMProfileSelectorTest(com.graphhopper.routing.lm.LMProfileSelectorTest)

Example 40 with CHProfile

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

the class MapMatchingResourceTurnCostsTest method createConfig.

private static GraphHopperServerConfiguration createConfig() {
    GraphHopperServerConfiguration config = new GraphHopperServerConfiguration();
    config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car|turn_costs=true,bike").putObject("datareader.file", "../map-matching/files/leipzig_germany.osm.pbf").putObject("graph.location", DIR).setProfiles(Arrays.asList(new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(true), new Profile("car_no_tc").setVehicle("car").setWeighting("fastest"), new Profile("bike").setVehicle("bike").setWeighting("fastest"))).setLMProfiles(Arrays.asList(new LMProfile("car"), new LMProfile("bike"), new LMProfile("car_no_tc").setPreparationProfile("car"))).setCHProfiles(Collections.singletonList(new CHProfile("car_no_tc")));
    return config;
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GraphHopperServerConfiguration(com.graphhopper.application.GraphHopperServerConfiguration) LMProfile(com.graphhopper.config.LMProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile)

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