예제 #1
0
        /// <summary>
        /// Tests if the many-to-many weights are the same as the point-to-point weights.
        /// </summary>
        protected void DoTestManyToMany1()
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <EdgeData> data        = this.BuildData(interpreter);
            IRoutingAlgorithm <EdgeData>     basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            var resolvedPoints = new RouterPoint[3];

            resolvedPoints[0] = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578532, 3.7192229));
            resolvedPoints[1] = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801));
            resolvedPoints[2] = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0581001, 3.7200612));

            double[][] weights = router.CalculateManyToManyWeight(Vehicle.Car, resolvedPoints, resolvedPoints);

            for (int x = 0; x < weights.Length; x++)
            {
                for (int y = 0; y < weights.Length; y++)
                {
                    double manyToMany   = weights[x][y];
                    double pointToPoint = router.CalculateWeight(Vehicle.Car, resolvedPoints[x], resolvedPoints[y]);

                    Assert.AreEqual(pointToPoint, manyToMany);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Test if routes between resolved nodes are correctly calculated.
        ///
        /// 20----x----21----x----16
        /// </summary>
        protected void DoTestResolveCase1()
        {
            // initialize data.
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <TEdgeData> data = this.BuildData(interpreter, "OsmSharp.Routing.Test.data.test_network.osm");

            var vertex20 = new GeoCoordinate(51.0578532, 3.7192229);
            var vertex21 = new GeoCoordinate(51.0578518, 3.7195654);
            var vertex16 = new GeoCoordinate(51.0577299, 3.719745);

            PointF2D point      = vertex20 + ((vertex21 - vertex20) * 0.5);
            var      vertex2021 = new GeoCoordinate(point[1], point[0]);

            point = vertex21 + ((vertex16 - vertex21) * 0.5);
            var vertex2116 = new GeoCoordinate(point[1], point[0]);

            // calculate route.
            IRoutingAlgorithm <TEdgeData> basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(data, interpreter, basicRouter);

            Route route = router.Calculate(Vehicle.Car,
                                           router.Resolve(Vehicle.Car, vertex2021),
                                           router.Resolve(Vehicle.Car, vertex2116));

            Assert.AreEqual(3, route.Segments.Length);
            Assert.AreEqual(vertex2021.Latitude, route.Segments[0].Latitude, 0.0001);
            Assert.AreEqual(vertex2021.Longitude, route.Segments[0].Longitude, 0.0001);

            Assert.AreEqual(vertex21.Latitude, route.Segments[1].Latitude, 0.0001);
            Assert.AreEqual(vertex21.Longitude, route.Segments[1].Longitude, 0.0001);

            Assert.AreEqual(vertex2116.Latitude, route.Segments[2].Latitude, 0.0001);
            Assert.AreEqual(vertex2116.Longitude, route.Segments[2].Longitude, 0.0001);
        }
예제 #3
0
 /// <summary>
 /// Builds a router.
 /// </summary>
 /// <returns></returns>
 public override Router BuildRouter(IRoutingAlgorithmData <Edge> data,
                                    IOsmRoutingInterpreter interpreter,
                                    IRoutingAlgorithm <Edge> basicRouter)
 {
     // initialize the router.
     return(Router.CreateFrom(data, basicRouter, interpreter));
 }
예제 #4
0
        /// <summary>
        /// Adds a graph layer with the given data and style.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        /// <returns></returns>
        public LayerGraph AddLayerGraph(IRoutingAlgorithmData <Edge> dataSource,
                                        StyleInterpreter styleInterpreter)
        {
            var layerGraph = new LayerGraph(dataSource, styleInterpreter);

            this.AddLayer(layerGraph);
            return(layerGraph);
        }
예제 #5
0
        /// <summary>
        /// Creates a router using interpreted edges.
        /// </summary>
        /// <param name="data">The data to route on.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static Router CreateFrom(IRoutingAlgorithmData <Edge> data, IRoutingInterpreter interpreter)
        {
            // creates the edge router.
            var typedRouter = new TypedRouterEdge(
                data, interpreter, new Dykstra());

            return(new Router(typedRouter)); // create the actual router.
        }
예제 #6
0
        /// <summary>
        /// Creates a router using interpreted edges.
        /// </summary>
        /// <param name="data">The data to route on.</param>
        /// <param name="basicRouter">A custom routing implementation.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static Router CreateCHFrom(IRoutingAlgorithmData <CHEdgeData> data, IRoutingAlgorithm <CHEdgeData> basicRouter,
                                          IRoutingInterpreter interpreter)
        {
            // creates the edge router.
            var typedRouter = new TypedRouterCHEdge(
                data, interpreter, basicRouter);

            return(new Router(typedRouter)); // create the actual router.
        }
예제 #7
0
파일: LayerGraph.cs 프로젝트: rolo2012/ui
        /// <summary>
        /// Creates a new OSM data layer.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        public LayerGraph(IRoutingAlgorithmData <Edge> dataSource,
                          StyleInterpreter styleInterpreter)
        {
            _dataSource       = dataSource;
            _styleInterpreter = styleInterpreter;

            _scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);
            _interpretedObjects = new Dictionary <int, HashSet <ArcId> >();
        }
