use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class RoutingExample method headingAndAlternativeRoute.
public static void headingAndAlternativeRoute(GraphHopper hopper) {
// define a heading (direction) at start and destination
GHRequest req = new GHRequest().setProfile("car").addPoint(new GHPoint(42.508774, 1.535414)).addPoint(new GHPoint(42.506595, 1.528795)).setHeadings(Arrays.asList(180d, 90d)).putHint(Parameters.CH.DISABLE, true);
// if you have via points you can avoid U-turns there with
// req.getHints().putObject(Parameters.Routing.PASS_THROUGH, true);
GHResponse res = hopper.route(req);
if (res.hasErrors())
throw new RuntimeException(res.getErrors().toString());
assert res.getAll().size() == 1;
assert Helper.round(res.getBest().getDistance(), -2) == 800;
// calculate alternative routes between two points (supported with and without CH)
req = new GHRequest().setProfile("car").addPoint(new GHPoint(42.502904, 1.514714)).addPoint(new GHPoint(42.511953, 1.535914)).setAlgorithm(Parameters.Algorithms.ALT_ROUTE);
req.getHints().putObject(Parameters.Algorithms.AltRoute.MAX_PATHS, 3);
res = hopper.route(req);
if (res.hasErrors())
throw new RuntimeException(res.getErrors().toString());
assert res.getAll().size() == 2;
assert Helper.round(res.getBest().getDistance(), -2) == 2300;
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class RoutingAlgorithmWithOSMTest method checkQueries.
/**
* Runs the given queries on the given GraphHopper instance and checks the expectations.
* All queries will use the first profile.
*/
private void checkQueries(GraphHopper hopper, List<Query> queries) {
for (Function<Query, GHRequest> requestFactory : createRequestFactories()) {
for (Query query : queries) {
GHRequest request = requestFactory.apply(query);
Profile profile = hopper.getProfiles().get(0);
request.setProfile(profile.getName());
GHResponse res = hopper.route(request);
checkResponse(res, query);
String expectedAlgo = request.getHints().getString("expected_algo", "no_expected_algo");
// for edge-based routing we expect a slightly different algo name for CH
if (profile.isTurnCosts())
expectedAlgo = expectedAlgo.replaceAll("\\|ch-routing", "|ch|edge_based|no_sod-routing");
assertTrue(res.getBest().getDebugInfo().contains(expectedAlgo), "Response does not contain expected algo string. Expected: '" + expectedAlgo + "', got: '" + res.getBest().getDebugInfo() + "'");
}
}
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class RoutingAlgorithmWithOSMTest method testDisconnectedAreaAndMultiplePoints.
@Test
public void testDisconnectedAreaAndMultiplePoints() {
Query query = new Query();
query.add(53.753177, 9.435968, 10, 10);
query.add(53.751299, 9.386959, 10, 10);
query.add(53.751299, 9.3869, 10, 10);
GraphHopper hopper = createHopper(DIR + "/krautsand.osm.gz", new Profile("car").setVehicle("car").setWeighting("fastest"));
hopper.setElevationProvider(new SRTMProvider(DIR));
hopper.importOrLoad();
for (Function<Query, GHRequest> requestFactory : createRequestFactories()) {
GHRequest request = requestFactory.apply(query);
request.setProfile(hopper.getProfiles().get(0).getName());
GHResponse res = hopper.route(request);
assertTrue(res.hasErrors());
assertTrue(res.getErrors().toString().contains("ConnectionNotFound"), res.getErrors().toString());
}
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class HeadingRoutingTest method headingTest6.
@Test
public void headingTest6() {
// Test if snaps at tower nodes are ignored
GraphHopperStorage graph = createSquareGraph();
Router router = createRouter(graph);
// QueryPoints directly on TowerNodes
GHPoint start = new GHPoint(0, 0);
GHPoint via = new GHPoint(0.002, 0.000);
GHPoint end = new GHPoint(0.002, 0.002);
GHRequest req = new GHRequest().setPoints(Arrays.asList(start, via, end)).setHeadings(Arrays.asList(90., 270., 270.)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
GHResponse response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 0, 1, 2, 3, 4 }, calcNodes(graph, response.getAll().get(0)));
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class HeadingRoutingTest method headingTest3.
@Test
public void headingTest3() {
GraphHopperStorage graph = createSquareGraph();
Router router = createRouter(graph);
// Start in middle of edge 4-5
GHPoint start = new GHPoint(0.0015, 0.002);
// Via Point between 8-7
GHPoint via = new GHPoint(0.0005, 0.001);
// End at middle of edge 2-3
GHPoint end = new GHPoint(0.002, 0.0005);
GHRequest req = new GHRequest().setPoints(Arrays.asList(start, via, end)).setHeadings(Arrays.asList(Double.NaN, 0., Double.NaN)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
GHResponse response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 4, 5, 6, 7, 8, 3, 2 }, calcNodes(graph, response.getAll().get(0)));
}
Aggregations