Search in sources :

Example 56 with CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopperTest method testImportCloseAndLoad.

private void testImportCloseAndLoad(boolean ch, boolean lm, boolean sort, boolean custom) {
    final String vehicle = "foot";
    final String profileName = "profile";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setStoreOnFlush(true).setSortGraph(sort);
    Profile profile = new Profile(profileName).setVehicle(vehicle).setWeighting("fastest");
    if (custom) {
        JsonFeature area51Feature = new JsonFeature();
        area51Feature.setGeometry(new GeometryFactory().createPolygon(new Coordinate[] { new Coordinate(7.4174, 43.7345), new Coordinate(7.4198, 43.7355), new Coordinate(7.4207, 43.7344), new Coordinate(7.4174, 43.7345) }));
        CustomModel customModel = new CustomModel().setDistanceInfluence(0);
        customModel.getPriority().add(Statement.If("in_area51", Statement.Op.MULTIPLY, 0.1));
        customModel.getAreas().put("area51", area51Feature);
        profile = new CustomProfile(profileName).setCustomModel(customModel).setVehicle(vehicle);
    }
    hopper.setProfiles(profile);
    if (ch) {
        hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profileName));
    }
    if (lm) {
        hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profileName));
    }
    hopper.importAndClose();
    hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(profile).setStoreOnFlush(true).setAllowWrites(false);
    if (ch) {
        hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profileName));
    }
    if (lm) {
        hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profileName));
    }
    hopper.importOrLoad();
    if (ch) {
        GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName);
        req.putHint(CH.DISABLE, false);
        req.putHint(Landmark.DISABLE, true);
        GHResponse rsp = hopper.route(req);
        ResponsePath bestPath = rsp.getBest();
        long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
        assertNotEquals(sum, 0);
        assertTrue(sum < 155, "Too many nodes visited " + sum);
        assertEquals(3535, bestPath.getDistance(), 1);
        assertEquals(115, bestPath.getPoints().size());
    }
    if (lm) {
        GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName).setAlgorithm(Parameters.Algorithms.ASTAR_BI);
        req.putHint(CH.DISABLE, true);
        req.putHint(Landmark.DISABLE, false);
        GHResponse rsp = hopper.route(req);
        ResponsePath bestPath = rsp.getBest();
        long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
        assertNotEquals(sum, 0);
        assertTrue(sum < 125, "Too many nodes visited " + sum);
        assertEquals(3535, bestPath.getDistance(), 1);
        assertEquals(115, bestPath.getPoints().size());
    }
    // flexible
    GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName);
    req.putHint(CH.DISABLE, true);
    req.putHint(Landmark.DISABLE, true);
    GHResponse rsp = hopper.route(req);
    ResponsePath bestPath = rsp.getBest();
    long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertNotEquals(sum, 0);
    assertTrue(sum > 120, "Too few nodes visited " + sum);
    assertEquals(3535, bestPath.getDistance(), 1);
    assertEquals(115, bestPath.getPoints().size());
    hopper.close();
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Coordinate(org.locationtech.jts.geom.Coordinate) LMProfile(com.graphhopper.config.LMProfile)

Example 57 with CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopperTest method executeCHFootRoute.

private void executeCHFootRoute(boolean sort) {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "shortest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).setSortGraph(sort);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.importOrLoad();
    // same query as in testMonacoWithInstructions
    GHResponse rsp = hopper.route(new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profile));
    ResponsePath bestPath = rsp.getBest();
    // identify the number of counts to compare with none-CH foot route which had nearly 700 counts
    long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertNotEquals(sum, 0);
    assertTrue(sum < 147, "Too many nodes visited " + sum);
    assertEquals(3437.1, bestPath.getDistance(), .1);
    assertEquals(85, bestPath.getPoints().size());
    hopper.close();
}
Also used : CHProfile(com.graphhopper.config.CHProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile)

Example 58 with CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopperTest method testCHWithFiniteUTurnCosts.

