Search in sources :

Example 16 with GHResponse

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

the class RoundTripRoutingTemplateTest method lookup_throwsIfNumberOfPointsInRequestNotOne.

@Test(expected = IllegalArgumentException.class)
public void lookup_throwsIfNumberOfPointsInRequestNotOne() {
    RoundTripRoutingTemplate routingTemplate = new RoundTripRoutingTemplate(new GHRequest(Arrays.asList(ghPoint1, ghPoint2)), new GHResponse(), null, 1);
    routingTemplate.lookup(Collections.singletonList(ghPoint1), carFE);
}
Also used : GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 17 with GHResponse

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

the class RoundTripRoutingTemplateTest method testLookupAndCalcPaths_simpleSquareGraph.

@Test
public void testLookupAndCalcPaths_simpleSquareGraph() {
    Graph g = createSquareGraph();
    // start at node 0 and head south, make sure the round trip is long enough to reach most southern node 6
    GHPoint start = new GHPoint(1, -1);
    double heading = 180.0;
    int numPoints = 2;
    double roundTripDistance = 670000;
    GHRequest ghRequest = new GHRequest(Collections.singletonList(start), Collections.singletonList(heading));
    ghRequest.getHints().put(Parameters.Algorithms.RoundTrip.POINTS, numPoints);
    ghRequest.getHints().put(Parameters.Algorithms.RoundTrip.DISTANCE, roundTripDistance);
    LocationIndex locationIndex = new LocationIndexTree(g, new RAMDirectory()).prepareIndex();
    RoundTripRoutingTemplate routingTemplate = new RoundTripRoutingTemplate(ghRequest, new GHResponse(), locationIndex, 1);
    List<QueryResult> stagePoints = routingTemplate.lookup(ghRequest.getPoints(), carFE);
    assertEquals(3, stagePoints.size());
    assertEquals(0, stagePoints.get(0).getClosestNode());
    assertEquals(6, stagePoints.get(1).getClosestNode());
    assertEquals(0, stagePoints.get(2).getClosestNode());
    QueryGraph queryGraph = new QueryGraph(g);
    queryGraph.lookup(stagePoints);
    Weighting weighting = new FastestWeighting(carFE);
    List<Path> paths = routingTemplate.calcPaths(queryGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
    // make sure the resulting paths are connected and form a round trip starting and ending at the start node 0
    assertEquals(2, paths.size());
    assertEquals(Helper.createTList(0, 7, 6, 5), paths.get(0).calcNodes());
    assertEquals(Helper.createTList(5, 4, 3, 2, 1, 0), paths.get(1).calcNodes());
}
Also used : LocationIndex(com.graphhopper.storage.index.LocationIndex) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) QueryResult(com.graphhopper.storage.index.QueryResult) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) GHRequest(com.graphhopper.GHRequest) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 18 with GHResponse

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

the class RoundTripRoutingTemplateTest method testCalcRoundTrip.

@Test
public void testCalcRoundTrip() throws Exception {
    Weighting weighting = new FastestWeighting(carFE);
    Graph g = createTestGraph(true);
    RoundTripRoutingTemplate rTripRouting = new RoundTripRoutingTemplate(new GHRequest(), new GHResponse(), null, 1);
    LocationIndex locationIndex = new LocationIndexTree(g, new RAMDirectory()).prepareIndex();
    QueryResult qr4 = locationIndex.findClosest(0.05, 0.25, EdgeFilter.ALL_EDGES);
    assertEquals(4, qr4.getClosestNode());
    QueryResult qr5 = locationIndex.findClosest(0.00, 0.05, EdgeFilter.ALL_EDGES);
    assertEquals(5, qr5.getClosestNode());
    QueryResult qr6 = locationIndex.findClosest(0.00, 0.10, EdgeFilter.ALL_EDGES);
    assertEquals(6, qr6.getClosestNode());
    QueryGraph qGraph = new QueryGraph(g);
    qGraph.lookup(qr4, qr5);
    rTripRouting.setQueryResults(Arrays.asList(qr5, qr4, qr5));
    List<Path> paths = rTripRouting.calcPaths(qGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
    assertEquals(2, paths.size());
    assertEquals(Helper.createTList(5, 6, 3, 4), paths.get(0).calcNodes());
    assertEquals(Helper.createTList(4, 8, 7, 6, 5), paths.get(1).calcNodes());
    qGraph = new QueryGraph(g);
    qGraph.lookup(qr4, qr6);
    rTripRouting.setQueryResults(Arrays.asList(qr6, qr4, qr6));
    paths = rTripRouting.calcPaths(qGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
    assertEquals(2, paths.size());
    assertEquals(Helper.createTList(6, 3, 4), paths.get(0).calcNodes());
    assertEquals(Helper.createTList(4, 8, 7, 6), paths.get(1).calcNodes());
}
Also used : GHResponse(com.graphhopper.GHResponse) LocationIndex(com.graphhopper.storage.index.LocationIndex) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) QueryResult(com.graphhopper.storage.index.QueryResult) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) GHRequest(com.graphhopper.GHRequest) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Example 19 with GHResponse

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

the class GraphHopperServletIT method testGraphHopperWeb.

@Test
public void testGraphHopperWeb() throws Exception {
    GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
    assertTrue(hopper.load(getTestRouteAPIUrl()));
    GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128));
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertTrue(rsp.getErrors().toString(), rsp.getErrors().isEmpty());
    PathWrapper arsp = rsp.getBest();
    assertTrue("distance wasn't correct:" + arsp.getDistance(), arsp.getDistance() > 9000);
    assertTrue("distance wasn't correct:" + arsp.getDistance(), arsp.getDistance() < 9500);
    rsp = hopper.route(new GHRequest().addPoint(new GHPoint(42.554851, 1.536198)).addPoint(new GHPoint(42.531896, 1.553278)).addPoint(new GHPoint(42.510071, 1.548128)));
    assertTrue(rsp.getErrors().toString(), rsp.getErrors().isEmpty());
    arsp = rsp.getBest();
    assertTrue("distance wasn't correct:" + arsp.getDistance(), arsp.getDistance() > 20000);
    assertTrue("distance wasn't correct:" + arsp.getDistance(), arsp.getDistance() < 21000);
    List<Map<String, Object>> instructions = arsp.getInstructions().createJson();
    assertEquals(26, instructions.size());
    assertEquals("Continue onto la Callisa", instructions.get(0).get("text"));
    assertEquals("At roundabout, take exit 2", instructions.get(4).get("text"));
    assertEquals(true, instructions.get(4).get("exited"));
    assertEquals(false, instructions.get(24).get("exited"));
}
Also used : PathWrapper(com.graphhopper.PathWrapper) GraphHopperAPI(com.graphhopper.GraphHopperAPI) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) Map(java.util.Map) Test(org.junit.Test)

Example 20 with GHResponse

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

the class GraphHopperServletIT method testInitInstructionsWithTurnDescription.

@Test
public void testInitInstructionsWithTurnDescription() {
    GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
    assertTrue(hopper.load(getTestRouteAPIUrl()));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128);
    GHResponse rsp = hopper.route(request);
    assertEquals("Continue onto Carrer Antoni Fiter i Rossell", rsp.getBest().getInstructions().get(3).getName());
    request.getHints().put("turn_description", false);
    rsp = hopper.route(request);
    assertEquals("Carrer Antoni Fiter i Rossell", rsp.getBest().getInstructions().get(3).getName());
}
Also used : GraphHopperAPI(com.graphhopper.GraphHopperAPI) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) Test(org.junit.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