use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class OSMReaderTest method testRoutingRequestFails_issue665.
@Test
public void testRoutingRequestFails_issue665() {
GraphHopper hopper = new GraphHopper().setOSMFile(getClass().getResource(file7).getFile()).setProfiles(new Profile("profile1").setVehicle("car").setWeighting("fastest"), new Profile("profile2").setVehicle("motorcycle").setWeighting("curvature")).setGraphHopperLocation(dir);
hopper.importOrLoad();
GHRequest req = new GHRequest(48.977277, 8.256896, 48.978876, 8.254884).setProfile("profile2");
GHResponse ghRsp = hopper.route(req);
assertFalse(ghRsp.hasErrors(), ghRsp.getErrors().toString());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class RoutingAlgorithmWithOSMTest method testMonacoParallel.
@Test
public void testMonacoParallel() throws InterruptedException {
GraphHopper hopper = createHopper(MONACO, new Profile("car").setVehicle("car").setWeighting("shortest"));
hopper.getReaderConfig().setMaxWayPointDistance(0);
hopper.getRouterConfig().setSimplifyResponse(false);
hopper.importOrLoad();
final List<Query> queries = createMonacoCarQueries();
List<Thread> threads = new ArrayList<>();
final AtomicInteger routeCount = new AtomicInteger(0);
// testing if algorithms are independent. should be. so test only two algorithms.
List<Function<Query, GHRequest>> requestFactories = Arrays.asList(q -> createRequest(q).setAlgorithm(DIJKSTRA_BI).setProfile("car"), q -> createRequest(q).setAlgorithm(ASTAR_BI).setProfile("car"));
int loops = 100;
for (int i = 0; i < loops; i++) {
for (Query query : queries) {
for (Function<Query, GHRequest> requestFactory : requestFactories) {
GHRequest req = requestFactory.apply(query);
Thread t = new Thread(() -> {
GHResponse res = hopper.route(req);
checkResponse(res, query);
routeCount.incrementAndGet();
});
t.start();
threads.add(t);
}
}
}
for (Thread t : threads) t.join();
assertEquals(loops * queries.size() * requestFactories.size(), routeCount.get());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class RoutingExample method speedModeVersusFlexibleMode.
public static void speedModeVersusFlexibleMode(GraphHopper hopper) {
GHRequest req = new GHRequest(42.508552, 1.532936, 42.507508, 1.528773).setProfile("car").setAlgorithm(Parameters.Algorithms.ASTAR_BI).putHint(Parameters.CH.DISABLE, true);
GHResponse res = hopper.route(req);
if (res.hasErrors())
throw new RuntimeException(res.getErrors().toString());
assert Helper.round(res.getBest().getDistance(), -2) == 900;
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class RoutingExample method routing.
public static void routing(GraphHopper hopper) {
// simple configuration of the request object
GHRequest req = new GHRequest(42.508552, 1.532936, 42.507508, 1.528773).setProfile("car").setLocale(Locale.US);
GHResponse rsp = hopper.route(req);
// handle errors
if (rsp.hasErrors())
throw new RuntimeException(rsp.getErrors().toString());
// use the best path, see the GHResponse class for more possibilities.
ResponsePath path = rsp.getBest();
// points, distance in meters and time in millis of the full path
PointList pointList = path.getPoints();
double distance = path.getDistance();
long timeInMs = path.getTime();
Translation tr = hopper.getTranslationMap().getWithFallBack(Locale.UK);
InstructionList il = path.getInstructions();
// iterate over all turn instructions
for (Instruction instruction : il) {
// System.out.println("distance " + instruction.getDistance() + " for instruction: " + instruction.getTurnDescription(tr));
}
assert il.size() == 6;
assert Helper.round(path.getDistance(), -2) == 900;
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class RoutingExampleTC method route.
private static void route(GraphHopper hopper, GHRequest req, int expectedDistance, int expectedTime) {
GHResponse rsp = hopper.route(req);
// handle errors
if (rsp.hasErrors())
// you either specify 'curbside=any' or Parameters.Routing.FORCE_CURBSIDE=false to ignore this situation
throw new RuntimeException(rsp.getErrors().toString());
ResponsePath path = rsp.getBest();
assert Math.abs(expectedDistance - path.getDistance()) < 1 : "unexpected distance : " + path.getDistance() + " vs. " + expectedDistance;
assert Math.abs(expectedTime - path.getTime()) < 1000 : "unexpected time : " + path.getTime() + " vs. " + expectedTime;
}
Aggregations