예제 #8
0
        /// <summary>
        /// Creates a new OSM data layer.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        public LayerGraph(IRoutingAlgorithmData<Edge> dataSource, 
                                         StyleInterpreter styleInterpreter)
        {
            _dataSource = dataSource;
            _styleInterpreter = styleInterpreter;

            _scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);
            _interpretedObjects = new Dictionary<int, HashSet<ArcId>>();
        }
예제 #9
0
        /// <summary>
        /// Tests the the given router class by comparing calculated routes agains a given reference router.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="referenceRouter"></param>
        /// <param name="router"></param>
        protected void TestCompareAll <TEdgeData>(IRoutingAlgorithmData <TEdgeData> data, Router referenceRouter, Router router)
            where TEdgeData : IGraphEdgeData
        {
            // loop over all nodes and resolve their locations.
            var resolvedReference = new RouterPoint[data.VertexCount - 1];
            var resolved          = new RouterPoint[data.VertexCount - 1];

            for (uint idx = 1; idx < data.VertexCount; idx++)
            { // resolve each vertex.
                float latitude, longitude;
                if (data.GetVertex(idx, out latitude, out longitude))
                {
                    resolvedReference[idx - 1] = referenceRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude), true);
                    resolved[idx - 1]          = router.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude), true);
                }

                // reference and resolved have to exist.
                Assert.IsNotNull(resolvedReference[idx - 1]);
                Assert.IsNotNull(resolved[idx - 1]);

                // reference and resolved cannot be more than 10cm apart.
                Assert.AreEqual(0, resolvedReference[idx - 1].Location.DistanceReal(
                                    resolved[idx - 1].Location).Value, 0.1, "Reference and resolved are more than 10cm apart.");
            }

            // limit tests to a fixed number.
            int maxTestCount   = 100;
            int testEveryOther = (resolved.Length * resolved.Length) / maxTestCount;

            testEveryOther = System.Math.Max(testEveryOther, 1);

            // check all the routes having the same weight(s).
            for (int fromIdx = 0; fromIdx < resolved.Length; fromIdx++)
            {
                for (int toIdx = 0; toIdx < resolved.Length; toIdx++)
                {
                    int testNumber = fromIdx * resolved.Length + toIdx;
                    if (testNumber % testEveryOther == 0)
                    {
                        OsmSharp.Logging.Log.TraceEvent("RoutingComparisonTestBase.TestCompareAll", Logging.TraceEventType.Information,
                                                        "Testing point {0} -> {1}", fromIdx, toIdx);
                        var referenceRoute = referenceRouter.Calculate(Vehicle.Car,
                                                                       resolvedReference[fromIdx], resolvedReference[toIdx]);
                        var route = router.Calculate(Vehicle.Car,
                                                     resolved[fromIdx], resolved[toIdx]);

                        if (referenceRoute != null)
                        {
                            Assert.IsNotNull(referenceRoute);
                            Assert.IsNotNull(route);
                            this.CompareRoutes(referenceRoute, route);
                        }
                    }
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Calculates the shortest path from all sources to all targets.
        /// </summary>
        /// <returns></returns>
        public PathSegment <long>[][] CalculateManyToMany(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter,
                                                          Vehicle vehicle, PathSegmentVisitList[] sources, PathSegmentVisitList[] targets, double maxSearch, Dictionary <string, object> parameters)
        {
            var results = new PathSegment <long> [sources.Length][];

            for (int sourceIdx = 0; sourceIdx < sources.Length; sourceIdx++)
            {
                results[sourceIdx] = this.DoCalculation(graph, interpreter, vehicle,
                                                        sources[sourceIdx], targets, maxSearch, false, false, parameters);
            }
            return(results);
        }
예제 #11
0
        /// <summary>
        /// Calculates a shortest path between the source vertex and any of the targets and returns the shortest.
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="interpreter"></param>
        /// <param name="vehicle"></param>
        /// <param name="from"></param>
        /// <param name="targets"></param>
        /// <param name="max"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public PathSegment <long> CalculateToClosest(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter,
                                                     Vehicle vehicle, PathSegmentVisitList from, PathSegmentVisitList[] targets, double max, Dictionary <string, object> parameters)
        {
            var result = this.DoCalculation(graph, interpreter, vehicle,
                                            from, targets, max, false, false, parameters);

            if (result != null && result.Length == 1)
            {
                return(result[0]);
            }
            return(null);
        }
예제 #12
0
        /// <summary>
        /// Calculates the shortest path from the given vertex to the given vertex given the weights in the graph.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="graph"></param>
        /// <param name="interpreter"></param>
        /// <param name="max"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public double CalculateWeight(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter, Vehicle vehicle,
                                      PathSegmentVisitList from, PathSegmentVisitList to, double max, Dictionary <string, object> parameters)
        {
            PathSegment <long> closest = this.CalculateToClosest(graph, interpreter, vehicle, from,
                                                                 new PathSegmentVisitList[] { to }, max, null);

            if (closest != null)
            {
                return(closest.Weight);
            }
            return(double.MaxValue);
        }
