Search in sources :

Example 6 with LocationIndexTree

use of com.graphhopper.storage.index.LocationIndexTree in project graphhopper by graphhopper.

the class GraphHopperGtfs method createOrLoadIndex.

public static LocationIndex createOrLoadIndex(GHDirectory directory, GraphHopperStorage graphHopperStorage, PtFlagEncoder flagEncoder) {
    final EverythingButPt everythingButPt = new EverythingButPt(flagEncoder);
    Graph walkNetwork = GraphSupport.filteredView(graphHopperStorage, everythingButPt);
    LocationIndex locationIndex = new LocationIndexTree(walkNetwork, directory);
    if (!locationIndex.loadExisting()) {
        locationIndex.prepareIndex();
    }
    return locationIndex;
}
Also used : QueryGraph(com.graphhopper.routing.QueryGraph) LocationIndex(com.graphhopper.storage.index.LocationIndex) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree)

Example 7 with LocationIndexTree

use of com.graphhopper.storage.index.LocationIndexTree 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 PrincetonReader(graph).setStream(new GZIPInputStream(PrincetonReader.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) AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) HintsMap(com.graphhopper.routing.util.HintsMap) PrincetonReader(com.graphhopper.reader.PrincetonReader) 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) GraphBuilder(com.graphhopper.storage.GraphBuilder) Directory(com.graphhopper.storage.Directory) Test(org.junit.Test)

Example 8 with LocationIndexTree

use of com.graphhopper.storage.index.LocationIndexTree in project graphhopper by graphhopper.

the class GraphEdgeIdFinderTest method testParseStringHints.

@Test
public void testParseStringHints() {
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = new EncodingManager(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    // 0-1-2
    // | |
    // 3-4
    graph.edge(0, 1, 1, true);
    graph.edge(1, 2, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(0, 3, 1, true);
    graph.edge(1, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
    LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
    GraphEdgeIdFinder graphFinder = new GraphEdgeIdFinder(graph, locationIndex);
    GraphEdgeIdFinder.BlockArea blockArea = graphFinder.parseBlockArea("0.01,0.005,1", new DefaultEdgeFilter(encoder), 1000 * 1000);
    GHIntHashSet blockedEdges = new GHIntHashSet();
    blockedEdges.add(0);
    assertEquals(blockedEdges, blockArea.blockedEdges);
    List<Shape> blockedShapes = new ArrayList<>();
    assertEquals(blockedShapes, blockArea.blockedShapes);
    // big area converts into shapes
    graphFinder = new GraphEdgeIdFinder(graph, locationIndex);
    blockArea = graphFinder.parseBlockArea("0,0,1000", new DefaultEdgeFilter(encoder), 1000 * 1000);
    blockedEdges.clear();
    assertEquals(blockedEdges, blockArea.blockedEdges);
    blockedShapes.add(new Circle(0, 0, 1000));
    assertEquals(blockedShapes, blockArea.blockedShapes);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) Circle(com.graphhopper.util.shapes.Circle) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) Shape(com.graphhopper.util.shapes.Shape) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ArrayList(java.util.ArrayList) LocationIndex(com.graphhopper.storage.index.LocationIndex) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Example 9 with LocationIndexTree

use of com.graphhopper.storage.index.LocationIndexTree in project graphhopper by graphhopper.

the class AbstractRoutingAlgorithmTester method calcPathViaQuery.

Path calcPathViaQuery(Weighting weighting, GraphHopperStorage ghStorage, double fromLat, double fromLon, double toLat, double toLon) {
    LocationIndex index = new LocationIndexTree(ghStorage, new RAMDirectory());
    index.prepareIndex();
    QueryResult from = index.findClosest(fromLat, fromLon, EdgeFilter.ALL_EDGES);
    QueryResult to = index.findClosest(toLat, toLon, EdgeFilter.ALL_EDGES);
    // correct order for CH: in factory do prepare and afterwards wrap in query graph
    AlgorithmOptions opts = AlgorithmOptions.start().weighting(weighting).build();
    RoutingAlgorithmFactory factory = createFactory(ghStorage, opts);
    QueryGraph qGraph = new QueryGraph(getGraph(ghStorage, weighting)).lookup(from, to);
    return factory.createAlgo(qGraph, opts).calcPath(from.getClosestNode(), to.getClosestNode());
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) LocationIndex(com.graphhopper.storage.index.LocationIndex) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree)

Example 10 with LocationIndexTree

use of com.graphhopper.storage.index.LocationIndexTree in project graphhopper by graphhopper.

the class GraphHopper method createLocationIndex.

protected LocationIndex createLocationIndex(Directory dir) {
    LocationIndexTree tmpIndex = new LocationIndexTree(ghStorage, dir);
    tmpIndex.setResolution(preciseIndexResolution);
    tmpIndex.setMaxRegionSearch(maxRegionSearch);
    if (!tmpIndex.loadExisting()) {
        ensureWriteAccess();
        tmpIndex.prepareIndex();
    }
    return tmpIndex;
}
Also used : LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree)

Aggregations

LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)10 LocationIndex (com.graphhopper.storage.index.LocationIndex)8 Test (org.junit.Test)6 QueryResult (com.graphhopper.storage.index.QueryResult)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 GHRequest (com.graphhopper.GHRequest)2 GHResponse (com.graphhopper.GHResponse)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 Directory (com.graphhopper.storage.Directory)2 RAMDirectory (com.graphhopper.storage.RAMDirectory)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 GraphHopper (com.graphhopper.GraphHopper)1 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)1 JsonFeatureConverter (com.graphhopper.json.JsonFeatureConverter)1 PrincetonReader (com.graphhopper.reader.PrincetonReader)1 OSMReader (com.graphhopper.reader.osm.OSMReader)1