use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class Measurement method start.
// creates properties file in the format key=value
// Every value is one y-value in a separate diagram with an identical x-value for every Measurement.start call
void start(CmdArgs args) {
String graphLocation = args.get("graph.location", "");
String propLocation = args.get("measurement.location", "");
if (isEmpty(propLocation))
propLocation = "measurement" + new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss").format(new Date()) + ".properties";
seed = args.getLong("measurement.seed", 123);
String gitCommit = args.get("measurement.gitinfo", "");
int count = args.getInt("measurement.count", 5000);
GraphHopper hopper = new GraphHopperOSM() {
@Override
protected void prepareCH() {
StopWatch sw = new StopWatch().start();
super.prepareCH();
put(Parameters.CH.PREPARE + "time", sw.stop().getTime());
int edges = getGraphHopperStorage().getAllEdges().getMaxId();
if (getCHFactoryDecorator().hasWeightings()) {
Weighting weighting = getCHFactoryDecorator().getWeightings().get(0);
int edgesAndShortcuts = getGraphHopperStorage().getGraph(CHGraph.class, weighting).getAllEdges().getMaxId();
put(Parameters.CH.PREPARE + "shortcuts", edgesAndShortcuts - edges);
}
}
@Override
protected DataReader importData() throws IOException {
StopWatch sw = new StopWatch().start();
DataReader dr = super.importData();
put("graph.import_time", sw.stop().getSeconds());
return dr;
}
};
hopper.init(args).forDesktop();
hopper.getCHFactoryDecorator().setDisablingAllowed(true);
hopper.getLMFactoryDecorator().setDisablingAllowed(true);
hopper.importOrLoad();
GraphHopperStorage g = hopper.getGraphHopperStorage();
String vehicleStr = args.get("graph.flag_encoders", "car");
FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicleStr);
StopWatch sw = new StopWatch().start();
try {
maxNode = g.getNodes();
boolean isCH = false;
boolean isLM = false;
GHBitSet allowedEdges = printGraphDetails(g, vehicleStr);
printMiscUnitPerfTests(g, isCH, encoder, count * 100, allowedEdges);
printLocationIndexQuery(g, hopper.getLocationIndex(), count);
printTimeOfRouteQuery(hopper, isCH, isLM, count / 20, "routing", vehicleStr, true, -1, true);
if (hopper.getLMFactoryDecorator().isEnabled()) {
System.gc();
isLM = true;
int activeLMCount = 12;
for (; activeLMCount > 3; activeLMCount -= 4) {
printTimeOfRouteQuery(hopper, isCH, isLM, count / 4, "routingLM" + activeLMCount, vehicleStr, true, activeLMCount, true);
}
// compareRouting(hopper, vehicleStr, count / 5);
}
if (hopper.getCHFactoryDecorator().isEnabled()) {
isCH = true;
// compareCHWithAndWithoutSOD(hopper, vehicleStr, count/5);
if (hopper.getLMFactoryDecorator().isEnabled()) {
isLM = true;
System.gc();
// try just one constellation, often ~4-6 is best
int lmCount = 5;
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCHLM" + lmCount, vehicleStr, true, lmCount, true);
}
isLM = false;
System.gc();
Weighting weighting = hopper.getCHFactoryDecorator().getWeightings().get(0);
CHGraph lg = g.getGraph(CHGraph.class, weighting);
fillAllowedEdges(lg.getAllEdges(), allowedEdges);
printMiscUnitPerfTests(lg, isCH, encoder, count * 100, allowedEdges);
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH", vehicleStr, true, -1, true);
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_sod", vehicleStr, true, -1, false);
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_instr", vehicleStr, false, -1, true);
}
logger.info("store into " + propLocation);
} catch (Exception ex) {
logger.error("Problem while measuring " + graphLocation, ex);
put("error", ex.toString());
} finally {
put("measurement.gitinfo", gitCommit);
put("measurement.count", count);
put("measurement.seed", seed);
put("measurement.time", sw.stop().getTime());
System.gc();
put("measurement.totalMB", getTotalMB());
put("measurement.usedMB", getUsedMB());
try {
store(new FileWriter(propLocation), "measurement finish, " + new Date().toString() + ", " + Constants.BUILD_DATE);
} catch (IOException ex) {
logger.error("Problem while storing properties " + graphLocation + ", " + propLocation, ex);
}
}
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GraphHopperModule method createGraphHopper.
@Provides
@Singleton
GraphHopper createGraphHopper(CmdArgs args) {
GraphHopper graphHopper = new GraphHopperOSM(SpatialRuleLookupHelper.createLandmarkSplittingFeatureCollection(args.get(Parameters.Landmark.PREPARE + "split_area_location", ""))).forServer();
SpatialRuleLookupHelper.buildAndInjectSpatialRuleIntoGH(graphHopper, args);
graphHopper.init(args);
return graphHopper;
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GraphHopperStorageLMTest method testLoad.
@Test
public void testLoad() {
String defaultGraphLoc = "./target/ghstorage_lm";
Helper.removeDir(new File(defaultGraphLoc));
CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager(carFlagEncoder);
GraphHopperStorage 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(carFlagEncoder.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(carFlagEncoder.handleWayTags(way_1_2, 1, 0));
graph.flush();
graph.close();
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false);
hopper.getLMFactoryDecorator().setEnabled(true).setWeightingsAsStrings(Arrays.asList("fastest"));
// does lm preparation
hopper.importOrLoad();
EncodingManager em = hopper.getEncodingManager();
assertNotNull(em);
assertEquals(1, em.fetchEdgeEncoders().size());
assertEquals(16, hopper.getLMFactoryDecorator().getLandmarks());
hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false);
hopper.getLMFactoryDecorator().setEnabled(true).setWeightingsAsStrings(Arrays.asList("fastest"));
// just loads the LM data
hopper.importOrLoad();
assertEquals(1, em.fetchEdgeEncoders().size());
assertEquals(16, hopper.getLMFactoryDecorator().getLandmarks());
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GraphHopperLandmarksIT method testQueries.
@Test
public void testQueries() throws Exception {
JsonNode json = query("point=55.99022,29.129734&point=56.001069,29.150848", 200);
JsonNode path = json.get("paths").get(0);
double distance = path.get("distance").asDouble();
assertEquals("distance wasn't correct:" + distance, 1870, distance, 100);
json = query("point=55.99022,29.129734&point=56.001069,29.150848&ch.disable=true", 200);
distance = json.get("paths").get(0).get("distance").asDouble();
assertEquals("distance wasn't correct:" + distance, 1870, distance, 100);
GraphHopper hopper = getInstance(GraphHopper.class);
hopper.getLMFactoryDecorator().setDisablingAllowed(true);
json = query("point=55.99022,29.129734&point=56.001069,29.150848&ch.disable=true&lm.disable=true", 200);
distance = json.get("paths").get(0).get("distance").asDouble();
assertEquals("distance wasn't correct:" + distance, 1870, distance, 100);
hopper.getLMFactoryDecorator().setDisablingAllowed(false);
}
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;
}
Aggregations