Search in sources :

Example 1 with CHGraph

use of com.graphhopper.storage.CHGraph 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 (Helper.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);
        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);
            }
        // compareRouting(hopper, vehicleStr, count / 5);
        }
        if (hopper.getCHFactoryDecorator().isEnabled()) {
            isCH = true;
            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);
            }
            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);
            printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_instr", vehicleStr, false, -1);
        }
        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", Helper.getTotalMB());
        put("measurement.usedMB", Helper.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) Date(java.util.Date) 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 2 with CHGraph

use of com.graphhopper.storage.CHGraph in project graphhopper by graphhopper.

the class Measurement method printMiscUnitPerfTests.

private void printMiscUnitPerfTests(final Graph graph, boolean isCH, final FlagEncoder encoder, int count, final GHBitSet allowedEdges) {
    final Random rand = new Random(seed);
    String description = "";
    if (isCH) {
        description = "CH";
        CHGraph lg = (CHGraph) graph;
        final CHEdgeExplorer chExplorer = lg.createEdgeExplorer(new LevelEdgeFilter(lg));
        MiniPerfTest miniPerf = new MiniPerfTest() {

            @Override
            public int doCalc(boolean warmup, int run) {
                int nodeId = rand.nextInt(maxNode);
                return GHUtility.count(chExplorer.setBaseNode(nodeId));
            }
        }.setIterations(count).start();
        print("unit_testsCH.level_edge_state_next", miniPerf);
        final CHEdgeExplorer chExplorer2 = lg.createEdgeExplorer();
        miniPerf = new MiniPerfTest() {

            @Override
            public int doCalc(boolean warmup, int run) {
                int nodeId = rand.nextInt(maxNode);
                CHEdgeIterator iter = chExplorer2.setBaseNode(nodeId);
                while (iter.next()) {
                    if (iter.isShortcut())
                        nodeId += (int) iter.getWeight();
                }
                return nodeId;
            }
        }.setIterations(count).start();
        print("unit_testsCH.get_weight", miniPerf);
    }
    EdgeFilter outFilter = new DefaultEdgeFilter(encoder, false, true);
    final EdgeExplorer outExplorer = graph.createEdgeExplorer(outFilter);
    MiniPerfTest miniPerf = new MiniPerfTest() {

        @Override
        public int doCalc(boolean warmup, int run) {
            int nodeId = rand.nextInt(maxNode);
            return GHUtility.count(outExplorer.setBaseNode(nodeId));
        }
    }.setIterations(count).start();
    print("unit_tests" + description + ".out_edge_state_next", miniPerf);
    final EdgeExplorer allExplorer = graph.createEdgeExplorer();
    miniPerf = new MiniPerfTest() {

        @Override
        public int doCalc(boolean warmup, int run) {
            int nodeId = rand.nextInt(maxNode);
            return GHUtility.count(allExplorer.setBaseNode(nodeId));
        }
    }.setIterations(count).start();
    print("unit_tests" + description + ".all_edge_state_next", miniPerf);
    final int maxEdgesId = graph.getAllEdges().getMaxId();
    miniPerf = new MiniPerfTest() {

        @Override
        public int doCalc(boolean warmup, int run) {
            while (true) {
                int edgeId = rand.nextInt(maxEdgesId);
                if (allowedEdges.contains(edgeId))
                    return graph.getEdgeIteratorState(edgeId, Integer.MIN_VALUE).getEdge();
            }
        }
    }.setIterations(count).start();
    print("unit_tests" + description + ".get_edge_state", miniPerf);
}
Also used : Random(java.util.Random) CHGraph(com.graphhopper.storage.CHGraph)

Example 3 with CHGraph

use of com.graphhopper.storage.CHGraph in project graphhopper by graphhopper.

the class CHEdgeIteratorTest method testUpdateFlags.

@Test
public void testUpdateFlags() {
    CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager(carFlagEncoder);
    FastestWeighting weighting = new FastestWeighting(carFlagEncoder);
    EdgeFilter carOutFilter = new DefaultEdgeFilter(carFlagEncoder, false, true);
    GraphHopperStorage ghStorage = new GraphBuilder(encodingManager).setCHGraph(weighting).create();
    CHGraph g = ghStorage.getGraph(CHGraph.class, weighting);
    g.edge(0, 1).setDistance(12).setFlags(carFlagEncoder.setProperties(10, true, true));
    g.edge(0, 2).setDistance(13).setFlags(carFlagEncoder.setProperties(20, true, true));
    ghStorage.freeze();
    assertEquals(2, GHUtility.count(g.getAllEdges()));
    assertEquals(1, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    EdgeIteratorState iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(1, iter.getAdjNode());
    assertEquals(carFlagEncoder.setProperties(10, true, true), iter.getFlags());
    // update setProperties
    iter.setFlags(carFlagEncoder.setProperties(20, true, false));
    assertEquals(12, iter.getDistance(), 1e-4);
    // update distance
    iter.setDistance(10);
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(0, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(carFlagEncoder.setProperties(20, true, false), iter.getFlags());
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(1, GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(1)).size());
    assertEquals(0, GHUtility.getNeighbors(g.createEdgeExplorer(carOutFilter).setBaseNode(1)).size());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CHGraph(com.graphhopper.storage.CHGraph) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

CHGraph (com.graphhopper.storage.CHGraph)3 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)2 GraphHopper (com.graphhopper.GraphHopper)1 GHBitSet (com.graphhopper.coll.GHBitSet)1 DataReader (com.graphhopper.reader.DataReader)1 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)1 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)1 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)1 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)1 EncodingManager (com.graphhopper.routing.util.EncodingManager)1 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)1 Weighting (com.graphhopper.routing.weighting.Weighting)1 GraphBuilder (com.graphhopper.storage.GraphBuilder)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Random (java.util.Random)1 Test (org.junit.Test)1