use of com.graphhopper.routing.lm.PrepareLandmarks in project graphhopper by graphhopper.
the class DefaultModule method createGraphHopper.
/**
* @return an initialized GraphHopper instance
*/
protected GraphHopper createGraphHopper(CmdArgs args) {
GraphHopper tmp = new GraphHopperOSM() {
@Override
protected void loadOrPrepareLM() {
if (!getLMFactoryDecorator().isEnabled() || getLMFactoryDecorator().getPreparations().isEmpty())
return;
try {
String location = args.get(Parameters.Landmark.PREPARE + "split_area_location", "");
Reader reader = location.isEmpty() ? new InputStreamReader(LandmarkStorage.class.getResource("map.geo.json").openStream()) : new FileReader(location);
JsonFeatureCollection jsonFeatureCollection = new GHJsonBuilder().create().fromJson(reader, JsonFeatureCollection.class);
if (!jsonFeatureCollection.getFeatures().isEmpty()) {
SpatialRuleLookup ruleLookup = new SpatialRuleLookupBuilder().build("country", new SpatialRuleLookupBuilder.SpatialRuleDefaultFactory(), jsonFeatureCollection, getGraphHopperStorage().getBounds(), 0.1, true);
for (PrepareLandmarks prep : getLMFactoryDecorator().getPreparations()) {
prep.setSpatialRuleLookup(ruleLookup);
}
}
} catch (IOException ex) {
logger.error("Problem while reading border map GeoJSON. Skipping this.", ex);
}
super.loadOrPrepareLM();
}
}.forServer().init(args);
String location = args.get("spatial_rules.location", "");
if (!location.isEmpty()) {
if (!tmp.getEncodingManager().supports(("generic"))) {
logger.warn("spatial_rules.location was specified but 'generic' encoder is missing to utilize the index");
} else
try {
SpatialRuleLookup index = buildIndex(new FileReader(location), tmp.getGraphHopperStorage().getBounds());
if (index != null) {
logger.info("Set spatial rule lookup with " + index.size() + " rules");
((DataFlagEncoder) tmp.getEncodingManager().getEncoder("generic")).setSpatialRuleLookup(index);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
tmp.importOrLoad();
logger.info("loaded graph at:" + tmp.getGraphHopperLocation() + ", data_reader_file:" + tmp.getDataReaderFile() + ", flag_encoders:" + tmp.getEncodingManager() + ", " + tmp.getGraphHopperStorage().toDetailsString());
return tmp;
}
use of com.graphhopper.routing.lm.PrepareLandmarks in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testMultipleLMPreparationsInParallel.
@Test
public void testMultipleLMPreparationsInParallel() {
HashMap<String, Integer> landmarkCount = new HashMap<String, Integer>();
// try all parallelization modes
for (int threadCount = 1; threadCount < 6; threadCount++) {
EncodingManager em = new EncodingManager(Arrays.asList(new CarFlagEncoder(), new MotorcycleFlagEncoder(), new MountainBikeFlagEncoder(), new RacingBikeFlagEncoder(), new FootFlagEncoder()), 8);
GraphHopper tmpGH = new GraphHopperOSM().setStoreOnFlush(false).setCHEnabled(false).setEncodingManager(em).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
tmpGH.getLMFactoryDecorator().addWeighting("fastest").setEnabled(true).setPreparationThreads(threadCount);
tmpGH.importOrLoad();
assertEquals(5, tmpGH.getLMFactoryDecorator().getPreparations().size());
for (PrepareLandmarks prepLM : tmpGH.getLMFactoryDecorator().getPreparations()) {
assertTrue("Preparation wasn't run! [" + threadCount + "]", prepLM.isPrepared());
String name = AbstractWeighting.weightingToFileName(prepLM.getWeighting());
Integer singleThreadShortcutCount = landmarkCount.get(name);
if (singleThreadShortcutCount == null)
landmarkCount.put(name, prepLM.getSubnetworksWithLandmarks());
else
assertEquals((int) singleThreadShortcutCount, prepLM.getSubnetworksWithLandmarks());
String keyError = Parameters.Landmark.PREPARE + "error." + name;
String valueError = tmpGH.getGraphHopperStorage().getProperties().get(keyError);
assertTrue("Properties for " + name + " should NOT contain error " + valueError + " [" + threadCount + "]", valueError.isEmpty());
String key = Parameters.Landmark.PREPARE + "date." + name;
String value = tmpGH.getGraphHopperStorage().getProperties().get(key);
assertTrue("Properties for " + name + " did NOT contain finish date [" + threadCount + "]", !value.isEmpty());
}
tmpGH.close();
}
}
Aggregations