예제 #13
0
        /// <summary>
        /// Calculates the shortest path from the given vertex to the given vertex given the weights in the graph.
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="interpreter"></param>
        /// <param name="vehicle"></param>
        /// <returns></returns>
        public PathSegment <long> Calculate(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter, Vehicle vehicle,
                                            uint from, uint to)
        {
            var source = new PathSegmentVisitList();

            source.UpdateVertex(new PathSegment <long>(from));
            var target = new PathSegmentVisitList();

            target.UpdateVertex(new PathSegment <long>(to));

            // do the basic CH calculations.
            return(this.Calculate(graph, interpreter, vehicle, source, target, float.MaxValue, null));
        }
예제 #14
0
        /// <summary>
        /// Calculates all points that are at or close to the given weight.
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="interpreter"></param>
        /// <param name="vehicle"></param>
        /// <param name="source"></param>
        /// <param name="weight"></param>
        /// <param name="forward"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public HashSet <long> CalculateRange(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter,
                                             Vehicle vehicle, PathSegmentVisitList source, double weight, bool forward, Dictionary <string, object> parameters)
        {
            PathSegment <long>[] result = this.DoCalculation(graph, interpreter, vehicle,
                                                             source, new PathSegmentVisitList[0], weight, false, true, forward, parameters);

            var resultVertices = new HashSet <long>();

            for (int idx = 0; idx < result.Length; idx++)
            {
                resultVertices.Add(result[idx].VertexId);
            }
            return(resultVertices);
        }
예제 #15
0
        /// <summary>
        /// Calculates all routes from a given sources to all given targets.
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="interpreter"></param>
        /// <param name="vehicle"></param>
        /// <param name="sources"></param>
        /// <param name="targets"></param>
        /// <param name="max"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public double[][] CalculateManyToManyWeight(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter,
                                                    Vehicle vehicle, PathSegmentVisitList[] sources, PathSegmentVisitList[] targets, double max, Dictionary <string, object> parameters)
        {
            var results = new double[sources.Length][];

            for (int idx = 0; idx < sources.Length; idx++)
            {
                results[idx] = this.CalculateOneToManyWeight(graph, interpreter, vehicle, sources[idx], targets, max, null);

                OsmSharp.Logging.Log.TraceEvent("Dykstra", TraceEventType.Information, "Calculating weights... {0}%",
                                                (int)(((float)idx / (float)sources.Length) * 100));
            }
            return(results);
        }
예제 #16
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        protected void DoTestShortest5()
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <TEdgeData> data         = this.BuildData(interpreter, "OsmSharp.Test.Unittests.test_network.osm");
            IRoutingAlgorithm <TEdgeData>     basic_router = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basic_router);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801));
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0581001, 3.7200612));

            Route route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(7, route.Segments.Length);
        }
예제 #17
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        protected void DoTestShortestResolved1()
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.Routing.Test.data.test_network.osm");
            IRoutingAlgorithm <TEdgeData>     basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578153, 3.7193937));
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0582408, 3.7194636));

            Route route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(10, route.Segments.Length);
        }
