Search in sources :

Example 6 with CHProfile

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

the class ProfileResolverTest method defaultVehicle.

@Test
public void defaultVehicle() {
    ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("car,foot,bike"), Arrays.asList(new Profile("my_bike").setVehicle("bike"), new Profile("your_car").setVehicle("car")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
    // without specifying the vehicle we get an error, because there are multiple matches
    assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
    // use vehicle to specify profile
    assertEquals("your_car", profileResolver.resolveProfile(new PMap().putObject("vehicle", "car")).getName());
    assertEquals("my_bike", profileResolver.resolveProfile(new PMap().putObject("vehicle", "bike")).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 7 with CHProfile

use of com.graphhopper.config.CHProfile 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());
}
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 8 with CHProfile

use of com.graphhopper.config.CHProfile 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());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) 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 9 with CHProfile

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

the class CHPreparationHandlerTest method testEnabled.

@Test
public void testEnabled() {
    CHPreparationHandler instance = new CHPreparationHandler();
    assertFalse(instance.isEnabled());
    instance.setCHProfiles(new CHProfile("myconfig"));
    assertTrue(instance.isEnabled());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) Test(org.junit.jupiter.api.Test)

Example 10 with CHProfile

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

the class RoutingExample method createGraphHopperInstance.

static GraphHopper createGraphHopperInstance(String ghLoc) {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile(ghLoc);
    // specify where to store graphhopper files
    hopper.setGraphHopperLocation("target/routing-graph-cache");
    // see docs/core/profiles.md to learn more about profiles
    hopper.setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(false));
    // this enables speed mode for the profile we called car
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
    // now this can take minutes if it imports or a few seconds for loading of course this is dependent on the area you import
    hopper.importOrLoad();
    return hopper;
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GraphHopper(com.graphhopper.GraphHopper) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) 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