use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testAllowMultipleReadingInstances.
@Test
public void testAllowMultipleReadingInstances() {
GraphHopper instance1 = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
instance1.importOrLoad();
GraphHopper instance2 = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car")).setDataReaderFile(testOsm);
instance2.load(ghLoc);
GraphHopper instance3 = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car")).setDataReaderFile(testOsm);
instance3.load(ghLoc);
instance1.close();
instance2.close();
instance3.close();
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class OSMReaderTest method testReadEleFromCustomOSM.
@Test
public void testReadEleFromCustomOSM() {
GraphHopper hopper = new GraphHopperFacade("custom-osm-ele.xml") {
@Override
protected DataReader createReader(GraphHopperStorage tmpGraph) {
return initDataReader(new OSMReader(tmpGraph) {
@Override
protected double getElevation(ReaderNode node) {
return node.getEle();
}
});
}
}.setElevation(true).importOrLoad();
Graph graph = hopper.getGraphHopperStorage();
int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
int n50 = AbstractGraphStorageTester.getIdOf(graph, 49);
EdgeIteratorState edge = GHUtility.getEdge(graph, n20, n50);
assertEquals(Helper.createPointList3D(52, 9, -10, 51.25, 9.43, 100, 49, 10, -30), edge.fetchWayGeometry(3));
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GraphHopperStorageForDataFlagEncoderTest method testStorageProperties.
@Test
public void testStorageProperties() {
graph = new GraphBuilder(encodingManager).setStore(true).setLocation(defaultGraphLoc).create();
// 0-1
ReaderWay way_0_1 = new ReaderWay(27l);
way_0_1.setTag("highway", "primary");
way_0_1.setTag("maxheight", "4.4");
graph.edge(0, 1, 1, true);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
graph.getEdgeIteratorState(0, 1).setFlags(encoder.handleWayTags(way_0_1, 1, 0));
// 1-2
ReaderWay way_1_2 = new ReaderWay(28l);
way_1_2.setTag("highway", "primary");
way_1_2.setTag("maxweight", "45");
graph.edge(1, 2, 1, true);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.02, 0.02);
graph.getEdgeIteratorState(1, 2).setFlags(encoder.handleWayTags(way_1_2, 1, 0));
// 2-0
ReaderWay way_2_0 = new ReaderWay(29l);
way_2_0.setTag("highway", "primary");
way_2_0.setTag("maxwidth", "5");
graph.edge(2, 0, 1, true);
graph.getEdgeIteratorState(2, 0).setFlags(encoder.handleWayTags(way_2_0, 1, 0));
graph.flush();
graph.close();
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false).importOrLoad();
EncodingManager em = hopper.getEncodingManager();
assertNotNull(em);
assertEquals(1, em.fetchEdgeEncoders().size());
FlagEncoder flagEncoder = em.fetchEdgeEncoders().get(0);
assertTrue(flagEncoder instanceof DataFlagEncoder);
DataFlagEncoder dataFlagEncoder = (DataFlagEncoder) flagEncoder;
assertTrue(dataFlagEncoder.isStoreHeight());
assertTrue(dataFlagEncoder.isStoreWeight());
assertFalse(dataFlagEncoder.isStoreWidth());
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GraphHopperOSMTest method createSquareGraphInstance.
private GraphHopper createSquareGraphInstance(boolean withCH) {
CarFlagEncoder carEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager(carEncoder);
Weighting weighting = new FastestWeighting(carEncoder);
GraphHopperStorage g = new GraphHopperStorage(Collections.singletonList(weighting), new RAMDirectory(), encodingManager, false, new GraphExtension.NoOpExtension()).create(20);
// 2---3---4
// / | \
// 1----8----5
// / | /
// 0----7---6
NodeAccess na = g.getNodeAccess();
na.setNode(0, 0.000, 0.000);
na.setNode(1, 0.001, 0.000);
na.setNode(2, 0.002, 0.000);
na.setNode(3, 0.002, 0.001);
na.setNode(4, 0.002, 0.002);
na.setNode(5, 0.001, 0.002);
na.setNode(6, 0.000, 0.002);
na.setNode(7, 0.000, 0.001);
na.setNode(8, 0.001, 0.001);
g.edge(0, 1, 100, true);
g.edge(1, 2, 100, true);
g.edge(2, 3, 100, true);
g.edge(3, 4, 100, true);
g.edge(4, 5, 100, true);
g.edge(5, 6, 100, true);
g.edge(6, 7, 100, true);
g.edge(7, 0, 100, true);
g.edge(1, 8, 110, true);
g.edge(3, 8, 110, true);
g.edge(5, 8, 110, true);
g.edge(7, 8, 110, true);
GraphHopper tmp = new GraphHopperOSM().setCHEnabled(withCH).setEncodingManager(encodingManager);
tmp.getCHFactoryDecorator().setWeightingsAsStrings("fastest");
tmp.setGraphHopperStorage(g);
tmp.postProcessing();
return tmp;
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class RoutingAlgorithmWithOSMIT method runAlgo.
/**
* @param withCH if true also the CH and LM algorithms will be tested which need
* preparation and takes a bit longer
*/
Graph runAlgo(TestAlgoCollector testCollector, String osmFile, String graphFile, List<OneRun> forEveryAlgo, String importVehicles, boolean withCH, String vehicle, String weightStr, boolean is3D) {
// for different weightings we need a different storage, otherwise we would need to remove the graph folder
// everytime we come with a different weighting
// graphFile += weightStr;
AlgoHelperEntry algoEntry = null;
OneRun tmpOneRun = null;
try {
Helper.removeDir(new File(graphFile));
GraphHopper hopper = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setDataReaderFile(osmFile).setGraphHopperLocation(graphFile).setEncodingManager(new EncodingManager(importVehicles));
if (osmFile.contains("krautsand"))
hopper.setMinNetworkSize(0, 0);
// avoid that path.getDistance is too different to path.getPoint.calcDistance
hopper.setWayPointMaxDistance(0);
// always enable landmarks
hopper.getLMFactoryDecorator().addWeighting(weightStr).setEnabled(true).setDisablingAllowed(true);
if (withCH)
hopper.getCHFactoryDecorator().addWeighting(weightStr).setEnabled(true).setDisablingAllowed(true);
if (is3D)
hopper.setElevationProvider(new SRTMProvider(DIR));
hopper.importOrLoad();
TraversalMode tMode = importVehicles.contains("turn_costs=true") ? TraversalMode.EDGE_BASED_2DIR : TraversalMode.NODE_BASED;
FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicle);
HintsMap hints = new HintsMap().setWeighting(weightStr).setVehicle(vehicle);
Collection<AlgoHelperEntry> prepares = RoutingAlgorithmIT.createAlgos(hopper, hints, tMode);
EdgeFilter edgeFilter = new DefaultEdgeFilter(encoder);
for (AlgoHelperEntry entry : prepares) {
algoEntry = entry;
LocationIndex idx = entry.getIdx();
for (OneRun oneRun : forEveryAlgo) {
tmpOneRun = oneRun;
List<QueryResult> list = oneRun.getList(idx, edgeFilter);
testCollector.assertDistance(algoEntry, list, oneRun);
}
}
return hopper.getGraphHopperStorage();
} catch (Exception ex) {
if (algoEntry == null)
throw new RuntimeException("cannot handle file " + osmFile + ", " + ex.getMessage(), ex);
throw new RuntimeException("cannot handle " + algoEntry.toString() + ", for " + tmpOneRun + ", file " + osmFile + ", " + ex.getMessage(), ex);
} finally {
// Helper.removeDir(new File(graphFile));
}
}
Aggregations