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;
}
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);
}
}
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);
}
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());
}
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;
}
Aggregations