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