use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class LMPreparationHandler method setLMProfiles.
/**
* Enables the use of landmarks to reduce query times.
*/
public LMPreparationHandler setLMProfiles(Collection<LMProfile> lmProfiles) {
this.lmProfiles.clear();
this.maximumWeights.clear();
for (LMProfile profile : lmProfiles) {
if (profile.usesOtherPreparation())
continue;
maximumWeights.put(profile.getProfile(), profile.getMaximumLMWeight());
}
this.lmProfiles.addAll(lmProfiles);
return this;
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class LMProfileSelectorTest method multipleProfiles.
@Test
public void multipleProfiles() {
List<Profile> profiles = Arrays.asList(fastCar, fastBike);
List<LMProfile> lmProfiles = Arrays.asList(new LMProfile("fast_car"), new LMProfile("fast_bike"));
assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, null, null);
assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", "fastest", null, null);
assertProfileFound(profiles.get(1), profiles, lmProfiles, "bike", null, null, null);
assertProfileFound(profiles.get(1), profiles, lmProfiles, "bike", "fastest", null, null);
// not specific enough
String error = assertLMProfileSelectionError(MULTIPLE_MATCHES_ERROR, profiles, lmProfiles, null, "fastest", null, null);
assertTrue(error.contains("requested: fastest|*|turn_costs=*"), error);
assertTrue(error.contains("matched: [fastest|car|turn_costs=false, fastest|bike|turn_costs=false]"), error);
assertTrue(error.contains("available: [fastest|car|turn_costs=false, fastest|bike|turn_costs=false]"), error);
assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, null, "shortest", null, null);
// u_turn_costs is set, but lm should not really care
assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, null, 54);
assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, false, 64);
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class LMProfileSelectorTest method assertProfileFound.
private void assertProfileFound(Profile expectedProfile, List<Profile> profiles, List<LMProfile> lmProfiles, String vehicle, String weighting, Boolean edgeBased, Integer uTurnCosts) {
PMap hintsMap = createHintsMap(vehicle, weighting, edgeBased, uTurnCosts);
try {
Profile selectedProfile = new ProfileResolver(encodingManager, profiles, Collections.<CHProfile>emptyList(), lmProfiles).selectProfileLM(hintsMap);
assertEquals(expectedProfile, selectedProfile);
} catch (IllegalArgumentException e) {
fail("no profile found\nexpected: " + expectedProfile + "\nerror: " + e.getMessage());
}
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class CHProfileSelectorTest method assertProfileFound.
private void assertProfileFound(Profile expectedProfile, List<Profile> profiles, List<CHProfile> chProfiles, String vehicle, String weighting, Boolean edgeBased, Integer uTurnCosts) {
PMap hintsMap = createHintsMap(vehicle, weighting, edgeBased, uTurnCosts);
try {
Profile selectedProfile = new ProfileResolver(encodingManager, profiles, chProfiles, Collections.<LMProfile>emptyList()).selectProfileCH(hintsMap);
assertEquals(expectedProfile, selectedProfile);
} catch (IllegalArgumentException e) {
fail("no profile found\nexpected: " + expectedProfile + "\nerror: " + e.getMessage());
}
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class GraphHopperStorageLMTest method testLoad.
@Test
public void testLoad() {
String defaultGraphLoc = "./target/ghstorage_lm";
Helper.removeDir(new File(defaultGraphLoc));
CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager.Builder().add(carFlagEncoder).add(Subnetwork.create("my_profile")).build();
GraphHopperStorage graph = GraphBuilder.start(encodingManager).setRAM(defaultGraphLoc, true).create();
// 0-1
ReaderWay way_0_1 = new ReaderWay(27l);
way_0_1.setTag("highway", "primary");
way_0_1.setTag("maxheight", "4.4");
GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(0, 1).setDistance(1));
updateDistancesFor(graph, 0, 0.00, 0.00);
updateDistancesFor(graph, 1, 0.01, 0.01);
graph.getEdgeIteratorState(0, 1).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_0_1));
// 1-2
ReaderWay way_1_2 = new ReaderWay(28l);
way_1_2.setTag("highway", "primary");
way_1_2.setTag("maxweight", "45");
GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(1, 2).setDistance(1));
updateDistancesFor(graph, 2, 0.02, 0.02);
graph.getEdgeIteratorState(1, 2).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_1_2));
graph.flush();
graph.close();
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
// does lm preparation
hopper.importOrLoad();
EncodingManager em = hopper.getEncodingManager();
assertNotNull(em);
assertEquals(1, em.fetchEdgeEncoders().size());
assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
// just loads the LM data
hopper.importOrLoad();
assertEquals(1, em.fetchEdgeEncoders().size());
assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
}
Aggregations