Search in sources :

Example 36 with GraphHopperStorage

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);
}
Also used : GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 37 with GraphHopperStorage

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());
}
Also used : TurnCostExtension(com.graphhopper.storage.TurnCostExtension) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 38 with GraphHopperStorage

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();
}
Also used : GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 39 with GraphHopperStorage

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();
}
Also used : PointList(com.graphhopper.util.PointList) NodeAccess(com.graphhopper.storage.NodeAccess) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 40 with GraphHopperStorage

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());
}
Also used : ChangeGraphHelper(com.graphhopper.storage.change.ChangeGraphHelper) GraphBuilder(com.graphhopper.storage.GraphBuilder) EncodingManager(com.graphhopper.routing.util.EncodingManager) CountDownLatch(java.util.concurrent.CountDownLatch) LocationIndex(com.graphhopper.storage.index.LocationIndex) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) JsonFeature(com.graphhopper.json.geo.JsonFeature) Graph(com.graphhopper.storage.Graph) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BBox(com.graphhopper.util.shapes.BBox) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Aggregations

GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)40 Test (org.junit.Test)28 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)7 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)5 TurnCostExtension (com.graphhopper.storage.TurnCostExtension)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 RAMDirectory (com.graphhopper.storage.RAMDirectory)4 EdgeExplorer (com.graphhopper.util.EdgeExplorer)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 GraphExtension (com.graphhopper.storage.GraphExtension)3 Random (java.util.Random)3 GraphHopper (com.graphhopper.GraphHopper)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 HintsMap (com.graphhopper.routing.util.HintsMap)2 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2