Search in sources :

Example 11 with GHResponse

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

the class GraphHopperOSMTest method testGetPathsDirectionEnforcement3.

@Test
public void testGetPathsDirectionEnforcement3() {
    instance = createSquareGraphInstance(false);
    // Start in middle of edge 4-5
    GHPoint start = new GHPoint(0.0015, 0.002);
    // End at middle of edge 2-3
    GHPoint end = new GHPoint(0.002, 0.0005);
    // Via Point betweeen 8-7
    GHPoint via = new GHPoint(0.0005, 0.001);
    GHRequest req = new GHRequest().addPoint(start).addPoint(via, 0.).addPoint(end);
    GHResponse response = new GHResponse();
    List<Path> paths = instance.calcPaths(req, response);
    assertFalse(response.hasErrors());
    assertEquals(IntArrayList.from(9, 5, 6, 7, 11), paths.get(0).calcNodes());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 12 with GHResponse

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

the class GraphHopperOSMTest method testGetPathsDirectionEnforcement5.

@Test
public void testGetPathsDirectionEnforcement5() {
    // Test independence of previous enforcement for subsequent pathes
    instance = createSquareGraphInstance(false);
    // Start in middle of edge 4-5
    GHPoint start = new GHPoint(0.0015, 0.002);
    // End at middle of edge 2-3
    GHPoint end = new GHPoint(0.002, 0.0005);
    // First go south and than come from west to via-point at 7-6. Then go back over previously punished (11)-4 edge
    GHPoint via = new GHPoint(0.000, 0.0015);
    GHRequest req = new GHRequest().addPoint(start, 0.).addPoint(via, 3.14 / 2).addPoint(end);
    req.getHints().put(Routing.PASS_THROUGH, true);
    GHResponse response = new GHResponse();
    List<Path> paths = instance.calcPaths(req, response);
    assertFalse(response.hasErrors());
    assertEquals(IntArrayList.from(9, 4, 3, 8, 7, 11), paths.get(0).calcNodes());
    assertEquals(IntArrayList.from(11, 6, 5, 9, 4, 3, 10), paths.get(1).calcNodes());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 13 with GHResponse

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

the class Measurement method compareRouting.

private void compareRouting(final GraphHopper hopper, String vehicle, int count) {
    logger.info("Comparing " + count + " routes. Differences will be printed to stderr.");
    String algo = Algorithms.ASTAR_BI;
    final Random rand = new Random(seed);
    final Graph g = hopper.getGraphHopperStorage();
    final NodeAccess na = g.getNodeAccess();
    for (int i = 0; i < count; i++) {
        int from = rand.nextInt(maxNode);
        int to = rand.nextInt(maxNode);
        double fromLat = na.getLatitude(from);
        double fromLon = na.getLongitude(from);
        double toLat = na.getLatitude(to);
        double toLon = na.getLongitude(to);
        GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon).setWeighting("fastest").setVehicle(vehicle).setAlgorithm(algo);
        GHResponse lmRsp = hopper.route(req);
        req.getHints().put(Landmark.DISABLE, true);
        GHResponse originalRsp = hopper.route(req);
        String locStr = " iteration " + i + ". " + fromLat + "," + fromLon + " -> " + toLat + "," + toLon;
        if (lmRsp.hasErrors()) {
            if (originalRsp.hasErrors())
                continue;
            logger.error("Error for LM but not for original response " + locStr);
        }
        String infoStr = " weight:" + lmRsp.getBest().getRouteWeight() + ", original: " + originalRsp.getBest().getRouteWeight() + " distance:" + lmRsp.getBest().getDistance() + ", original: " + originalRsp.getBest().getDistance() + " time:" + round2(lmRsp.getBest().getTime() / 1000) + ", original: " + round2(originalRsp.getBest().getTime() / 1000) + " points:" + lmRsp.getBest().getPoints().size() + ", original: " + originalRsp.getBest().getPoints().size();
        if (Math.abs(1 - lmRsp.getBest().getRouteWeight() / originalRsp.getBest().getRouteWeight()) > 0.000001)
            logger.error("Too big weight difference for LM. " + locStr + infoStr);
    }
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) CHGraph(com.graphhopper.storage.CHGraph) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse)

Example 14 with GHResponse

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

the class Measurement method compareCHWithAndWithoutSOD.

private void compareCHWithAndWithoutSOD(final GraphHopper hopper, String vehicle, int count) {
    logger.info("Comparing " + count + " routes for CH with and without stall on demand." + " Differences will be printed to stderr.");
    final Random rand = new Random(seed);
    final Graph g = hopper.getGraphHopperStorage();
    final NodeAccess na = g.getNodeAccess();
    for (int i = 0; i < count; i++) {
        int from = rand.nextInt(maxNode);
        int to = rand.nextInt(maxNode);
        double fromLat = na.getLatitude(from);
        double fromLon = na.getLongitude(from);
        double toLat = na.getLatitude(to);
        double toLon = na.getLongitude(to);
        GHRequest sodReq = new GHRequest(fromLat, fromLon, toLat, toLon).setWeighting("fastest").setVehicle(vehicle).setAlgorithm(DIJKSTRA_BI);
        GHRequest noSodReq = new GHRequest(fromLat, fromLon, toLat, toLon).setWeighting("fastest").setVehicle(vehicle).setAlgorithm(DIJKSTRA_BI);
        noSodReq.getHints().put("stall_on_demand", false);
        GHResponse sodRsp = hopper.route(sodReq);
        GHResponse noSodRsp = hopper.route(noSodReq);
        String locStr = " iteration " + i + ". " + fromLat + "," + fromLon + " -> " + toLat + "," + toLon;
        if (sodRsp.hasErrors()) {
            if (noSodRsp.hasErrors()) {
                logger.info("Error with and without SOD");
                continue;
            } else {
                logger.error("Error with SOD but not without SOD" + locStr);
                continue;
            }
        }
        String infoStr = " weight:" + noSodRsp.getBest().getRouteWeight() + ", original: " + sodRsp.getBest().getRouteWeight() + " distance:" + noSodRsp.getBest().getDistance() + ", original: " + sodRsp.getBest().getDistance() + " time:" + round2(noSodRsp.getBest().getTime() / 1000) + ", original: " + round2(sodRsp.getBest().getTime() / 1000) + " points:" + noSodRsp.getBest().getPoints().size() + ", original: " + sodRsp.getBest().getPoints().size();
        if (Math.abs(1 - noSodRsp.getBest().getRouteWeight() / sodRsp.getBest().getRouteWeight()) > 0.000001)
            logger.error("Too big weight difference for SOD. " + locStr + infoStr);
    }
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) CHGraph(com.graphhopper.storage.CHGraph) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse)

Example 15 with GHResponse

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

the class RoundTripRoutingTemplateTest method lookup_throwsIfNumberOfGivenPointsNotOne.

@Test(expected = IllegalArgumentException.class)
public void lookup_throwsIfNumberOfGivenPointsNotOne() {
    RoundTripRoutingTemplate routingTemplate = new RoundTripRoutingTemplate(new GHRequest(Collections.singletonList(ghPoint1)), new GHResponse(), null, 1);
    routingTemplate.lookup(Arrays.asList(ghPoint1, ghPoint2), carFE);
}
Also used : 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