예제 #18
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        protected void DoTestShortestResolved2()
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.Test.Unittests.test_network.osm");
            IRoutingAlgorithm <TEdgeData>     basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0581843, 3.7201209)); // between 2 - 3
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0581484, 3.7194957)); // between 9 - 8

            Route route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(5, route.Segments.Length);
        }
예제 #19
0
        /// <summary>
        /// Returns true if the search can move beyond the given weight.
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="interpreter"></param>
        /// <param name="vehicle"></param>
        /// <param name="source"></param>
        /// <param name="weight"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public bool CheckConnectivity(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter, Vehicle vehicle,
                                      PathSegmentVisitList source, double weight, Dictionary <string, object> parameters)
        {
            HashSet <long> range = this.CalculateRange(graph, interpreter, vehicle, source, weight, true, null);

            if (range.Count > 0)
            {
                range = this.CalculateRange(graph, interpreter, vehicle, source, weight, false, null);
                if (range.Count > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="access_tags"></param>
        protected void DoTestShortestWithoutAccess(Vehicle vehicle, List <KeyValuePair <string, string> > access_tags)
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <EdgeData> data        = this.BuildData(interpreter, vehicle, access_tags);
            IRoutingAlgorithm <EdgeData>     basicRouter = this.BuildBasicRouter(data, vehicle);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(vehicle, new GeoCoordinate(51.0579530, 3.7196168)); // -56
            RouterPoint target = router.Resolve(vehicle, new GeoCoordinate(51.0582205, 3.7192647)); // -52

            Route route = router.Calculate(vehicle, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(6, route.Segments.Length);

            float latitude, longitude;

            data.GetVertex(10, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[0].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[0].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Start, route.Segments[0].Type);

            data.GetVertex(12, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[1].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[1].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[1].Type);

            data.GetVertex(13, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[2].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[2].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[2].Type);

            data.GetVertex(14, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[3].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[3].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[3].Type);

            data.GetVertex(15, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[4].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[4].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[4].Type);

            data.GetVertex(19, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[5].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[5].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Stop, route.Segments[5].Type);
        }
예제 #21
0
        /// <summary>
        /// Test if the resolving of nodes returns those same nodes.
        ///
        /// (does not work on a lazy loading data source!)
        /// </summary>
        protected void DoTestResolveAllNodes()
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.Test.Unittests.test_network.osm");
            IRoutingAlgorithm <TEdgeData>     basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);

            for (int idx = 1; idx < data.VertexCount; idx++)
            {
                float latitude, longitude;
                if (data.GetVertex((uint)idx, out latitude, out longitude))
                {
                    var point = router.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                    Assert.AreEqual(idx, (point as RouterPoint).Id);
                }
            }
        }
예제 #22
0
        public static void Test(IRoutingAlgorithmData <Edge> data, Vehicle vehicle, int testCount)
        {
            // creates the edge router.
            var router      = new Dykstra();
            var interpreter = new OsmRoutingInterpreter();

            var performanceInfo = new PerformanceInfoConsumer("Routing");

            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            var successCount   = 0;
            var totalCount     = testCount;
            var latestProgress = -1.0f;

            while (testCount > 0)
            {
                var from = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(data.VertexCount - 1) + 1;
                var to   = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(data.VertexCount - 1) + 1;

                var route = router.Calculate(data, interpreter, vehicle, from, to);

                if (route != null)
                {
                    successCount++;
                }
                testCount--;

                // report progress.
                var progress = (float)System.Math.Round(((double)(totalCount - testCount) / (double)totalCount) * 100);
                if (progress != latestProgress)
                {
                    OsmSharp.Logging.Log.TraceEvent("Routing", TraceEventType.Information,
                                                    "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("Routing", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
예제 #23
0
        /// <summary>
        /// Tests access for a given vehicle type and for a given network between two given points.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="interpreter"></param>
        protected bool DoTestForVehicle(Vehicle vehicle, GeoCoordinate from, GeoCoordinate to,
                                        IOsmRoutingInterpreter interpreter)
        {
            IRoutingAlgorithmData <TEdgeData> data =
                this.BuildData(interpreter, "OsmSharp.Test.Unittests.test_segments.osm", vehicle);
            IRoutingAlgorithm <TEdgeData> basicRouter =
                this.BuildBasicRouter(data);
            Router router =
                this.BuildRouter(data, interpreter, basicRouter);

            RouterPoint resolvedFrom = router.Resolve(vehicle, from);
            RouterPoint resolvedTo   = router.Resolve(vehicle, to);

            if (resolvedFrom != null && resolvedTo != null)
            {
                Route route = router.Calculate(vehicle, resolvedFrom, resolvedTo);
                return(route != null);
            }
            return(false);
        }
예제 #24
0
        /// <summary>
        /// Calculates all routes from a given source to all given targets.
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="interpreter"></param>
        /// <param name="vehicle"></param>
        /// <param name="source"></param>
        /// <param name="targets"></param>
        /// <param name="max"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public double[] CalculateOneToManyWeight(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter, Vehicle vehicle,
                                                 PathSegmentVisitList source, PathSegmentVisitList[] targets, double max, Dictionary <string, object> parameters)
        {
            var many = this.DoCalculation(graph, interpreter, vehicle,
                                          source, targets, max, false, false, null);

            var weights = new double[many.Length];

            for (int idx = 0; idx < many.Length; idx++)
            {
                if (many[idx] != null)
                {
                    weights[idx] = many[idx].Weight;
                }
                else
                {
                    weights[idx] = double.MaxValue;
                }
            }
            return(weights);
        }
예제 #25
0
        /// <summary>
        /// Test if the connectivity test succeed/fail.
        /// </summary>
        protected void DoTestConnectivity1()
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.Test.Unittests.test_network.osm");
            IRoutingAlgorithm <TEdgeData>     basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            var resolvedPoints = new RouterPoint[3];

            resolvedPoints[0] = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578532, 3.7192229));
            resolvedPoints[1] = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801));
            resolvedPoints[2] = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0581001, 3.7200612));

            // test connectivity succes.
            Assert.IsTrue(router.CheckConnectivity(Vehicle.Car, resolvedPoints[0], 5));
            //Assert.IsTrue(router.CheckConnectivity(VehicleEnum.Car, resolved_points[1], 5));
            Assert.IsTrue(router.CheckConnectivity(Vehicle.Car, resolvedPoints[2], 5));

            // test connectivity failiure.
            Assert.IsFalse(router.CheckConnectivity(Vehicle.Car, resolvedPoints[0], 1000));
            Assert.IsFalse(router.CheckConnectivity(Vehicle.Car, resolvedPoints[1], 1000));
            Assert.IsFalse(router.CheckConnectivity(Vehicle.Car, resolvedPoints[2], 1000));
        }
