Search in sources :

Example 26 with GHResponse

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)));
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 27 with GHResponse

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);
    }
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 28 with GHResponse

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)));
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 29 with GHResponse

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)));
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 30 with GHResponse

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)));
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Aggregations

GHResponse (com.graphhopper.GHResponse)100 GHRequest (com.graphhopper.GHRequest)86 GHPoint (com.graphhopper.util.shapes.GHPoint)52 Test (org.junit.Test)31 Test (org.junit.jupiter.api.Test)31 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ResponsePath (com.graphhopper.ResponsePath)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 PathWrapper (com.graphhopper.PathWrapper)9 GraphHopper (com.graphhopper.GraphHopper)7 InstructionList (com.graphhopper.util.InstructionList)7 PathDetail (com.graphhopper.util.details.PathDetail)7 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 Profile (com.graphhopper.config.Profile)5 Graph (com.graphhopper.storage.Graph)5 NodeAccess (com.graphhopper.storage.NodeAccess)5 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)5