use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.
the class DijkstraOneToManyTest method testWeightLimit_issue380.
@Test
public void testWeightLimit_issue380() {
GraphHopperStorage graph = createGHStorage(false);
initGraphWeightLimit(graph);
DijkstraOneToMany algo = (DijkstraOneToMany) createAlgo(graph);
algo.setWeightLimit(3);
Path p = algo.calcPath(0, 4);
assertTrue(p.isFound());
assertEquals(3.0, p.getWeight(), 1e-6);
algo = (DijkstraOneToMany) createAlgo(graph);
p = algo.calcPath(0, 3);
assertTrue(p.isFound());
assertEquals(3.0, p.getWeight(), 1e-6);
}
use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.
the class EdgeBasedRoutingAlgorithmTest method testBasicTurnRestriction.
@Test
public void testBasicTurnRestriction() {
GraphHopperStorage g = createStorage(createEncodingManager(true));
initGraph(g);
TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
initTurnRestrictions(g, tcs, carEncoder);
Path p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_2DIR).build()).calcPath(5, 1);
assertEquals(Helper.createTList(5, 2, 3, 4, 7, 6, 3, 1), p.calcNodes());
// test 7-6-5 and reverse
p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_1DIR).build()).calcPath(5, 7);
assertEquals(Helper.createTList(5, 6, 7), p.calcNodes());
p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_1DIR).build()).calcPath(7, 5);
assertEquals(Helper.createTList(7, 6, 3, 2, 5), p.calcNodes());
}
use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.
the class GraphHopperAPITest method testDisconnected179.
@Test
public void testDisconnected179() {
GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
initGraph(graph);
GraphHopper instance = new GraphHopper().setStoreOnFlush(false).setEncodingManager(encodingManager).setCHEnabled(false).loadGraph(graph);
GHResponse rsp = instance.route(new GHRequest(42, 10, 42, 10.4));
assertTrue(rsp.hasErrors());
try {
rsp.getBest().getPoints();
assertTrue(false);
} catch (Exception ex) {
}
instance.close();
}
use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.
the class GraphHopperAPITest method testLoad.
@Test
public void testLoad() {
GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
initGraph(graph);
// do further changes:
NodeAccess na = graph.getNodeAccess();
na.setNode(4, 41.9, 10.2);
graph.edge(1, 2, 10, false);
graph.edge(0, 4, 40, true);
graph.edge(4, 3, 40, true);
GraphHopper instance = new GraphHopper().setStoreOnFlush(false).setEncodingManager(encodingManager).setCHEnabled(false).loadGraph(graph);
// 3 -> 0
GHResponse rsp = instance.route(new GHRequest(42, 10.4, 42, 10));
assertFalse(rsp.hasErrors());
PathWrapper arsp = rsp.getBest();
assertEquals(80, arsp.getDistance(), 1e-6);
PointList points = arsp.getPoints();
assertEquals(42, points.getLatitude(0), 1e-5);
assertEquals(10.4, points.getLongitude(0), 1e-5);
assertEquals(41.9, points.getLatitude(1), 1e-5);
assertEquals(10.2, points.getLongitude(1), 1e-5);
assertEquals(3, points.getSize());
instance.close();
}
use of com.graphhopper.storage.GraphHopperStorage 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