Exemple #1
0
        static void Main(string[] args)
        {
            // enable logging.
            OsmSharp.Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                Console.WriteLine(string.Format("[{0}] {1} - {2}", o, level, message));
            };
            Itinero.Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                Console.WriteLine(string.Format("[{0}] {1} - {2}", o, level, message));
            };
            _logger = new Logger("Default");

            Itinero.Osm.Vehicles.Vehicle.RegisterVehicles();

            // download and extract test-data if not already there.
            _logger.Log(TraceEventType.Information, "Downloading Luxembourg...");
            Download.DownloadLuxembourgAll();

            // TEST1: Tests building a router db for cars, contracting it and calculating routes.
            // test building a router db.
            var routerDb = Runner.GetTestBuildRouterDb(Download.LuxembourgLocal, false, false, Vehicle.Car).TestPerf("Build belgium router db for Car.");
            var router   = new Router(routerDb);

            // build profile cache.
            var profileCache = new Profiles.ProfileFactorAndSpeedCache(routerDb);

            profileCache.CalculateFor(Vehicle.Car.Fastest());
            profileCache.CalculateFor(Vehicle.Bicycle.Fastest());
            profileCache.CalculateFor(Vehicle.Pedestrian.Fastest());
            router.ProfileFactorAndSpeedCache = profileCache;

            Runner.GetTestAddContracted(routerDb, Vehicle.Car.Fastest(), true).TestPerf("Add contracted graph for Car.Fastest()");

            //using (var stream = File.Open("temp.routerdb", FileMode.Create, FileAccess.ReadWrite))
            //{
            //    routerDb.Serialize(stream);
            //    stream.Flush();
            //    stream.Close();
            //}

            //using (var stream = File.Open("temp.routerdb", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
            //{
            //    routerDb = RouterDb.Deserialize(stream);
            //}
            //router = new Router(routerDb);

            // TEST1: Test random routes.
            Runner.GetTestRandomRoutes(new Router(routerDb), Vehicle.Car.Fastest(), 100).TestPerf("Testing route calculation speed.");

            // TEST2: Tests find islands.
            Runner.GetTestIslandDetection(routerDb).TestPerf("Testing island detection.", 10);

            // TEST3: calulate isochrones.
            var polygons = Runner.GetTestIsochroneCalculation(router).TestPerf("Testing isochrone calculation.", 1);
            //var polygonsJson = polygons.ToFeatureCollection().ToGeoJson();

            // TEST4: calculate heatmaps.
            var heatmap = Runner.GetTestHeatmapCalculation(router).TestPerf("Testing heatmap calculation.", 10);

            // TEST5: calculate tree.
            var lines = Runner.GetTestTreeCalculation(router).TestPerf("Testing tree calculation.", 100);

            //var linesJson = lines.ToGeoJson();

            _logger.Log(TraceEventType.Information, "Testing finished.");
#if DEBUG
            Console.ReadLine();
#endif
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // enable logging.
            OsmSharp.Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                Console.WriteLine(string.Format("[{0}] {1} - {2}", o, level, message));
            };
            Itinero.Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                Console.WriteLine(string.Format("[{0}] {1} - {2}", o, level, message));
            };
            _logger = new Logger("Default");

            Itinero.Osm.Vehicles.Vehicle.RegisterVehicles();

            // download and extract test-data if not already there.
            _logger.Log(TraceEventType.Information, "Downloading Luxembourg...");
            Download.DownloadLuxembourgAll();

            // TEST1: Tests building a router db for cars, contracting it and calculating routes.
            // test building a router db.
            //var routerDb = Runner.GetTestBuildRouterDb(Download.LuxembourgLocal, false, false, Vehicle.Car).TestPerf("Build belgium router db for Car.");
            //var router = new Router(routerDb);

            var routerDb = RouterDb.Deserialize(File.OpenRead("temp.routerdb"));
            var router   = new Router(routerDb);

            // build profile cache.
            var profileCache = new Profiles.ProfileFactorAndSpeedCache(routerDb);

            profileCache.CalculateFor(Vehicle.Car.Fastest());
            profileCache.CalculateFor(Vehicle.Bicycle.Fastest());
            profileCache.CalculateFor(Vehicle.Pedestrian.Fastest());
            router.ProfileFactorAndSpeedCache = profileCache;

            // Runner.GetTestAddContracted(routerDb, Vehicle.Car.Fastest(), true).TestPerf("Add contracted graph for Car.Fastest()");
            // Runner.GetTestRandomRoutes(new Router(routerDb), Vehicle.Car.Fastest(), 1000).TestPerf("Testing route calculation speed.");

            // TEST2: Tests find islands.
            Func <ushort, Factor> profile = (p) =>
            {
                var prof = routerDb.EdgeProfiles.Get(p);
                if (prof != null)
                {
                    var highway = string.Empty;
                    if (prof.TryGetValue("highway", out highway))
                    {
                        if (highway == "motorway" ||
                            highway == "motorway_link")
                        {
                            return(new Profiles.Factor()
                            {
                                Direction = 0,
                                Value = 10
                            });
                        }
                    }
                }
                return(new Profiles.Factor()
                {
                    Direction = 0,
                    Value = 0
                });
            };
            // Runner.GetTestIslandDetection(routerDb, profile).TestPerf("Testing island detection.", 10);

            // TEST3: calulate isochrones.
            var polygons     = Runner.GetTestIsochroneCalculation(router).TestPerf("Testing isochrone calculation.", 1);
            var polygonsJson = polygons.ToFeatureCollection().ToGeoJson();

            // TEST4: calculate heatmaps.
            var result = Runner.GetTestHeatmapCalculation(router).TestPerf("Testing heatmap calculation.", 10);

            _logger.Log(TraceEventType.Information, "Testing finished.");
            Console.ReadLine();
        }