Search in sources :

Example 11 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM 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();
}
Also used : AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) ArrayList(java.util.ArrayList) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) OneRun(com.graphhopper.routing.util.TestAlgoCollector.OneRun) GraphHopper(com.graphhopper.GraphHopper) LocationIndex(com.graphhopper.storage.index.LocationIndex) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Graph(com.graphhopper.storage.Graph) Weighting(com.graphhopper.routing.weighting.Weighting) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) Test(org.junit.Test)

Example 12 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.

the class Import method main.

public static void main(String[] strs) throws Exception {
    CmdArgs args = CmdArgs.read(strs);
    args = CmdArgs.readFromConfigAndMerge(args, "config", "graphhopper.config");
    GraphHopper hopper = new GraphHopperOSM(SpatialRuleLookupHelper.createLandmarkSplittingFeatureCollection(args.get(Parameters.Landmark.PREPARE + "split_area_location", "")));
    SpatialRuleLookupHelper.buildAndInjectSpatialRuleIntoGH(hopper, args);
    hopper.init(args);
    hopper.importOrLoad();
    hopper.close();
}
Also used : CmdArgs(com.graphhopper.util.CmdArgs) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GraphHopper(com.graphhopper.GraphHopper)

Example 13 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM 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 14 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM 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 15 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.

the class GraphHopperIT method testSRTMWithoutTunnelInterpolation.

@Test
public void testSRTMWithoutTunnelInterpolation() throws Exception {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(importVehicles, 8));
    tmpHopper.setElevationProvider(new SRTMProvider(DIR));
    tmpHopper.importOrLoad();
    GHResponse rsp = tmpHopper.route(new GHRequest(43.74056471749763, 7.4299266210693755, 43.73790260334179, 7.427984089259056).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
    PathWrapper arsp = rsp.getBest();
    assertEquals(356.5, arsp.getDistance(), .1);
    PointList pointList = arsp.getPoints();
    assertEquals(6, pointList.getSize());
    assertTrue(pointList.is3D());
    assertEquals(20.0, pointList.getEle(0), .1);
    assertEquals(23.0, pointList.getEle(1), .1);
    assertEquals(23.0, pointList.getEle(2), .1);
    assertEquals(41.0, pointList.getEle(3), .1);
    assertEquals(19.0, pointList.getEle(4), .1);
    assertEquals(26.5, pointList.getEle(5), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider)

Aggregations

GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)26 EncodingManager (com.graphhopper.routing.util.EncodingManager)18 GraphHopper (com.graphhopper.GraphHopper)7 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)4 GHPoint (com.graphhopper.util.shapes.GHPoint)4 File (java.io.File)4 IOException (java.io.IOException)3 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 Provides (com.google.inject.Provides)1 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHJsonBuilder (com.graphhopper.json.GHJsonBuilder)1 JsonFeatureCollection (com.graphhopper.json.geo.JsonFeatureCollection)1 DataReader (com.graphhopper.reader.DataReader)1 LandmarkStorage (com.graphhopper.routing.lm.LandmarkStorage)1 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)1 SpatialRuleLookup (com.graphhopper.routing.util.spatialrules.SpatialRuleLookup)1 SpatialRuleLookupBuilder (com.graphhopper.routing.util.spatialrules.SpatialRuleLookupBuilder)1