Search in sources :

Example 1 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testLoadingWithDifferentCHConfig_issue471.

@Test
public void testLoadingWithDifferentCHConfig_issue471() {
    // with CH should not be loadable without CH configured
    GraphHopper gh = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
    gh.importOrLoad();
    GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car"));
    try {
        gh.load(ghLoc);
        assertTrue(false);
    } catch (Exception ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("Configured graph.ch.weightings:"));
    }
    Helper.removeDir(new File(ghLoc));
    // without CH should not be loadable with CH enabled
    gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
    gh.importOrLoad();
    rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car"));
    try {
        gh.load(ghLoc);
        assertTrue(false);
    } catch (Exception ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("Configured graph.ch.weightings:"));
    }
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testLoadOSMNoCH.

@Test
public void testLoadOSMNoCH() {
    GraphHopper gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
    gh.importOrLoad();
    assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
    GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car"));
    assertTrue(gh.load(ghLoc));
    rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm).init(new CmdArgs().put("graph.flag_encoders", "car").put(Parameters.CH.PREPARE + "weightings", "no"));
    assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
    gh.close();
}
Also used : CmdArgs(com.graphhopper.util.CmdArgs) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 3 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testWayReferencesNotExistingAdjNode.

@Test
public void testWayReferencesNotExistingAdjNode() {
    GraphHopper hopper = new GraphHopperFacade(file4).importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    assertEquals(2, graph.getNodes());
    int n10 = AbstractGraphStorageTester.getIdOf(graph, 51.2492152);
    int n30 = AbstractGraphStorageTester.getIdOf(graph, 51.2);
    assertEquals(GHUtility.asSet(n30), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n10)));
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 4 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testWithBounds.

@Test
public void testWithBounds() {
    GraphHopper hopper = new GraphHopperFacade(file1) {

        @Override
        protected DataReader createReader(GraphHopperStorage tmpGraph) {
            return new OSMReader(tmpGraph) {

                @Override
                public boolean isInBounds(ReaderNode node) {
                    return node.getLat() > 49 && node.getLon() > 8;
                }
            };
        }
    };
    hopper.importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    assertEquals(4, graph.getNodes());
    int n10 = AbstractGraphStorageTester.getIdOf(graph, 51.2492152);
    int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
    int n30 = AbstractGraphStorageTester.getIdOf(graph, 51.2);
    int n40 = AbstractGraphStorageTester.getIdOf(graph, 51.25);
    assertEquals(GHUtility.asSet(n20), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n10)));
    assertEquals(3, GHUtility.count(carOutExplorer.setBaseNode(n20)));
    assertEquals(GHUtility.asSet(n20), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n30)));
    EdgeIterator iter = carOutExplorer.setBaseNode(n20);
    assertTrue(iter.next());
    assertEquals(n40, iter.getAdjNode());
    AbstractGraphStorageTester.assertPList(Helper.createPointList(), iter.fetchWayGeometry(0));
    assertTrue(iter.next());
    assertEquals(n30, iter.getAdjNode());
    assertEquals(93146.888, iter.getDistance(), 1);
    assertTrue(iter.next());
    AbstractGraphStorageTester.assertPList(Helper.createPointList(), iter.fetchWayGeometry(0));
    assertEquals(n10, iter.getAdjNode());
    assertEquals(88643, iter.getDistance(), 1);
    // get third added location => 2
    iter = carOutExplorer.setBaseNode(n30);
    assertTrue(iter.next());
    assertEquals(n20, iter.getAdjNode());
    assertEquals(93146.888, iter.getDistance(), 1);
    assertFalse(iter.next());
}
Also used : ReaderNode(com.graphhopper.reader.ReaderNode) GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 5 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class RoutingAlgorithmWithOSMIT method testMonacoParallel.

@Test
public void testMonacoParallel() throws IOException {
    System.out.println("testMonacoParallel takes a bit time...");
    String graphFile = "target/monaco-gh";
    Helper.removeDir(new File(graphFile));
    final EncodingManager encodingManager = new EncodingManager("car");
    final GraphHopper hopper = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(encodingManager).setCHEnabled(false).setWayPointMaxDistance(0).setDataReaderFile(DIR + "/monaco.osm.gz").setGraphHopperLocation(graphFile).importOrLoad();
    final Graph g = hopper.getGraphHopperStorage();
    final LocationIndex idx = hopper.getLocationIndex();
    final List<OneRun> instances = createMonacoCar();
    List<Thread> threads = new ArrayList<Thread>();
    final AtomicInteger integ = new AtomicInteger(0);
    int MAX = 100;
    final FlagEncoder carEncoder = encodingManager.getEncoder("car");
    // testing if algorithms are independent. should be. so test only two algorithms.
    // also the preparing is too costly to be called for every thread
    int algosLength = 2;
    final Weighting weighting = new ShortestWeighting(encodingManager.getEncoder("car"));
    final EdgeFilter filter = new DefaultEdgeFilter(carEncoder);
    for (int no = 0; no < MAX; no++) {
        for (int instanceNo = 0; instanceNo < instances.size(); instanceNo++) {
            String[] algos = new String[] { ASTAR, DIJKSTRA_BI };
            for (final String algoStr : algos) {
                // an algorithm is not thread safe! reuse via clear() is ONLY appropriated if used from same thread!
                final int instanceIndex = instanceNo;
                Thread t = new Thread() {

                    @Override
                    public void run() {
                        OneRun oneRun = instances.get(instanceIndex);
                        AlgorithmOptions opts = AlgorithmOptions.start().weighting(weighting).algorithm(algoStr).build();
                        testCollector.assertDistance(new AlgoHelperEntry(g, opts, idx, algoStr + "|" + weighting), oneRun.getList(idx, filter), oneRun);
                        integ.addAndGet(1);
                    }
                };
                t.start();
                threads.add(t);
            }
        }
    }
    for (Thread t : threads) {
        try {
            t.join();
        } catch (InterruptedException ex) {
            throw new RuntimeException(ex);
        }
    }
    assertEquals(MAX * algosLength * instances.size(), integ.get());
    assertEquals(testCollector.toString(), 0, testCollector.errors.size());
    hopper.close();
}
Also used : AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) ArrayList(java.util.ArrayList) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) OneRun(com.graphhopper.routing.util.TestAlgoCollector.OneRun) GraphHopper(com.graphhopper.GraphHopper) LocationIndex(com.graphhopper.storage.index.LocationIndex) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Graph(com.graphhopper.storage.Graph) Weighting(com.graphhopper.routing.weighting.Weighting) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) Test(org.junit.Test)

Aggregations

GraphHopper (com.graphhopper.GraphHopper)101 Test (org.junit.jupiter.api.Test)62 Profile (com.graphhopper.config.Profile)52 LMProfile (com.graphhopper.config.LMProfile)44 CHProfile (com.graphhopper.config.CHProfile)39 GraphHopperTest (com.graphhopper.GraphHopperTest)25 ArrayList (java.util.ArrayList)24 File (java.io.File)16 Test (org.junit.Test)11 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)10 GHRequest (com.graphhopper.GHRequest)7 GHResponse (com.graphhopper.GHResponse)7 GraphHopperConfig (com.graphhopper.GraphHopperConfig)6 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)6 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 PMap (com.graphhopper.util.PMap)6 GHPoint (com.graphhopper.util.shapes.GHPoint)5 IOException (java.io.IOException)5 Gpx (com.graphhopper.jackson.Gpx)4 MapMatching (com.graphhopper.matching.MapMatching)4