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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations