Search in sources :

Example 1 with Directory

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);
}
Also used : StorableProperties(com.graphhopper.storage.StorableProperties) RAMDirectory(com.graphhopper.storage.RAMDirectory) RAMDirectory(com.graphhopper.storage.RAMDirectory) Directory(com.graphhopper.storage.Directory)

Example 2 with Directory

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;
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) RAMDirectory(com.graphhopper.storage.RAMDirectory) Directory(com.graphhopper.storage.Directory)

Example 3 with Directory

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);
    }
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) GraphHopper(com.graphhopper.GraphHopper) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) StopWatch(com.graphhopper.util.StopWatch) GZIPInputStream(java.util.zip.GZIPInputStream) Random(java.util.Random) PrinctonReader(com.graphhopper.reader.PrinctonReader) GraphBuilder(com.graphhopper.storage.GraphBuilder) Directory(com.graphhopper.storage.Directory) Test(org.junit.Test)

Aggregations

Directory (com.graphhopper.storage.Directory)3 RAMDirectory (com.graphhopper.storage.RAMDirectory)2 GraphHopper (com.graphhopper.GraphHopper)1 PrinctonReader (com.graphhopper.reader.PrinctonReader)1 EncodingManager (com.graphhopper.routing.util.EncodingManager)1 HintsMap (com.graphhopper.routing.util.HintsMap)1 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)1 GraphBuilder (com.graphhopper.storage.GraphBuilder)1 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)1 StorableProperties (com.graphhopper.storage.StorableProperties)1 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)1 StopWatch (com.graphhopper.util.StopWatch)1 Random (java.util.Random)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Test (org.junit.Test)1