use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class HeadingRoutingTest method testHeadingWithSnapFilter2.
@Test
public void testHeadingWithSnapFilter2() {
GraphHopperStorage graph = createSquareGraphWithTunnel();
Router router = createRouter(graph);
// Start at 8 (slightly east to snap to edge 1->5 per default)
GHPoint start = new GHPoint(0.001, 0.0011);
// End at middle of edge 2-3
GHPoint end = new GHPoint(0.002, 0.0005);
GHRequest req = new GHRequest().setPoints(Arrays.asList(start, end)).setProfile("profile").setHeadings(Arrays.asList(0.)).setPathDetails(Collections.singletonList("edge_key"));
req.putHint(Parameters.Routing.PASS_THROUGH, true);
GHResponse response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 8, 3, 2 }, calcNodes(graph, response.getAll().get(0)));
req = new GHRequest().setPoints(Arrays.asList(start, end)).setProfile("profile").setHeadings(Arrays.asList(180.)).setPathDetails(Collections.singletonList("edge_key"));
req.putHint(Parameters.Routing.PASS_THROUGH, true);
response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 8, 3, 2 }, calcNodes(graph, response.getAll().get(0)));
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class HeadingRoutingTest method testHeadingWithSnapFilter.
@Test
public void testHeadingWithSnapFilter() {
GraphHopperStorage graph = createSquareGraphWithTunnel();
Router router = createRouter(graph);
// Start at 8 (slightly north to make it independent on some edge ordering and always use 8-3 or 3-8 as fallback)
GHPoint start = new GHPoint(0.0011, 0.001);
// End at middle of edge 2-3
GHPoint end = new GHPoint(0.002, 0.0005);
// no heading
GHRequest req = new GHRequest().setPoints(Arrays.asList(start, end)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
req.putHint(Parameters.Routing.PASS_THROUGH, true);
GHResponse response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 8, 3, 2 }, calcNodes(graph, response.getAll().get(0)));
// same start + end but heading=0, parallel to 3-8-7
req = new GHRequest().setPoints(Arrays.asList(start, end)).setHeadings(Arrays.asList(0.)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
req.putHint(Parameters.Routing.PASS_THROUGH, true);
response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 8, 3, 2 }, calcNodes(graph, response.getAll().get(0)));
// heading=90 parallel to 1->5
req = new GHRequest().setPoints(Arrays.asList(start, end)).setHeadings(Arrays.asList(90., Double.NaN)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
req.putHint(Parameters.Routing.PASS_THROUGH, true);
response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 1, 5, 4, 3, 2 }, calcNodes(graph, response.getAll().get(0)));
for (double angle = 0; angle < 360; angle += 10) {
// Ignore angles nearly parallel to 1->5. I.e. it should fallback to results with 8-3.. or 3-8..
if (angle >= 60 && angle <= 120)
continue;
req = new GHRequest().setPoints(Arrays.asList(start, end)).setHeadings(Arrays.asList(angle, Double.NaN)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
req.putHint(Parameters.Routing.PASS_THROUGH, true);
response = router.route(req);
assertFalse(response.hasErrors());
int[] expectedNodes = (angle >= 130 && angle <= 250) ? new int[] { 3, 8, 7, 0, 1, 2, 3 } : new int[] { 8, 3, 2 };
// System.out.println(Arrays.toString(calcNodes(graph, response.getAll().get(0))) + " angle:" + angle);
assertArrayEquals(expectedNodes, calcNodes(graph, response.getAll().get(0)), "angle: " + angle);
}
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class HeadingRoutingTest method headingTest4.
@Test
public void headingTest4() {
// Test straight via routing
GraphHopperStorage graph = createSquareGraph();
Router router = createRouter(graph);
// Start in middle of edge 4-5
GHPoint start = new GHPoint(0.0015, 0.002);
// End at middle of edge 2-3
GHPoint end = new GHPoint(0.002, 0.0005);
// Via Point between 8-3
GHPoint via = new GHPoint(0.0015, 0.001);
GHRequest req = new GHRequest().setPoints(Arrays.asList(start, via, end)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
req.putHint(Parameters.Routing.PASS_THROUGH, true);
GHResponse response = router.route(req);
assertFalse(response.hasErrors());
assertEquals(1, response.getAll().size());
assertArrayEquals(new int[] { 5, 4, 3, 8, 1, 2, 3 }, calcNodes(graph, response.getAll().get(0)));
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class HeadingRoutingTest method headingTest2.
@Test
public void headingTest2() {
// Test enforce south start direction and east end direction
GraphHopperStorage graph = createSquareGraph();
Router router = createRouter(graph);
// Start in middle of edge 4-5
GHPoint start = new GHPoint(0.0015, 0.002);
// End at middle of edge 2-3
GHPoint end = new GHPoint(0.002, 0.0005);
GHRequest req = new GHRequest(start, end).setHeadings(Arrays.asList(180.0, 90.0)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
GHResponse response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 4, 5, 8, 1, 2, 3 }, calcNodes(graph, response.getAll().get(0)));
// Test uni-directional case
req.setAlgorithm(DIJKSTRA);
response = router.route(req);
assertFalse(response.hasErrors(), response.getErrors().toString());
assertArrayEquals(new int[] { 4, 5, 8, 1, 2, 3 }, calcNodes(graph, response.getAll().get(0)));
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class HeadingRoutingTest method headingTest5.
@Test
public void headingTest5() {
// Test independence of previous enforcement for subsequent paths
GraphHopperStorage graph = createSquareGraph();
Router router = createRouter(graph);
// Start in middle of edge 4-5
GHPoint start = new GHPoint(0.0015, 0.002);
// End at middle of edge 2-3
GHPoint end = new GHPoint(0.002, 0.0005);
// First go south and than come from west to via-point at 7-6. Then go back over previously punished (11)-4 edge
GHPoint via = new GHPoint(0.000, 0.0015);
GHRequest req = new GHRequest().setPoints(Arrays.asList(start, via, end)).setHeadings(Arrays.asList(0., 90., Double.NaN)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
req.putHint(Parameters.Routing.PASS_THROUGH, true);
GHResponse response = router.route(req);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 5, 4, 3, 8, 7, 6, 5, 4, 3, 2 }, calcNodes(graph, response.getAll().get(0)));
}
Aggregations