use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.
the class PathBidirRefTest method testExtract.
@Test
public void testExtract() {
Graph g = createGraph();
g.edge(1, 2, 10, true);
PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
EdgeIterator iter = explorer.setBaseNode(1);
iter.next();
pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 0);
pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 10);
pw.edgeTo = new SPTEntry(EdgeIterator.NO_EDGE, 2, 0);
Path p = pw.extract();
assertEquals(Helper.createTList(1, 2), p.calcNodes());
assertEquals(10, p.getDistance(), 1e-4);
}
use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.
the class GraphHopperAPITest method testConcurrentGraphChange.
@Test
public void testConcurrentGraphChange() throws InterruptedException {
final GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
initGraph(graph);
graph.edge(1, 2, 10, true);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger checkPointCounter = new AtomicInteger(0);
final GraphHopper graphHopper = new GraphHopper() {
@Override
protected ChangeGraphHelper createChangeGraphHelper(Graph graph, LocationIndex locationIndex) {
return new ChangeGraphHelper(graph, locationIndex) {
@Override
public long applyChanges(EncodingManager em, Collection<JsonFeature> features) {
// force sleep inside the lock and let the main thread run until the lock barrier
latch.countDown();
try {
Thread.sleep(400);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
checkPointCounter.incrementAndGet();
return super.applyChanges(em, features);
}
};
}
}.setStoreOnFlush(false).setEncodingManager(encodingManager).setCHEnabled(false).loadGraph(graph);
GHResponse rsp = graphHopper.route(new GHRequest(42, 10.4, 42, 10));
assertFalse(rsp.toString(), rsp.hasErrors());
assertEquals(1800, rsp.getBest().getTime());
final List<JsonFeature> list = new ArrayList<>();
Map<String, Object> properties = new HashMap<>();
properties.put("speed", 5);
list.add(new JsonFeature("1", "bbox", new BBox(10.399, 10.4, 42.0, 42.001), null, properties));
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(new Runnable() {
@Override
public void run() {
graphHopper.changeGraph(list);
checkPointCounter.incrementAndGet();
}
});
latch.await();
assertEquals(0, checkPointCounter.get());
rsp = graphHopper.route(new GHRequest(42, 10.4, 42, 10));
assertFalse(rsp.toString(), rsp.hasErrors());
assertEquals(8400, rsp.getBest().getTime());
executorService.shutdown();
executorService.awaitTermination(3, TimeUnit.SECONDS);
assertEquals(2, checkPointCounter.get());
}
Aggregations