Search in sources :

Example 36 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method testNoPoints.

@Test
public void testNoPoints() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
    req.getHints().put("instructions", false);
    req.getHints().put("calc_points", false);
    GHResponse res = gh.route(req);
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    PathWrapper alt = res.getBest();
    assertEquals(0, alt.getPoints().size());
    isBetween(11000, 12000, alt.getDistance());
}
Also used : PathWrapper(com.graphhopper.PathWrapper) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 37 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testGetPathsDirectionEnforcement6.

@Test
public void testGetPathsDirectionEnforcement6() {
    // Test if query results at tower nodes are ignored
    instance = createSquareGraphInstance(false);
    // 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().addPoint(start, 90.).addPoint(via, 270.).addPoint(end, 270.);
    GHResponse response = new GHResponse();
    List<Path> paths = instance.calcPaths(req, response);
    assertFalse(response.hasErrors());
    assertArrayEquals(new int[] { 0, 1, 2 }, paths.get(0).calcNodes().toArray());
    assertArrayEquals(new int[] { 2, 3, 4 }, paths.get(1).calcNodes().toArray());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 38 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testGetPathsDirectionEnforcement1.

@Test
public void testGetPathsDirectionEnforcement1() {
    // Test enforce start direction
    // Note: This Test does not pass for CH enabled
    instance = createSquareGraphInstance(false);
    // 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().addPoint(start, 180.).addPoint(end);
    GHResponse response = new GHResponse();
    List<Path> paths = instance.calcPaths(req, response);
    assertFalse(response.hasErrors());
    assertArrayEquals(new int[] { 9, 5, 8, 3, 10 }, paths.get(0).calcNodes().toArray());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 39 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testVia.

@Test
public void testVia() {
    instance = new GraphHopperOSM().setStoreOnFlush(true).init(new CmdArgs().put("datareader.file", testOsm3).put("prepare.min_network_size", "1").put("graph.flag_encoders", "car")).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().addPoint(first).addPoint(second));
    assertFalse("should find 1->2", rsp12.hasErrors());
    assertEquals(147930.5, rsp12.getBest().getDistance(), .1);
    GHResponse rsp23 = instance.route(new GHRequest().addPoint(second).addPoint(third));
    assertFalse("should find 2->3", rsp23.hasErrors());
    assertEquals(176608.9, rsp23.getBest().getDistance(), .1);
    GHResponse grsp = instance.route(new GHRequest().addPoint(first).addPoint(second).addPoint(third));
    assertFalse("should find 1->2->3", grsp.hasErrors());
    PathWrapper rsp = grsp.getBest();
    assertEquals(rsp12.getBest().getDistance() + rsp23.getBest().getDistance(), rsp.getDistance(), 1e-6);
    assertEquals(4, rsp.getPoints().getSize());
    assertEquals(5, rsp.getInstructions().size());
    assertEquals(Instruction.REACHED_VIA, rsp.getInstructions().get(1).getSign());
}
Also used : PathWrapper(com.graphhopper.PathWrapper) CmdArgs(com.graphhopper.util.CmdArgs) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 40 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testGetPathsDirectionEnforcement4.

@Test
public void testGetPathsDirectionEnforcement4() {
    // Test straight via routing
    instance = createSquareGraphInstance(false);
    // 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 betweeen 8-3
    GHPoint via = new GHPoint(0.0015, 0.001);
    GHRequest req = new GHRequest().addPoint(start).addPoint(via).addPoint(end);
    req.getHints().put(Routing.PASS_THROUGH, true);
    GHResponse response = new GHResponse();
    List<Path> paths = instance.calcPaths(req, response);
    assertFalse(response.hasErrors());
    assertEquals(1, response.getAll().size());
    assertEquals(IntArrayList.from(9, 4, 3, 10), paths.get(0).calcNodes());
    assertEquals(IntArrayList.from(10, 8, 1, 2, 11), paths.get(1).calcNodes());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Aggregations

GHRequest (com.graphhopper.GHRequest)50 Test (org.junit.Test)43 GHResponse (com.graphhopper.GHResponse)42 GHPoint (com.graphhopper.util.shapes.GHPoint)26 PathWrapper (com.graphhopper.PathWrapper)13 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 GraphHopper (com.graphhopper.GraphHopper)4 CHGraph (com.graphhopper.storage.CHGraph)3 Graph (com.graphhopper.storage.Graph)3 NodeAccess (com.graphhopper.storage.NodeAccess)3 CmdArgs (com.graphhopper.util.CmdArgs)3 IOException (java.io.IOException)3 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 QueryResult (com.graphhopper.storage.index.QueryResult)2 Downloader (com.graphhopper.util.Downloader)2 InstructionList (com.graphhopper.util.InstructionList)2 PathDetail (com.graphhopper.util.details.PathDetail)2