예제 #26
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        protected void DoTestShortestWithDirection()
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <EdgeData> data        = this.BuildData(interpreter);
            IRoutingAlgorithm <EdgeData>     basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0582205, 3.7192647)); // -52
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0579530, 3.7196168)); // -56

            Route route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(4, route.Segments.Length);

            float latitude, longitude;

            data.GetVertex(19, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[0].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[0].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Start, route.Segments[0].Type);

            data.GetVertex(8, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[1].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[1].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[1].Type);

            data.GetVertex(9, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[2].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[2].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[2].Type);

            data.GetVertex(10, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Segments[3].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Segments[3].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Stop, route.Segments[3].Type);
        }
예제 #27
0
        /// <summary>
        /// Tests that a router preserves tags given to resolved points.
        /// </summary>
        protected void DoTestResolvedTags()
        {
            var interpreter = new OsmRoutingInterpreter();
            IRoutingAlgorithmData <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.Test.Unittests.test_network.osm");
            IRoutingAlgorithm <TEdgeData>     basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578532, 3.7192229));

            source.Tags.Add(new KeyValuePair <string, string>("name", "source"));
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801));

            target.Tags.Add(new KeyValuePair <string, string>("name", "target"));

            Route route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(5, route.Segments.Length);

            // float latitude, longitude;
            // data.GetVertex(20, out latitude, out longitude);
            Assert.AreEqual(51.0578537, route.Segments[0].Latitude, 0.00001);
            Assert.AreEqual(3.71922278, route.Segments[0].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Start, route.Segments[0].Type);
            Assert.IsNotNull(route.Segments[0].Points[0].Tags);
            Assert.AreEqual(1, route.Segments[0].Points[0].Tags.Length);
            Assert.AreEqual("source", route.Segments[0].Points[0].Tags[0].Value);

            // data.GetVertex(23, out latitude, out longitude);
            Assert.AreEqual(51.05762, route.Segments[4].Latitude, 0.00001);
            Assert.AreEqual(3.71918, route.Segments[4].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Stop, route.Segments[4].Type);
            Assert.IsNotNull(route.Segments[4].Points[0].Tags);
            Assert.AreEqual(1, route.Segments[4].Points[0].Tags.Length);
            Assert.AreEqual("target", route.Segments[4].Points[0].Tags[0].Value);
        }
