Search in sources :

Example 31 with GHResponse

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());
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) Profile(com.graphhopper.config.Profile) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 32 with GHResponse

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());
}
Also used : ArrayList(java.util.ArrayList) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) GHPoint(com.graphhopper.util.shapes.GHPoint) Function(java.util.function.Function) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GHRequest(com.graphhopper.GHRequest) Test(org.junit.jupiter.api.Test)

Example 33 with GHResponse

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;
}
Also used : GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse)

Example 34 with GHResponse

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;
}
Also used : ResponsePath(com.graphhopper.ResponsePath) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse)

Example 35 with GHResponse

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;
}
Also used : ResponsePath(com.graphhopper.ResponsePath) GHResponse(com.graphhopper.GHResponse)

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