use of com.graphhopper.reader.DataReader in project graphhopper by graphhopper.
the class GraphHopper method process.
/**
* Creates the graph from OSM data.
*/
private GraphHopper process(String graphHopperLocation) {
setGraphHopperLocation(graphHopperLocation);
GHLock lock = null;
try {
if (ghStorage.getDirectory().getDefaultType().isStoring()) {
lockFactory.setLockDir(new File(graphHopperLocation));
lock = lockFactory.create(fileLockName, true);
if (!lock.tryLock())
throw new RuntimeException("To avoid multiple writers we need to obtain a write lock but it failed. In " + graphHopperLocation, lock.getObtainFailedReason());
}
try {
DataReader reader = importData();
DateFormat f = createFormatter();
ghStorage.getProperties().put("datareader.import.date", f.format(new Date()));
if (reader.getDataDate() != null)
ghStorage.getProperties().put("datareader.data.date", f.format(reader.getDataDate()));
} catch (IOException ex) {
throw new RuntimeException("Cannot read file " + getDataReaderFile(), ex);
}
cleanUp();
postProcessing();
flush();
} finally {
if (lock != null)
lock.release();
}
return this;
}
use of com.graphhopper.reader.DataReader in project graphhopper by graphhopper.
the class GraphHopper method importData.
protected DataReader importData() throws IOException {
ensureWriteAccess();
if (ghStorage == null)
throw new IllegalStateException("Load graph before importing OSM data");
if (dataReaderFile == null)
throw new IllegalStateException("Couldn't load from existing folder: " + ghLocation + " but also cannot use file for DataReader as it wasn't specified!");
encodingManager.setEnableInstructions(enableInstructions);
encodingManager.setPreferredLanguage(preferredLanguage);
DataReader reader = createReader(ghStorage);
logger.info("using " + ghStorage.toString() + ", memory:" + getMemInfo());
reader.readGraph();
return reader;
}
use of com.graphhopper.reader.DataReader in project graphhopper by graphhopper.
the class Measurement method start.
// creates properties file in the format key=value
// Every value is one y-value in a separate diagram with an identical x-value for every Measurement.start call
void start(CmdArgs args) {
String graphLocation = args.get("graph.location", "");
String propLocation = args.get("measurement.location", "");
if (isEmpty(propLocation))
propLocation = "measurement" + new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss").format(new Date()) + ".properties";
seed = args.getLong("measurement.seed", 123);
String gitCommit = args.get("measurement.gitinfo", "");
int count = args.getInt("measurement.count", 5000);
GraphHopper hopper = new GraphHopperOSM() {
@Override
protected void prepareCH() {
StopWatch sw = new StopWatch().start();
super.prepareCH();
put(Parameters.CH.PREPARE + "time", sw.stop().getTime());
int edges = getGraphHopperStorage().getAllEdges().getMaxId();
if (getCHFactoryDecorator().hasWeightings()) {
Weighting weighting = getCHFactoryDecorator().getWeightings().get(0);
int edgesAndShortcuts = getGraphHopperStorage().getGraph(CHGraph.class, weighting).getAllEdges().getMaxId();
put(Parameters.CH.PREPARE + "shortcuts", edgesAndShortcuts - edges);
}
}
@Override
protected DataReader importData() throws IOException {
StopWatch sw = new StopWatch().start();
DataReader dr = super.importData();
put("graph.import_time", sw.stop().getSeconds());
return dr;
}
};
hopper.init(args).forDesktop();
hopper.getCHFactoryDecorator().setDisablingAllowed(true);
hopper.getLMFactoryDecorator().setDisablingAllowed(true);
hopper.importOrLoad();
GraphHopperStorage g = hopper.getGraphHopperStorage();
String vehicleStr = args.get("graph.flag_encoders", "car");
FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicleStr);
StopWatch sw = new StopWatch().start();
try {
maxNode = g.getNodes();
boolean isCH = false;
boolean isLM = false;
GHBitSet allowedEdges = printGraphDetails(g, vehicleStr);
printMiscUnitPerfTests(g, isCH, encoder, count * 100, allowedEdges);
printLocationIndexQuery(g, hopper.getLocationIndex(), count);
printTimeOfRouteQuery(hopper, isCH, isLM, count / 20, "routing", vehicleStr, true, -1, true);
if (hopper.getLMFactoryDecorator().isEnabled()) {
System.gc();
isLM = true;
int activeLMCount = 12;
for (; activeLMCount > 3; activeLMCount -= 4) {
printTimeOfRouteQuery(hopper, isCH, isLM, count / 4, "routingLM" + activeLMCount, vehicleStr, true, activeLMCount, true);
}
// compareRouting(hopper, vehicleStr, count / 5);
}
if (hopper.getCHFactoryDecorator().isEnabled()) {
isCH = true;
// compareCHWithAndWithoutSOD(hopper, vehicleStr, count/5);
if (hopper.getLMFactoryDecorator().isEnabled()) {
isLM = true;
System.gc();
// try just one constellation, often ~4-6 is best
int lmCount = 5;
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCHLM" + lmCount, vehicleStr, true, lmCount, true);
}
isLM = false;
System.gc();
Weighting weighting = hopper.getCHFactoryDecorator().getWeightings().get(0);
CHGraph lg = g.getGraph(CHGraph.class, weighting);
fillAllowedEdges(lg.getAllEdges(), allowedEdges);
printMiscUnitPerfTests(lg, isCH, encoder, count * 100, allowedEdges);
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH", vehicleStr, true, -1, true);
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_sod", vehicleStr, true, -1, false);
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_instr", vehicleStr, false, -1, true);
}
logger.info("store into " + propLocation);
} catch (Exception ex) {
logger.error("Problem while measuring " + graphLocation, ex);
put("error", ex.toString());
} finally {
put("measurement.gitinfo", gitCommit);
put("measurement.count", count);
put("measurement.seed", seed);
put("measurement.time", sw.stop().getTime());
System.gc();
put("measurement.totalMB", getTotalMB());
put("measurement.usedMB", getUsedMB());
try {
store(new FileWriter(propLocation), "measurement finish, " + new Date().toString() + ", " + Constants.BUILD_DATE);
} catch (IOException ex) {
logger.error("Problem while storing properties " + graphLocation + ", " + propLocation, ex);
}
}
}
Aggregations