예제 #28
0
 /// <summary>
 /// Creates a new type router using edges of type CHEdgeData.
 /// </summary>
 /// <param name="graph"></param>
 /// <param name="interpreter"></param>
 /// <param name="router"></param>
 public TypedRouterCHEdge(IRoutingAlgorithmData <CHEdgeData> graph, IRoutingInterpreter interpreter, IRoutingAlgorithm <CHEdgeData> router)
     : base(graph, interpreter, router)
 {
     DefaultSearchDelta = 0.0125f;
 }
예제 #29
0
 /// <summary>
 /// Builds the basic router.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public abstract IRoutingAlgorithm <TEdgeData> BuildBasicRouter(IRoutingAlgorithmData <TEdgeData> data);
예제 #30
0
 /// <summary>
 /// Builds the router;
 /// </summary>
 /// <param name="data"></param>
 /// <param name="interpreter"></param>
 /// <param name="basicRouter"></param>
 /// <returns></returns>
 public abstract Router BuildRouter(IRoutingAlgorithmData <TEdgeData> data,
                                    IOsmRoutingInterpreter interpreter, IRoutingAlgorithm <TEdgeData> basicRouter);
예제 #31
0
 /// <summary>
 /// Builds a basic router.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public override IRoutingAlgorithm <Edge> BuildBasicRouter(IRoutingAlgorithmData <Edge> data)
 {
     return(new Dykstra());
 }
예제 #32
0
파일: Router.cs 프로젝트: UnifyKit/OsmSharp
        /// <summary>
        /// Creates a router using interpreted edges.
        /// </summary>
        /// <param name="data">The data to route on.</param>
        /// <param name="basicRouter">A custom routing implementation.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static Router CreateCHFrom(IRoutingAlgorithmData<CHEdgeData> data, IRoutingAlgorithm<CHEdgeData> basicRouter, 
            IRoutingInterpreter interpreter)
        {
            // creates the edge router.
            var typedRouter = new TypedRouterCHEdge(
                data, interpreter, basicRouter);

            return new Router(typedRouter); // create the actual router.
        }
예제 #33
0
파일: Router.cs 프로젝트: UnifyKit/OsmSharp
        /// <summary>
        /// Creates a router using interpreted edges.
        /// </summary>
        /// <param name="data">The data to route on.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static Router CreateFrom(IRoutingAlgorithmData<Edge> data, IRoutingInterpreter interpreter)
        {
            // creates the edge router.
            var typedRouter = new TypedRouterEdge(
                data, interpreter, new Dykstra());

            return new Router(typedRouter); // create the actual router.
        }
예제 #34
0
        public static void Test(IRoutingAlgorithmData<Edge> data, Vehicle vehicle, int testCount)
        {
            // creates the edge router.
            var router = new Dykstra();
            var interpreter = new OsmRoutingInterpreter();

            var performanceInfo = new PerformanceInfoConsumer("Routing");
            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            var successCount = 0;
            var totalCount = testCount;
            var latestProgress = -1.0f;
            while (testCount > 0)
            {
                var from = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(data.VertexCount - 1) + 1;
                var to = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(data.VertexCount - 1) + 1;

                var route = router.Calculate(data, interpreter, vehicle, from, to);

                if (route != null)
                {
                    successCount++;
                }
                testCount--;

                // report progress.
                var progress = (float)System.Math.Round(((double)(totalCount - testCount) / (double)totalCount) * 100);
                if (progress != latestProgress)
                {
                    OsmSharp.Logging.Log.TraceEvent("Routing", TraceEventType.Information,
                        "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("Routing", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
예제 #35
0
파일: Map.cs 프로젝트: UnifyKit/OsmSharp
 /// <summary>
 /// Adds a graph layer with the given data and style.
 /// </summary>
 /// <param name="dataSource"></param>
 /// <param name="styleInterpreter"></param>
 /// <returns></returns>
 public LayerGraph AddLayerGraph(IRoutingAlgorithmData<Edge> dataSource,
     StyleInterpreter styleInterpreter)
 {
     var layerGraph = new LayerGraph(dataSource, styleInterpreter);
     this.AddLayer(layerGraph);
     return layerGraph;
 }