Search in sources :

Example 16 with GraphHopper

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);
        }
    }
}
Also used : GHBitSet(com.graphhopper.coll.GHBitSet) FileWriter(java.io.FileWriter) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GraphHopper(com.graphhopper.GraphHopper) IOException(java.io.IOException) IOException(java.io.IOException) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) DataReader(com.graphhopper.reader.DataReader) Weighting(com.graphhopper.routing.weighting.Weighting) CHGraph(com.graphhopper.storage.CHGraph) SimpleDateFormat(java.text.SimpleDateFormat)

Example 17 with GraphHopper

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;
}
Also used : GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GraphHopper(com.graphhopper.GraphHopper) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 18 with 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());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) ReaderWay(com.graphhopper.reader.ReaderWay) GraphHopper(com.graphhopper.GraphHopper) File(java.io.File) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Example 19 with GraphHopper

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);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.Test)

Example 20 with GraphHopper

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;
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) AbstractWeighting(com.graphhopper.routing.weighting.AbstractWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphHopper(com.graphhopper.GraphHopper)

Aggregations

GraphHopper (com.graphhopper.GraphHopper)42 Test (org.junit.Test)34 GHPoint (com.graphhopper.util.shapes.GHPoint)17 IOException (java.io.IOException)8 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)7 GHRequest (com.graphhopper.GHRequest)4 GHResponse (com.graphhopper.GHResponse)4 File (java.io.File)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)3 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CmdArgs (com.graphhopper.util.CmdArgs)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 JsonFeatureCollection (com.graphhopper.json.geo.JsonFeatureCollection)2 ReaderNode (com.graphhopper.reader.ReaderNode)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)2 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)2 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2