Search in sources :

Example 36 with LMProfile

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

the class LMPreparationHandlerTest method maximumLMWeight.

@Test
public void maximumLMWeight() {
    LMPreparationHandler handler = new LMPreparationHandler();
    handler.setLMProfiles(new LMProfile("conf1").setMaximumLMWeight(65_000), new LMProfile("conf2").setMaximumLMWeight(20_000));
    FlagEncoder car = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(car);
    List<LMConfig> lmConfigs = Arrays.asList(new LMConfig("conf1", new FastestWeighting(car)), new LMConfig("conf2", new ShortestWeighting(car)));
    List<PrepareLandmarks> preparations = handler.createPreparations(lmConfigs, new GraphBuilder(em).build(), null);
    assertEquals(1, preparations.get(0).getLandmarkStorage().getFactor(), .1);
    assertEquals(0.3, preparations.get(1).getLandmarkStorage().getFactor(), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) LMProfile(com.graphhopper.config.LMProfile) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Example 37 with LMProfile

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

the class CHProfileSelectorTest method assertCHProfileSelectionError.

private String assertCHProfileSelectionError(String expectedError, List<Profile> profiles, List<CHProfile> chProfiles, String vehicle, String weighting, Boolean edgeBased, Integer uTurnCosts) {
    PMap hintsMap = createHintsMap(vehicle, weighting, edgeBased, uTurnCosts);
    try {
        new ProfileResolver(encodingManager, profiles, chProfiles, Collections.<LMProfile>emptyList()).selectProfileCH(hintsMap);
        fail("There should have been an error");
        return "";
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains(expectedError), "There should have been an error message containing:\n'" + expectedError + "'\nbut was:\n'" + e.getMessage() + "'");
        return e.getMessage();
    }
}
Also used : ProfileResolver(com.graphhopper.routing.ProfileResolver) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile)

Example 38 with LMProfile

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

the class RoutingAlgorithmWithOSMTest method createHopper.

/**
 * Creates a {@link GraphHopper} instance with some default settings for this test. The settings can
 * be adjusted before calling {@link GraphHopper#importOrLoad()}
 */
private GraphHopper createHopper(String osmFile, Profile... profiles) {
    GraphHopper hopper = new GraphHopper().setStoreOnFlush(true).setOSMFile(osmFile).setProfiles(profiles).setGraphHopperLocation(GH_LOCATION);
    hopper.getRouterConfig().setSimplifyResponse(false);
    hopper.setMinNetworkSize(0);
    hopper.getReaderConfig().setMaxWayPointDistance(0);
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profiles[0].getName()));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profiles[0].getName()));
    return hopper;
}
Also used : CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper)

Example 39 with LMProfile

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

the class LMProfileSelectorTest method singleProfile.

@Test
public void singleProfile() {
    List<Profile> profiles = Arrays.asList(fastCar);
    List<LMProfile> lmProfiles = Arrays.asList(new LMProfile("fast_car"));
    // as long as we do not request something that does not fit the existing profile we have a match
    assertProfileFound(profiles.get(0), profiles, lmProfiles, null, null, null, null);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, null, null);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, null, "fastest", null, null);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", "fastest", null, null);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", "fastest", false, null);
    // requesting edge_based when the profile is not edge_based leads to a non-match
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, null, null, true, null);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, "car", null, true, null);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, null, "fastest", true, null);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, "car", "fastest", true, null);
    // requesting u_turn_costs should not lead to a non-match
    assertProfileFound(profiles.get(0), profiles, lmProfiles, null, null, null, 54);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, null, null, false, 54);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, false, 54);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, null, "fastest", false, 54);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", "fastest", false, 54);
    // if we request something that does not fit we do not get a match
    String error = assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, "bike", null, null, null);
    assertTrue(error.contains("requested:  *|bike|turn_costs=*"), error);
    assertTrue(error.contains("available: [fastest|car|turn_costs=false]"), error);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, "car", "shortest", null, null);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, "car", null, true, null);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, null, "shortest", null, null);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, "truck", "short_fastest", null, null);
}
Also used : LMProfile(com.graphhopper.config.LMProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Example 40 with LMProfile

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

the class LMProfileSelectorTest method withAndWithoutTurnCosts.

@Test
public void withAndWithoutTurnCosts() {
    List<Profile> profiles = Arrays.asList(fastCar, fastBike, fastCarEdge, shortBikeEdge);
    List<LMProfile> lmProfiles = Arrays.asList(new LMProfile("fast_car"), new LMProfile("fast_bike"), new LMProfile("fast_car_edge"), new LMProfile("short_bike_edge"));
    // edge_based can be used to select between otherwise identical profiles
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, false, null);
    assertProfileFound(profiles.get(2), profiles, lmProfiles, "car", null, true, null);
    // in case there are two matching profiles and they are only different by turn_costs=true/false the one with
    // turn costs is preferred (just like for CH)
    assertProfileFound(profiles.get(2), profiles, lmProfiles, "car", null, null, null);
    // not being specific enough leads to multiple matching profiles error
    assertLMProfileSelectionError(MULTIPLE_MATCHES_ERROR, profiles, lmProfiles, null, "fastest", null, null);
    // we get an error if we request turn_costs that are not supported
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, "bike", "fastest", true, null);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, "bike", "shortest", false, null);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, null, "shortest", false, null);
    // vehicle&weighting are derived from the available profiles in case they are not given
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, false, null);
    assertProfileFound(profiles.get(1), profiles, lmProfiles, "bike", null, false, null);
    assertProfileFound(profiles.get(2), profiles, lmProfiles, null, "fastest", true, null);
    assertProfileFound(profiles.get(3), profiles, lmProfiles, null, "shortest", true, null);
}
Also used : LMProfile(com.graphhopper.config.LMProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Aggregations

LMProfile (com.graphhopper.config.LMProfile)48 Profile (com.graphhopper.config.Profile)41 CHProfile (com.graphhopper.config.CHProfile)33 Test (org.junit.jupiter.api.Test)24 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)15 PMap (com.graphhopper.util.PMap)12 GraphHopper (com.graphhopper.GraphHopper)10 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)6 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 File (java.io.File)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 Gpx (com.graphhopper.jackson.Gpx)3 EdgeMatch (com.graphhopper.matching.EdgeMatch)3 MapMatching (com.graphhopper.matching.MapMatching)3 MatchResult (com.graphhopper.matching.MatchResult)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3