Exemplo n.º 1
0
        void mapControl1_MapMouseClick(MapControlEventArgs e)
        {
            if (_router != null)
            {
                var routerPoint = _router.Resolve(Vehicle.Car, e.Position);
                if (routerPoint != null)
                {
                    _points.Add(routerPoint);
                    _layerPrimitives.AddPoint(routerPoint.Location, 15, SimpleColor.FromKnownColor(KnownColor.Black).Value);
                    _layerPrimitives.AddPoint(routerPoint.Location, 7, SimpleColor.FromKnownColor(KnownColor.White).Value);
                }

                if (_points.Count > 1)
                {
                    var tspRouter = new RouterTSPWrapper <RouterTSPAEXGenetic>(
                        new RouterTSPAEXGenetic(), _router);

                    var route = tspRouter.CalculateTSP(Vehicle.Car, _points.ToArray());
                    if (route != null)
                    {
                        _layerRoute.Clear();
                        _layerRoute.AddRoute(route);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the TSP.
        /// </summary>
        /// <param name="dataStream"></param>
        /// <param name="csvStream"></param>
        /// <param name="pbf"></param>
        /// <param name="vehicleEnum"></param>
        /// <returns></returns>
        private Route CalculateTSP(Stream dataStream, Stream csvStream, bool pbf, Vehicle vehicleEnum)
        {
            // create the router.
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();
            Router router = Router.CreateLiveFrom(
                new XmlOsmStreamSource(dataStream), interpreter);

            // read the source files.
            const int latitudeIdx  = 2;
            const int longitudeIdx = 3;

            string[][] pointStrings = DelimitedFileHandler.ReadDelimitedFileFromStream(
                csvStream,
                DelimiterType.DotCommaSeperated);
            var points = new List <RouterPoint>();
            int cnt    = 10;

            foreach (string[] line in pointStrings)
            {
                if (points.Count >= cnt)
                {
                    break;
                }
                var latitudeString  = (string)line[latitudeIdx];
                var longitudeString = (string)line[longitudeIdx];

                //string route_ud = (string)line[1];

                double longitude = 0;
                double latitude  = 0;
                if (double.TryParse(longitudeString, System.Globalization.NumberStyles.Any,
                                    System.Globalization.CultureInfo.InvariantCulture, out longitude) &&
                    double.TryParse(latitudeString, System.Globalization.NumberStyles.Any,
                                    System.Globalization.CultureInfo.InvariantCulture, out latitude))
                {
                    var point = new GeoCoordinate(latitude, longitude);

                    RouterPoint resolved = router.Resolve(Vehicle.Car, point);
                    if (resolved != null && router.CheckConnectivity(Vehicle.Car, resolved, 100))
                    {
                        points.Add(resolved);
                    }
                }
            }

            var tspSolver = new RouterTSPWrapper <RouterTSP>(
                new RouterTSPAEXGenetic(), router, interpreter);

            return(tspSolver.CalculateTSP(vehicleEnum, points.ToArray()));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener());
            // read the source file.
            var lines = OsmSharp.IO.DelimitedFiles.DelimitedFileHandler.ReadDelimitedFile(null,
                new FileInfo("bicylestations.csv").OpenRead(), OsmSharp.IO.DelimitedFiles.DelimiterType.DotCommaSeperated, true);

            // create router.
            var interpreter = new OsmRoutingInterpreter();
            var router = Router.CreateLiveFrom(new PBFOsmStreamSource(new FileInfo("antwerp.osm.pbf").OpenRead()), interpreter);

            // resolve all points.
            var resolvedPoints = new List<RouterPoint>();
            foreach(var line in lines)
            {
                var latitude = double.Parse(line[0], System.Globalization.CultureInfo.InvariantCulture);
                var longitude = double.Parse(line[1], System.Globalization.CultureInfo.InvariantCulture);
                var refId = double.Parse(line[2], System.Globalization.CultureInfo.InvariantCulture);

                var resolved = router.Resolve(Vehicle.Bicycle, new Math.Geo.GeoCoordinate(latitude, longitude));
                if(resolved != null && router.CheckConnectivity(Vehicle.Bicycle, resolved, 100))
                { // point exists and is connected.
                    resolvedPoints.Add(resolved);
                }
                else
                { // report that the point could not be resolved.
                    Console.WriteLine("Point with ref {0} could not be resolved!", refId);
                }
            }

            // calculate TSP.
            var tspSolver = new RouterTSPWrapper<RouterTSP>(
                new RouterTSPAEXGenetic(1000, 200), router, interpreter);
            var route = tspSolver.CalculateTSP(Vehicle.Bicycle, resolvedPoints.ToArray());
            route.SaveAsGpx(new FileInfo("output.gpx").OpenWrite());
        }
Exemplo n.º 4
0
        void mapControl1_MapMouseClick(MapControlEventArgs e)
        {
            if(_router != null)
            {
                var routerPoint = _router.Resolve(Vehicle.Car, e.Position);
                if(routerPoint != null)
                {
                    _points.Add(routerPoint);
                    _layerPrimitives.AddPoint(routerPoint.Location, 15, SimpleColor.FromKnownColor(KnownColor.Black).Value);
                    _layerPrimitives.AddPoint(routerPoint.Location, 7, SimpleColor.FromKnownColor(KnownColor.White).Value);
                }

                if(_points.Count > 1)
                {
                    var tspRouter = new RouterTSPWrapper<RouterTSPAEXGenetic>(
                        new RouterTSPAEXGenetic(), _router);

                    var route = tspRouter.CalculateTSP(Vehicle.Car, _points.ToArray());
                    if(route != null)
                    {
                        _layerRoute.Clear();
                        _layerRoute.AddRoute(route);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Calculates the TSP.
        /// </summary>
        /// <param name="dataStream"></param>
        /// <param name="csvStream"></param>
        /// <param name="pbf"></param>
        /// <param name="vehicleEnum"></param>
        /// <returns></returns>
        private OsmSharpRoute CalculateTSP(Stream dataStream, Stream csvStream, bool pbf, VehicleEnum vehicleEnum)
        {
            // create the router.
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new OsmTagsIndex();

            // do the data processing.
            var osmData =
                new DynamicGraphRouterDataSource<PreProcessedEdge>(tagsIndex);
            var targetData = new PreProcessedDataGraphProcessingTarget(
                osmData, interpreter, osmData.TagsIndex, vehicleEnum);
            var dataProcessorSource = new XmlDataProcessorSource(dataStream);
            var sorter = new DataProcessorFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            IRouter<RouterPoint> router = new Router<PreProcessedEdge>(osmData, interpreter,
                new DykstraRoutingPreProcessed(osmData.TagsIndex));

            // read the source files.
            const int latitudeIdx = 2;
            const int longitudeIdx = 3;
            string[][] pointStrings = OsmSharp.Tools.DelimitedFiles.DelimitedFileHandler.ReadDelimitedFileFromStream(
                csvStream,
                DelimiterType.DotCommaSeperated);
            var points = new List<RouterPoint>();
            int cnt = 10;
            foreach (string[] line in pointStrings)
            {
                if (points.Count >= cnt)
                {
                    break;
                }
                var latitudeString = (string)line[latitudeIdx];
                var longitudeString = (string)line[longitudeIdx];

                //string route_ud = (string)line[1];

                double longitude = 0;
                double latitude = 0;
                if (double.TryParse(longitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out longitude) &&
                   double.TryParse(latitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out latitude))
                {
                    var point = new GeoCoordinate(latitude, longitude);

                    RouterPoint resolved = router.Resolve(VehicleEnum.Car, point);
                    if (resolved != null && router.CheckConnectivity(VehicleEnum.Car, resolved, 100))
                    {
                        points.Add(resolved);
                    }
                }
            }

            var tspSolver = new RouterTSPWrapper<RouterPoint, RouterTSP>(
                new RouterTSPAEXGenetic(), router, interpreter);
            return tspSolver.CalculateTSP(vehicleEnum, points.ToArray());
        }
Exemplo n.º 6
0
        private void Route(GeoCoordinate geo)
        {
            if (_router != null)
            {
                var routerPoint = _router.Resolve(Vehicle.Car, geo);
                if (routerPoint != null)
                {
                    _points.Add(routerPoint);
                    _layerPrimitives.AddPoint(routerPoint.Location, 15, SimpleColor.FromKnownColor(KnownColor.Black).Value);
                    _layerPrimitives.AddPoint(routerPoint.Location, 7, SimpleColor.FromKnownColor(KnownColor.White).Value);
                }

                if (_points.Count > 1)
                {
                    double xmin = 0, xmax = 0, ymin = 0, ymax = 0;
                    foreach (var point in _points)
                    {
                        if (xmin == 0) xmin = point.Location.Longitude;
                        if (xmax == 0) xmax = point.Location.Longitude;
                        if (ymin == 0) ymin = point.Location.Latitude;
                        if (ymax == 0) ymax = point.Location.Latitude;
                        if (point.Location.Longitude < xmin) xmin = point.Location.Longitude;
                        if (point.Location.Longitude > xmax) xmax = point.Location.Longitude;
                        if (point.Location.Latitude < ymin) ymin = point.Location.Latitude;
                        if (point.Location.Latitude > ymax) ymax = point.Location.Latitude;
                    }
                    GeoCoordinateBox boundingBox = new GeoCoordinateBox(new GeoCoordinate(ymin, xmin), new GeoCoordinate(ymax, xmax));
                    this.mapControl1.MapCenter = new GeoCoordinate((ymin + ymax) / 2, (xmin + xmax) / 2);

                    var tspRouter = new RouterTSPWrapper<RouterTSPAEXGenetic>(
                        new RouterTSPAEXGenetic(), _router);

                    var route = tspRouter.CalculateTSP(Vehicle.Car, _points.ToArray(), false);
                    if (route != null)
                    {
                        _layerRoute.Clear();
                        _layerRoute.AddRoute(route);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Calculates the TSP.
        /// </summary>
        /// <param name="dataStream"></param>
        /// <param name="csvStream"></param>
        /// <param name="pbf"></param>
        /// <param name="vehicleEnum"></param>
        /// <returns></returns>
        private Route CalculateTSP(Stream dataStream, Stream csvStream, bool pbf, Vehicle vehicleEnum)
        {
            // create the router.
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();
            Router router = Router.CreateLiveFrom(
                new XmlOsmStreamSource(dataStream), interpreter);

            // read the source files.
            const int latitudeIdx = 2;
            const int longitudeIdx = 3;
            string[][] pointStrings = DelimitedFileHandler.ReadDelimitedFileFromStream(
                csvStream,
                DelimiterType.DotCommaSeperated);
            var points = new List<RouterPoint>();
            int cnt = 10;
            foreach (string[] line in pointStrings)
            {
                if (points.Count >= cnt)
                {
                    break;
                }
                var latitudeString = (string)line[latitudeIdx];
                var longitudeString = (string)line[longitudeIdx];

                //string route_ud = (string)line[1];

                double longitude = 0;
                double latitude = 0;
                if (double.TryParse(longitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out longitude) &&
                   double.TryParse(latitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out latitude))
                {
                    var point = new GeoCoordinate(latitude, longitude);

                    RouterPoint resolved = router.Resolve(Vehicle.Car, point);
                    if (resolved != null && router.CheckConnectivity(Vehicle.Car, resolved, 100))
                    {
                        points.Add(resolved);
                    }
                }
            }

            var tspSolver = new RouterTSPWrapper<RouterTSP>(
                new RouterTSPAEXGenetic(), router, interpreter);
            return tspSolver.CalculateTSP(vehicleEnum, points.ToArray());
        }