Search in sources :

Example 61 with CHProfile

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

the class GraphHopperTest method testTurnCostsOnOffCH.

@Test
public void testTurnCostsOnOffCH() {
    final String profile1 = "profile_turn_costs";
    final String profile2 = "profile_no_turn_costs";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MOSCOW).setProfiles(Arrays.asList(new Profile(profile1).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true), new Profile(profile2).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(false))).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile1), new CHProfile(profile2));
    hopper.importOrLoad();
    GHRequest req = new GHRequest(55.813357, 37.5958585, 55.811042, 37.594689);
    req.setProfile("profile_no_turn_costs");
    assertEquals(400, hopper.route(req).getBest().getDistance(), 1);
    req.setProfile("profile_turn_costs");
    assertEquals(1044, hopper.route(req).getBest().getDistance(), 1);
}
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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with CHProfile

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

the class GraphHopperTest method testMultipleVehiclesWithCH.

@Test
public void testMultipleVehiclesWithCH() {
    final String profile1 = "profile1";
    final String profile2 = "profile2";
    final String vehicle1 = "bike";
    final String vehicle2 = "car";
    final String weighting = "fastest";
    List<Profile> profiles = asList(new Profile(profile1).setVehicle(vehicle1).setWeighting(weighting), new Profile(profile2).setVehicle(vehicle2).setWeighting(weighting));
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(profiles).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile1), new CHProfile(profile2));
    hopper.importOrLoad();
    String str = hopper.getEncodingManager().toString();
    GHResponse rsp = hopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setProfile("profile2"));
    ResponsePath res = rsp.getBest();
    assertFalse(rsp.hasErrors(), "car routing for " + str + " should not have errors:" + rsp.getErrors());
    assertEquals(207, res.getTime() / 1000f, 1);
    assertEquals(2837, res.getDistance(), 1);
    rsp = hopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setProfile("profile1"));
    res = rsp.getBest();
    assertFalse(rsp.hasErrors(), "bike routing for " + str + " should not have errors:" + rsp.getErrors());
    assertEquals(511, res.getTime() / 1000f, 1);
    assertEquals(2481, res.getDistance(), 1);
    rsp = hopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setProfile("profile3"));
    assertTrue(rsp.hasErrors(), "only profile1 and profile2 exist, request for profile3 should fail");
    GHRequest req = new GHRequest().addPoint(new GHPoint(43.741069, 7.426854)).addPoint(new GHPoint(43.744445, 7.429483)).setHeadings(Arrays.asList(0., 190.)).setProfile("profile1");
    rsp = hopper.route(req);
    assertTrue(rsp.hasErrors(), "heading not allowed for CH enabled graph");
}
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 63 with CHProfile

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

the class GraphHopperProfileTest method duplicateCHProfile_error.

@Test
public void duplicateCHProfile_error() {
    final GraphHopper hopper = createHopper();
    hopper.setProfiles(new Profile("profile").setVehicle("car"));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("profile"), new CHProfile("profile"));
    assertIllegalArgument(hopper::load, "Duplicate CH reference to profile 'profile'");
}
Also used : CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Example 64 with CHProfile

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

the class GraphHopperProfileTest method chProfileDoesNotExist_error.

@Test
public void chProfileDoesNotExist_error() {
    final GraphHopper hopper = createHopper();
    hopper.setProfiles(new Profile("profile1").setVehicle("car"));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("other_profile"));
    assertIllegalArgument(hopper::load, "CH profile references unknown profile 'other_profile'");
}
Also used : CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Example 65 with CHProfile

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

the class GraphHopperTest method testPreparedProfileNotAvailable.

@Test
public void testPreparedProfileNotAvailable() {
    final String profile1 = "fast_profile";
    final String profile2 = "short_fast_profile";
    final String vehicle = "car";
    final String weighting1 = "fastest";
    final String weighting2 = "short_fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile1).setVehicle(vehicle).setWeighting(weighting1), new Profile(profile2).setVehicle(vehicle).setWeighting(weighting2)).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile1));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profile1).setMaximumLMWeight(2000));
    hopper.importOrLoad();
    // request a profile that was not prepared
    GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profile2);
    // try with CH
    req.putHint(CH.DISABLE, false);
    req.putHint(Landmark.DISABLE, false);
    GHResponse res = hopper.route(req);
    assertTrue(res.hasErrors(), res.getErrors().toString());
    assertTrue(res.getErrors().get(0).getMessage().contains("Cannot find CH preparation for the requested profile: 'short_fast_profile'"), res.getErrors().toString());
    // try with LM
    req.putHint(CH.DISABLE, true);
    req.putHint(Landmark.DISABLE, false);
    res = hopper.route(req);
    assertTrue(res.hasErrors(), res.getErrors().toString());
    assertTrue(res.getErrors().get(0).getMessage().contains("Cannot find LM preparation for the requested profile: 'short_fast_profile'"), res.getErrors().toString());
    // falling back to non-prepared algo works
    req.putHint(CH.DISABLE, true);
    req.putHint(Landmark.DISABLE, true);
    res = hopper.route(req);
    assertFalse(res.hasErrors(), res.getErrors().toString());
    assertEquals(3587, res.getBest().getDistance(), 1);
}
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