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);
}
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();
}
}
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;
}
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);
}
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);
}
Aggregations