use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperTest method testImportCloseAndLoad.
private void testImportCloseAndLoad(boolean ch, boolean lm, boolean sort, boolean custom) {
final String vehicle = "foot";
final String profileName = "profile";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setStoreOnFlush(true).setSortGraph(sort);
Profile profile = new Profile(profileName).setVehicle(vehicle).setWeighting("fastest");
if (custom) {
JsonFeature area51Feature = new JsonFeature();
area51Feature.setGeometry(new GeometryFactory().createPolygon(new Coordinate[] { new Coordinate(7.4174, 43.7345), new Coordinate(7.4198, 43.7355), new Coordinate(7.4207, 43.7344), new Coordinate(7.4174, 43.7345) }));
CustomModel customModel = new CustomModel().setDistanceInfluence(0);
customModel.getPriority().add(Statement.If("in_area51", Statement.Op.MULTIPLY, 0.1));
customModel.getAreas().put("area51", area51Feature);
profile = new CustomProfile(profileName).setCustomModel(customModel).setVehicle(vehicle);
}
hopper.setProfiles(profile);
if (ch) {
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profileName));
}
if (lm) {
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profileName));
}
hopper.importAndClose();
hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(profile).setStoreOnFlush(true).setAllowWrites(false);
if (ch) {
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profileName));
}
if (lm) {
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profileName));
}
hopper.importOrLoad();
if (ch) {
GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName);
req.putHint(CH.DISABLE, false);
req.putHint(Landmark.DISABLE, true);
GHResponse rsp = hopper.route(req);
ResponsePath bestPath = rsp.getBest();
long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
assertNotEquals(sum, 0);
assertTrue(sum < 155, "Too many nodes visited " + sum);
assertEquals(3535, bestPath.getDistance(), 1);
assertEquals(115, bestPath.getPoints().size());
}
if (lm) {
GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName).setAlgorithm(Parameters.Algorithms.ASTAR_BI);
req.putHint(CH.DISABLE, true);
req.putHint(Landmark.DISABLE, false);
GHResponse rsp = hopper.route(req);
ResponsePath bestPath = rsp.getBest();
long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
assertNotEquals(sum, 0);
assertTrue(sum < 125, "Too many nodes visited " + sum);
assertEquals(3535, bestPath.getDistance(), 1);
assertEquals(115, bestPath.getPoints().size());
}
// flexible
GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName);
req.putHint(CH.DISABLE, true);
req.putHint(Landmark.DISABLE, true);
GHResponse rsp = hopper.route(req);
ResponsePath bestPath = rsp.getBest();
long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
assertNotEquals(sum, 0);
assertTrue(sum > 120, "Too few nodes visited " + sum);
assertEquals(3535, bestPath.getDistance(), 1);
assertEquals(115, bestPath.getPoints().size());
hopper.close();
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperTest method executeCHFootRoute.
private void executeCHFootRoute(boolean sort) {
final String profile = "profile";
final String vehicle = "foot";
final String weighting = "shortest";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).setSortGraph(sort);
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
hopper.importOrLoad();
// same query as in testMonacoWithInstructions
GHResponse rsp = hopper.route(new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profile));
ResponsePath bestPath = rsp.getBest();
// identify the number of counts to compare with none-CH foot route which had nearly 700 counts
long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
assertNotEquals(sum, 0);
assertTrue(sum < 147, "Too many nodes visited " + sum);
assertEquals(3437.1, bestPath.getDistance(), .1);
assertEquals(85, bestPath.getPoints().size());
hopper.close();
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperTest method testCHWithFiniteUTurnCosts.
@Test
public void testCHWithFiniteUTurnCosts() {
GraphHopper h = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest").setTurnCosts(true).putHint(U_TURN_COSTS, 40));
h.getCHPreparationHandler().setCHProfiles(new CHProfile("my_profile"));
h.importOrLoad();
GHPoint p = new GHPoint(43.73397, 7.414173);
GHPoint q = new GHPoint(43.73222, 7.415557);
GHRequest req = new GHRequest(p, q);
req.setProfile("my_profile");
// we force the start/target directions such that there are u-turns right after we start and right before
// we reach the target
req.setCurbsides(Arrays.asList("right", "right"));
GHResponse res = h.route(req);
assertFalse(res.hasErrors(), "routing should not fail");
assertEquals(266.8, res.getBest().getRouteWeight(), 0.1);
assertEquals(2116, res.getBest().getDistance(), 1);
assertEquals(266800, res.getBest().getTime(), 1000);
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperTest method testForceCurbsides.
@Test
public void testForceCurbsides() {
final String profile = "my_profile";
final String vehicle = "car";
final String weighting = "fastest";
GraphHopper h = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true));
h.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
h.importOrLoad();
// depending on the curbside parameters we take very different routes
// p
// ---->----
// q
GHPoint p = new GHPoint(43.738399, 7.420782);
GHPoint q = new GHPoint(43.737949, 7.423523);
final String boulevard = "Boulevard de Suisse";
final String avenue = "Avenue de la Costa";
assertCurbsidesPathError(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_RIGHT), "Impossible curbside constraint: 'curbside=right' at point 0", true);
assertCurbsidesPathError(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_LEFT), "Impossible curbside constraint: 'curbside=right' at point 0", true);
assertCurbsidesPath(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_RIGHT), 463, asList(boulevard, avenue));
assertCurbsidesPathError(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_LEFT), "Impossible curbside constraint: 'curbside=left' at point 1", true);
// without restricting anything we get the shortest path
assertCurbsidesPath(h, p, q, asList(CURBSIDE_ANY, CURBSIDE_ANY), 463, asList(boulevard, avenue));
assertCurbsidesPath(h, p, q, Collections.<String>emptyList(), 463, asList(boulevard, avenue));
// if we set force_curbside to false impossible curbside constraints will be ignored
assertCurbsidesPath(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_RIGHT), 463, asList(boulevard, avenue), false);
assertCurbsidesPath(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_LEFT), 463, asList(boulevard, avenue), false);
assertCurbsidesPath(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_RIGHT), 463, asList(boulevard, avenue), false);
assertCurbsidesPath(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_LEFT), 463, asList(boulevard, avenue), false);
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperTest method testIssue1960.
@Test
public void testIssue1960() {
final String profile = "car";
final String vehicle = "car";
final String weighting = "fastest";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MOSCOW).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true));
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profile));
hopper.importOrLoad();
GHRequest req = new GHRequest(55.815670, 37.604613, 55.806151, 37.617823);
req.setProfile("car");
req.getHints().putObject(CH.DISABLE, false).putObject(Landmark.DISABLE, true);
ResponsePath pathCH = hopper.route(req).getBest();
req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, false);
ResponsePath pathLM = hopper.route(req).getBest();
req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, true);
ResponsePath path = hopper.route(req).getBest();
assertEquals(1995.38, pathCH.getDistance(), 0.1);
assertEquals(1995.38, pathLM.getDistance(), 0.1);
assertEquals(1995.38, path.getDistance(), 0.1);
assertEquals(149497, pathCH.getTime());
assertEquals(149497, pathLM.getTime());
assertEquals(149497, path.getTime());
}
Aggregations