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);
}
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());
}
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());
}
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"));
}
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());
}
Aggregations