@Test
public void testCHWithFiniteUTurnCosts() {
    GraphHopper h = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest").setTurnCosts(true).putHint(U_TURN_COSTS, 40));
    h.getCHPreparationHandler().setCHProfiles(new CHProfile("my_profile"));
    h.importOrLoad();
    GHPoint p = new GHPoint(43.73397, 7.414173);
    GHPoint q = new GHPoint(43.73222, 7.415557);
    GHRequest req = new GHRequest(p, q);
    req.setProfile("my_profile");
    // we force the start/target directions such that there are u-turns right after we start and right before
    // we reach the target
    req.setCurbsides(Arrays.asList("right", "right"));
    GHResponse res = h.route(req);
    assertFalse(res.hasErrors(), "routing should not fail");
    assertEquals(266.8, res.getBest().getRouteWeight(), 0.1);
    assertEquals(2116, res.getBest().getDistance(), 1);
    assertEquals(266800, res.getBest().getTime(), 1000);
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 59 with CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopperTest method testForceCurbsides.

@Test
public void testForceCurbsides() {
    final String profile = "my_profile";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper h = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true));
    h.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    h.importOrLoad();
    // depending on the curbside parameters we take very different routes
    // p
    // ---->----
    // q
    GHPoint p = new GHPoint(43.738399, 7.420782);
    GHPoint q = new GHPoint(43.737949, 7.423523);
    final String boulevard = "Boulevard de Suisse";
    final String avenue = "Avenue de la Costa";
    assertCurbsidesPathError(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_RIGHT), "Impossible curbside constraint: 'curbside=right' at point 0", true);
    assertCurbsidesPathError(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_LEFT), "Impossible curbside constraint: 'curbside=right' at point 0", true);
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_RIGHT), 463, asList(boulevard, avenue));
    assertCurbsidesPathError(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_LEFT), "Impossible curbside constraint: 'curbside=left' at point 1", true);
    // without restricting anything we get the shortest path
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_ANY, CURBSIDE_ANY), 463, asList(boulevard, avenue));
    assertCurbsidesPath(h, p, q, Collections.<String>emptyList(), 463, asList(boulevard, avenue));
    // if we set force_curbside to false impossible curbside constraints will be ignored
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_RIGHT), 463, asList(boulevard, avenue), false);
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_LEFT), 463, asList(boulevard, avenue), false);
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_RIGHT), 463, asList(boulevard, avenue), false);
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_LEFT), 463, asList(boulevard, avenue), false);
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 60 with CHProfile

use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.

the class GraphHopperTest method testIssue1960.

@Test
public void testIssue1960() {
    final String profile = "car";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MOSCOW).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profile));
    hopper.importOrLoad();
    GHRequest req = new GHRequest(55.815670, 37.604613, 55.806151, 37.617823);
    req.setProfile("car");
    req.getHints().putObject(CH.DISABLE, false).putObject(Landmark.DISABLE, true);
    ResponsePath pathCH = hopper.route(req).getBest();
    req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, false);
    ResponsePath pathLM = hopper.route(req).getBest();
    req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, true);
    ResponsePath path = hopper.route(req).getBest();
    assertEquals(1995.38, pathCH.getDistance(), 0.1);
    assertEquals(1995.38, pathLM.getDistance(), 0.1);
    assertEquals(1995.38, path.getDistance(), 0.1);
    assertEquals(149497, pathCH.getTime());
    assertEquals(149497, pathLM.getTime());
    assertEquals(149497, path.getTime());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CHProfile (com.graphhopper.config.CHProfile)66 Profile (com.graphhopper.config.Profile)63 LMProfile (com.graphhopper.config.LMProfile)58 Test (org.junit.jupiter.api.Test)39 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 PMap (com.graphhopper.util.PMap)10 GHPoint (com.graphhopper.util.shapes.GHPoint)9 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)8 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)8 GraphHopper (com.graphhopper.GraphHopper)6 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 CountryRuleFactory (com.graphhopper.routing.util.countryrules.CountryRuleFactory)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 JtsModule (com.bedatadriven.jackson.datatype.jts.JtsModule)1 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1