use of com.graphhopper.PathWrapper in project graphhopper by graphhopper.
the class ShapeFileReaderTest method testTravelTimesBetweenRandomLocations.
@Test
public void testTravelTimesBetweenRandomLocations() {
int nTests = 200;
final Random random = new Random(123);
final GHPoint min = new GHPoint(35.882931, 14.403076);
final GHPoint max = new GHPoint(35.913523, 14.448566);
class RandPointGenerator {
double rand(double min, double max) {
return min + random.nextDouble() * (max - min);
}
GHPoint randPoint() {
return new GHPoint(rand(min.lat, max.lat), rand(min.lon, max.lon));
}
}
RandPointGenerator pointGenerator = new RandPointGenerator();
int nbFails = 0;
DoubleSummaryStatistics stats = new DoubleSummaryStatistics();
for (int i = 0; i < nTests; i++) {
FromToPair pair = new FromToPair(pointGenerator.randPoint(), pointGenerator.randPoint());
// paths from random points can fail to don't assert on failure
PathWrapper shpPath = pair.getPath(hopperShp, false);
PathWrapper pbfPath = pair.getPath(hopperPbf, false);
// the road network)
if (shpPath == null || pbfPath == null) {
nbFails++;
continue;
}
double shpSecs = getSecondsTravel(shpPath);
double pbfSecs = getSecondsTravel(pbfPath);
double frac = shpSecs / pbfSecs;
double percentageDeviation = Math.abs(1.0 - frac) * 100;
stats.accept(percentageDeviation);
}
assertTrue("Number of fails should be small for the chosen box", nbFails < nTests / 3);
// Test mean fraction. There will be some deviation as not all tags are
// considered etc,
// but we expect it to be small for a large number of tests
double mean = stats.getAverage();
assertTrue("Should have a mean deviation in travel times of less than 1%", mean < 1.0);
}
use of com.graphhopper.PathWrapper in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testSortedGraph_noCH.
@Test
public void testSortedGraph_noCH() {
instance = new GraphHopperOSM().setStoreOnFlush(false).setSortGraph(true).setEncodingManager(new EncodingManager("car")).setCHEnabled(false).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
instance.importOrLoad();
PathWrapper rsp = instance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setAlgorithm(DIJKSTRA_BI)).getBest();
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getPoints().getSize());
assertEquals(new GHPoint(51.24921503475044, 9.431716451757769), rsp.getPoints().toGHPoint(0));
assertEquals(new GHPoint(52.0, 9.0), rsp.getPoints().toGHPoint(1));
assertEquals(new GHPoint(51.199999850988384, 9.39999970197677), rsp.getPoints().toGHPoint(2));
GHRequest req = new GHRequest(51.2492152, 9.4317166, 51.2, 9.4);
boolean old = instance.isEnableInstructions();
req.getHints().put("instructions", true);
instance.route(req);
assertEquals(old, instance.isEnableInstructions());
req.getHints().put("instructions", false);
instance.route(req);
assertEquals("route method should not change instance field", old, instance.isEnableInstructions());
}
use of com.graphhopper.PathWrapper in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testFootAndCar.
@Test
public void testFootAndCar() {
// now all ways are imported
instance = new GraphHopperOSM().setStoreOnFlush(false).setEncodingManager(new EncodingManager("car,foot")).setCHEnabled(false).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm3);
instance.importOrLoad();
assertEquals(5, instance.getGraphHopperStorage().getNodes());
assertEquals(8, instance.getGraphHopperStorage().getAllEdges().getMaxId());
// A to D
GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.3, 51).setVehicle("car"));
assertFalse(grsp.hasErrors());
PathWrapper rsp = grsp.getBest();
assertEquals(3, rsp.getPoints().getSize());
// => found A and D
assertEquals(50, rsp.getPoints().getLongitude(0), 1e-3);
assertEquals(11.1, rsp.getPoints().getLatitude(0), 1e-3);
assertEquals(51, rsp.getPoints().getLongitude(2), 1e-3);
assertEquals(11.3, rsp.getPoints().getLatitude(2), 1e-3);
// A to D not allowed for foot. But the location index will choose a node close to D accessible to FOOT
grsp = instance.route(new GHRequest(11.1, 50, 11.3, 51).setVehicle("foot"));
assertFalse(grsp.hasErrors());
rsp = grsp.getBest();
assertEquals(2, rsp.getPoints().getSize());
// => found a point on edge A-B
assertEquals(11.680, rsp.getPoints().getLatitude(1), 1e-3);
assertEquals(50.644, rsp.getPoints().getLongitude(1), 1e-3);
// A to E only for foot
grsp = instance.route(new GHRequest(11.1, 50, 10, 51).setVehicle("foot"));
assertFalse(grsp.hasErrors());
rsp = grsp.getBest();
assertEquals(2, rsp.getPoints().size());
// A D E for car
grsp = instance.route(new GHRequest(11.1, 50, 10, 51).setVehicle("car"));
assertFalse(grsp.hasErrors());
rsp = grsp.getBest();
assertEquals(3, rsp.getPoints().getSize());
}
use of com.graphhopper.PathWrapper in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testFootOnly.
@Test
public void testFootOnly() {
// now only footable ways are imported => no A D C and B D E => the other both ways have pillar nodes!
instance = new GraphHopperOSM().setStoreOnFlush(false).setEncodingManager(new EncodingManager("foot")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm3);
instance.importOrLoad();
assertEquals(2, instance.getGraphHopperStorage().getNodes());
assertEquals(2, instance.getGraphHopperStorage().getAllEdges().getMaxId());
// A to E only for foot
GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.19, 52).setVehicle("foot"));
assertFalse(grsp.hasErrors());
PathWrapper rsp = grsp.getBest();
// the last points snaps to the edge
assertEquals(Helper.createPointList(11.1, 50, 10, 51, 11.194015, 51.995013), rsp.getPoints());
}
use of com.graphhopper.PathWrapper in project graphhopper by graphhopper.
the class AlternativeRoutingTemplate method isReady.
@Override
public boolean isReady(PathMerger pathMerger, Translation tr) {
if (pathList.isEmpty())
throw new RuntimeException("Empty paths for alternative route calculation not expected");
// if alternative route calculation was done then create the responses from single paths
PointList wpList = getWaypoints();
altResponse.setWaypoints(wpList);
ghResponse.add(altResponse);
pathMerger.doWork(altResponse, Collections.singletonList(pathList.get(0)), tr);
for (int index = 1; index < pathList.size(); index++) {
PathWrapper tmpAltRsp = new PathWrapper();
tmpAltRsp.setWaypoints(wpList);
ghResponse.add(tmpAltRsp);
pathMerger.doWork(tmpAltRsp, Collections.singletonList(pathList.get(index)), tr);
}
return true;
}
Aggregations