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