use of com.graphhopper.storage.Directory in project graphhopper by graphhopper.
the class EncodingManager method create.
/**
* Create the EncodingManager from the provided GraphHopper location. Throws an
* IllegalStateException if it fails. Used if no EncodingManager specified on load.
*/
public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) {
Directory dir = new RAMDirectory(ghLoc, true);
StorableProperties properties = new StorableProperties(dir);
if (!properties.loadExisting())
throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation());
// check encoding for compatibility
properties.checkVersions(false);
String acceptStr = properties.get("graph.flag_encoders");
if (acceptStr.isEmpty())
throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation());
int bytesForFlags = 4;
if ("8".equals(properties.get("graph.bytes_for_flags")))
bytesForFlags = 8;
return new EncodingManager(factory, acceptStr, bytesForFlags);
}
use of com.graphhopper.storage.Directory in project graphhopper by graphhopper.
the class LocationIndexTreeTest method createIndexNoPrepare.
public LocationIndexTree createIndexNoPrepare(Graph g, int resolution) {
Directory dir = new RAMDirectory(location);
LocationIndexTree tmpIDX = new LocationIndexTree(g, dir);
tmpIDX.setResolution(resolution);
return tmpIDX;
}
use of com.graphhopper.storage.Directory in project graphhopper by graphhopper.
the class RoutingAlgorithmIT method testPerformance.
@Test
public void testPerformance() throws IOException {
int N = 10;
int noJvmWarming = N / 4;
Random rand = new Random(0);
final EncodingManager eManager = new EncodingManager("car");
final GraphHopperStorage graph = new GraphBuilder(eManager).create();
String bigFile = "10000EWD.txt.gz";
new PrinctonReader(graph).setStream(new GZIPInputStream(PrinctonReader.class.getResourceAsStream(bigFile))).read();
GraphHopper hopper = new GraphHopper() {
{
setCHEnabled(false);
setEncodingManager(eManager);
loadGraph(graph);
}
@Override
protected LocationIndex createLocationIndex(Directory dir) {
return new LocationIndexTree(graph, dir);
}
};
Collection<AlgoHelperEntry> prepares = createAlgos(hopper, new HintsMap().setWeighting("shortest").setVehicle("car"), TraversalMode.NODE_BASED);
for (AlgoHelperEntry entry : prepares) {
StopWatch sw = new StopWatch();
for (int i = 0; i < N; i++) {
int node1 = Math.abs(rand.nextInt(graph.getNodes()));
int node2 = Math.abs(rand.nextInt(graph.getNodes()));
RoutingAlgorithm d = entry.createRoutingFactory().createAlgo(graph, entry.getAlgorithmOptions());
if (i >= noJvmWarming)
sw.start();
Path p = d.calcPath(node1, node2);
// avoid jvm optimization => call p.distance
if (i >= noJvmWarming && p.getDistance() > -1)
sw.stop();
// System.out.println("#" + i + " " + name + ":" + sw.getSeconds() + " " + p.nodes());
}
float perRun = sw.stop().getSeconds() / ((float) (N - noJvmWarming));
System.out.println("# " + getClass().getSimpleName() + " " + entry + ":" + sw.stop().getSeconds() + ", per run:" + perRun);
assertTrue("speed to low!? " + perRun + " per run", perRun < 0.08);
}
}
Aggregations