コード例 #1
0
        public void TestVerifiedContraction1NoWitnesses()
        {
            var graph   = new MemoryDirectedGraph <CHEdgeData>();
            var vertex1 = graph.AddVertex(1, 0);
            var vertex2 = graph.AddVertex(2, 0);
            var vertex3 = graph.AddVertex(3, 0);

            graph.AddEdge(vertex1, vertex3, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex3, vertex1, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex2, vertex3, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex3, vertex2, new CHEdgeData(1, false, true, true, 10));

            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor      = new CHPreProcessor(graph,
                                                       new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator), witnessCalculator);

            preProcessor.Contract(3);

            // there should be no edge from 1->3 and from 2->3.
            Assert.IsFalse(graph.ContainsEdges(1, 3));
            Assert.IsFalse(graph.ContainsEdges(2, 3));

            var router = new CHRouter();
            // expected: (1)-10s-(3)-10s-(2) (20s in total).
            var path = router.Calculate(graph, 1, 2);

            Assert.IsNotNull(path);
            Assert.AreEqual(20, path.Weight);
            var pathArray = path.ToArrayWithWeight();

            Assert.AreEqual(3, pathArray.Length);
            float latitude, longitude;

            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(3, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);

            // expected: (2)-10s-(3)-10s-(1) (20s in total).
            path = router.Calculate(graph, 2, 1);
            Assert.IsNotNull(path);
            Assert.AreEqual(20, path.Weight);
            pathArray = path.ToArrayWithWeight();
            Assert.AreEqual(3, pathArray.Length);
            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(3, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
        }
コード例 #2
0
        /// <summary>
        /// Called left before the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnBeforeContractionEvent(uint vertex, KeyValuePair <uint, CHEdgeData>[] edges)
        {
            // create a new CHRouter
            var router = new CHRouter(_data);

            // calculate all the routes between the neighbours of the contracted vertex.
            _pathsBeforeContraction =
                new Dictionary <uint, Dictionary <uint, PathSegment <long> > >();
            foreach (KeyValuePair <uint, CHEdgeData> from in edges)
            {
                // initialize the from-list.
                var fromList = new PathSegmentVisitList();
                fromList.UpdateVertex(new PathSegment <long>(from.Key));

                // initalize the from dictionary.
                var fromDic = new Dictionary <uint, PathSegment <long> >();
                _pathsBeforeContraction[from.Key] = fromDic;
                foreach (KeyValuePair <uint, CHEdgeData> to in edges)
                {
                    // initialize the to-list.
                    var toList = new PathSegmentVisitList();
                    toList.UpdateVertex(new PathSegment <long>(to.Key));

                    // calculate the route.
                    PathSegment <long> route = router.Calculate(_data, _interpreter,
                                                                OsmSharp.Routing.Vehicle.Car, fromList, toList, double.MaxValue);
                    fromDic[to.Key] = route;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Called left before the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnBeforeContractionEvent(uint vertex, List <Edge <CHEdgeData> > edges)
        {
            // create a new CHRouter
            var router = new CHRouter();

            // calculate all the routes between the neighbours of the contracted vertex.
            var pathsBeforeContraction = new Dictionary <uint, Dictionary <uint, PathSegment <long> > >();

            _pathsBeforeContraction.Add(vertex, pathsBeforeContraction);
            foreach (var from in edges)
            {
                // initialize the from-list.
                var fromList = new PathSegmentVisitList();
                fromList.UpdateVertex(new PathSegment <long>(from.Neighbour));

                // initalize the from dictionary.
                var fromDic = new Dictionary <uint, PathSegment <long> >();
                pathsBeforeContraction[from.Neighbour] = fromDic;
                foreach (var to in edges)
                {
                    // initialize the to-list.
                    var toList = new PathSegmentVisitList();
                    toList.UpdateVertex(new PathSegment <long>(to.Neighbour));

                    // calculate the route.
                    fromDic[to.Neighbour] = router.Calculate(_data, _interpreter,
                                                             Vehicle.Car, fromList, toList, double.MaxValue, null);;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Called right after the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnAfterContractionEvent(uint vertex, KeyValuePair <uint, CHEdgeData>[] edges)
        {
            // create a new CHRouter
            var router = new CHRouter(_data);

            // calculate all the routes between the neighbours of the contracted vertex.
            foreach (KeyValuePair <uint, CHEdgeData> from in edges)
            {
                // initialize the from-list.
                var fromList = new PathSegmentVisitList();
                fromList.UpdateVertex(new PathSegment <long>(from.Key));

                // initalize the from dictionary.
                Dictionary <uint, PathSegment <long> > fromDic = _pathsBeforeContraction[from.Key];
                foreach (KeyValuePair <uint, CHEdgeData> to in edges)
                {
                    // initialize the to-list.
                    var toList = new PathSegmentVisitList();
                    toList.UpdateVertex(new PathSegment <long>(to.Key));

                    // calculate the route.
                    PathSegment <long> route = router.Calculate(_data, _interpreter, OsmSharp.Routing.Vehicle.Car, fromList, toList, double.MaxValue);
                    if ((fromDic[to.Key] == null && route != null) ||
                        (fromDic[to.Key] != null && route == null) ||
                        ((fromDic[to.Key] != null && route != null) && fromDic[to.Key] != route))
                    { // the route match!
                        Assert.Fail("Routes are different before/after contraction!");
                    }
                }
            }
        }
コード例 #5
0
        public void TestVerifiedContraction1NoWitnesses()
        {
            var graph = new DirectedGraph<CHEdgeData>();
            var vertex1 = graph.AddVertex(1, 0);
            var vertex2 = graph.AddVertex(2, 0);
            var vertex3 = graph.AddVertex(3, 0);

            graph.AddEdge(vertex1, vertex3, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex3, vertex1, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex2, vertex3, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex3, vertex2, new CHEdgeData(1, false, true, true, 10));

            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor = new CHPreprocessor(graph,
                new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator), witnessCalculator);
            preProcessor.Contract(3);

            // there should be no edge from 1->3 and from 2->3.
            Assert.IsFalse(graph.ContainsEdges(1, 3));
            Assert.IsFalse(graph.ContainsEdges(2, 3));

            var router = new CHRouter();
            // expected: (1)-10s-(3)-10s-(2) (20s in total).
            var path = router.Calculate(graph, 1, 2);
            Assert.IsNotNull(path);
            Assert.AreEqual(20, path.Weight);
            var pathArray = path.ToArrayWithWeight();
            Assert.AreEqual(3, pathArray.Length);
            float latitude, longitude;
            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(3, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);

            // expected: (2)-10s-(3)-10s-(1) (20s in total).
            path = router.Calculate(graph, 2, 1);
            Assert.IsNotNull(path);
            Assert.AreEqual(20, path.Weight);
            pathArray = path.ToArrayWithWeight();
            Assert.AreEqual(3, pathArray.Length);
            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(3, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
        }
コード例 #6
0
ファイル: CHRoutingTest.cs プロジェクト: yousoftvn/OsmSharp
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="testCount"></param>
        public static void TestRouting(string name, Stream stream, int testCount)
        {
            var vehicle = Vehicle.Car;

            var tagsIndex = new TagsTableCollectionIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();

            source.RegisterSource(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream));
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(source,
                                                             new OsmRoutingInterpreter(), vehicle);

            var router = new CHRouter();

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");

            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, 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("CHRouting", TraceEventType.Information,
                                                    "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
コード例 #7
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="testCount"></param>
        public static void Test(RouterDataSource <CHEdgeData> data, int testCount)
        {
            var router = new CHRouter();

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");

            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, 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("CHRouting", TraceEventType.Information,
                                                    "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
コード例 #8
0
ファイル: CHRoutingTest.cs プロジェクト: UnifyKit/OsmSharp
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="testCount"></param>
        public static void Test(RouterDataSource<CHEdgeData> data, int testCount)
        {
            var router = new CHRouter();

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");
            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, 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("CHRouting", TraceEventType.Information,
                        "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
コード例 #9
0
        public void TestVerifiedContraction3TinyOneWay()
        {
            var graph   = new MemoryDirectedGraph <CHEdgeData>();
            var vertex1 = graph.AddVertex(1, 0);
            var vertex2 = graph.AddVertex(2, 0);
            var vertex3 = graph.AddVertex(3, 0);
            var vertex4 = graph.AddVertex(4, 0);
            var vertex5 = graph.AddVertex(5, 0);

            graph.AddEdge(vertex1, vertex4, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex4, vertex1, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex1, vertex2, new CHEdgeData(1, true, true, false, 10));  // oneway forward
            graph.AddEdge(vertex2, vertex1, new CHEdgeData(1, false, false, true, 10)); // oneway backward.
            graph.AddEdge(vertex1, vertex3, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex3, vertex1, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex2, vertex3, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex3, vertex2, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex2, vertex5, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex5, vertex2, new CHEdgeData(1, false, true, true, 10));

            Assert.IsFalse(graph.ContainsEdges(vertex1, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex3, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex4, vertex1));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex2));
            Assert.IsFalse(graph.ContainsEdges(vertex2, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex3, vertex2));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex5, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex3));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex3));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex2, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex1, vertex5));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex5));

            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor      = new CHPreProcessor(graph,
                                                       new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator), witnessCalculator);

            preProcessor.Start();

            var router = new CHRouter();
            // expected: (4)-10s-(1)-10s-(2)-10s-(3) (30s in total).
            var path = router.Calculate(graph, 4, 5);

            Assert.IsNotNull(path);
            Assert.AreEqual(30, path.Weight);
            var pathArray = path.ToArrayWithWeight();

            Assert.AreEqual(4, pathArray.Length);
            float latitude, longitude;

            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(4, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);
            Assert.AreEqual(30, pathArray[3].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[3].Item1, out latitude, out longitude));
            Assert.AreEqual(5, latitude);

            // expected: (5)-10s-(2)-10s-(3)-10s-(1)-10s-(4) (40s in total).
            path = router.Calculate(graph, 5, 4);
            Assert.IsNotNull(path);
            Assert.AreEqual(40, path.Weight);
            pathArray = path.ToArrayWithWeight();
            Assert.AreEqual(5, pathArray.Length);
            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(5, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(3, latitude);
            Assert.AreEqual(30, pathArray[3].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[3].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
            Assert.AreEqual(40, pathArray[4].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[4].Item1, out latitude, out longitude));
            Assert.AreEqual(4, latitude);
        }
コード例 #10
0
ファイル: CHRoutingTest.cs プロジェクト: OpenMaps/OsmSharp
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="testCount"></param>
        public static void TestRouting(string name, Stream stream, int testCount)
        {
            var vehicle = Vehicle.Car;

            var tagsIndex = new TagsTableCollectionIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();
            source.RegisterSource(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream));
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(source,
                new OsmRoutingInterpreter(), vehicle);

            var router = new CHRouter();

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");
            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, 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("CHRouting", TraceEventType.Information,
                        "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
コード例 #11
0
        /// <summary>
        /// Called left before the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnBeforeContractionEvent(uint vertex, List<Edge<CHEdgeData>> edges)
        {
            // create a new CHRouter
            var router = new CHRouter();

            // calculate all the routes between the neighbours of the contracted vertex.
            var pathsBeforeContraction = new Dictionary<uint, Dictionary<uint, PathSegment<long>>>();
            _pathsBeforeContraction.Add(vertex, pathsBeforeContraction);
            foreach (var from in edges)
            {
                // initialize the from-list.
                var fromList = new PathSegmentVisitList();
                fromList.UpdateVertex(new PathSegment<long>(from.Neighbour));

                // initalize the from dictionary.
                var fromDic = new Dictionary<uint, PathSegment<long>>();
                pathsBeforeContraction[from.Neighbour] = fromDic;
                foreach (var to in edges)
                {
                    // initialize the to-list.
                    var toList = new PathSegmentVisitList();
                    toList.UpdateVertex(new PathSegment<long>(to.Neighbour));

                    // calculate the route.
                    fromDic[to.Neighbour] = router.Calculate(_data, _interpreter,
                        Vehicle.Car, fromList, toList, double.MaxValue, null); ;
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Called right after the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnAfterContractionEvent(uint vertex, List<Edge<CHEdgeData>> edges)
        {
            // get dictionary for vertex.
            var pathsBeforeContraction = _pathsBeforeContraction[vertex];

            // create a new CHRouter
            var router = new CHRouter();

            // calculate all the routes between the neighbours of the contracted vertex.
            foreach (var from in edges)
            {
                // initialize the from-list.
                var fromList = new PathSegmentVisitList();
                fromList.UpdateVertex(new PathSegment<long>(from.Neighbour));

                // initalize the from dictionary.
                var fromDic = pathsBeforeContraction[from.Neighbour];
                foreach (var to in edges)
                {
                    // initialize the to-list.
                    var toList = new PathSegmentVisitList();
                    toList.UpdateVertex(new PathSegment<long>(to.Neighbour));

                    // calculate the route.
                    var route = router.Calculate(_data, _interpreter, Vehicle.Car, fromList, toList, double.MaxValue, null);
                    if ((fromDic[to.Neighbour] == null && route != null) ||
                        (fromDic[to.Neighbour] != null && route == null))
                    { // the route match!
                        Assert.Fail("Routes are different before/after contraction!");
                    }
                    else if (fromDic[to.Neighbour] != null && route != null)
                    {
                        this.ComparePaths(fromDic[to.Neighbour], route);
                    }
                }
            }

            if (_referenceRouter != null)
            { // do crazy verification!
                var chRouter = Router.CreateCHFrom(_data, router, new OsmRoutingInterpreter());

                // 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));
                        resolved[idx - 1] = chRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                    }

                    Assert.IsNotNull(resolvedReference[idx - 1]);
                    Assert.IsNotNull(resolved[idx - 1]);

                    Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude,
                        resolved[idx - 1].Location.Latitude, 0.0001);
                    Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude,
                        resolved[idx - 1].Location.Longitude, 0.0001);
                }

                // 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)
                        {
                            Route referenceRoute = _referenceRouter.Calculate(Vehicle.Car,
                                resolvedReference[fromIdx], resolvedReference[toIdx]);
                            Route route = chRouter.Calculate(Vehicle.Car,
                                resolved[fromIdx], resolved[toIdx]);

                            if (referenceRoute != null)
                            {
                                Assert.IsNotNull(referenceRoute);
                                Assert.IsNotNull(route);
                                this.CompareRoutes(referenceRoute, route);
                            }
                        }
                    }
                }
            }

            _pathsBeforeContraction.Remove(vertex);
        }
コード例 #13
0
        /// <summary>
        /// Called left before the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnBeforeContractionEvent(uint vertex, KeyValuePair<uint, CHEdgeData>[] edges)
        {
            // create a new CHRouter
            var router = new CHRouter();

            // calculate all the routes between the neighbours of the contracted vertex.
            _pathsBeforeContraction =
                new Dictionary<uint, Dictionary<uint, PathSegment<long>>>();
            foreach (KeyValuePair<uint, CHEdgeData> from in edges)
            {
                // initialize the from-list.
                var fromList = new PathSegmentVisitList();
                fromList.UpdateVertex(new PathSegment<long>(from.Key));

                // initalize the from dictionary.
                var fromDic = new Dictionary<uint, PathSegment<long>>();
                _pathsBeforeContraction[from.Key] = fromDic;
                foreach (KeyValuePair<uint, CHEdgeData> to in edges)
                {
                    // initialize the to-list.
                    var toList = new PathSegmentVisitList();
                    toList.UpdateVertex(new PathSegment<long>(to.Key));

                    // calculate the route.
                    PathSegment<long> route = router.Calculate(_data, _interpreter,
                        OsmSharp.Routing.Vehicle.Car, fromList, toList, double.MaxValue);
                    fromDic[to.Key] = route;
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Called right after the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnAfterContractionEvent(uint vertex, List <Edge <CHEdgeData> > edges)
        {
            // get dictionary for vertex.
            var pathsBeforeContraction = _pathsBeforeContraction[vertex];

            // create a new CHRouter
            var router = new CHRouter();

            // calculate all the routes between the neighbours of the contracted vertex.
            foreach (var from in edges)
            {
                // initialize the from-list.
                var fromList = new PathSegmentVisitList();
                fromList.UpdateVertex(new PathSegment <long>(from.Neighbour));

                // initalize the from dictionary.
                var fromDic = pathsBeforeContraction[from.Neighbour];
                foreach (var to in edges)
                {
                    // initialize the to-list.
                    var toList = new PathSegmentVisitList();
                    toList.UpdateVertex(new PathSegment <long>(to.Neighbour));

                    // calculate the route.
                    var route = router.Calculate(_data, _interpreter, Vehicle.Car, fromList, toList, double.MaxValue, null);
                    if ((fromDic[to.Neighbour] == null && route != null) ||
                        (fromDic[to.Neighbour] != null && route == null))
                    { // the route match!
                        Assert.Fail("Routes are different before/after contraction!");
                    }
                    else if (fromDic[to.Neighbour] != null && route != null)
                    {
                        this.ComparePaths(fromDic[to.Neighbour], route);
                    }
                }
            }

            if (_referenceRouter != null)
            { // do crazy verification!
                var chRouter = Router.CreateCHFrom(_data, router, new OsmRoutingInterpreter());

                // 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));
                        resolved[idx - 1]          = chRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                    }

                    Assert.IsNotNull(resolvedReference[idx - 1]);
                    Assert.IsNotNull(resolved[idx - 1]);

                    Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude,
                                    resolved[idx - 1].Location.Latitude, 0.0001);
                    Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude,
                                    resolved[idx - 1].Location.Longitude, 0.0001);
                }

                // 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)
                        {
                            Route referenceRoute = _referenceRouter.Calculate(Vehicle.Car,
                                                                              resolvedReference[fromIdx], resolvedReference[toIdx]);
                            Route route = chRouter.Calculate(Vehicle.Car,
                                                             resolved[fromIdx], resolved[toIdx]);

                            if (referenceRoute != null)
                            {
                                Assert.IsNotNull(referenceRoute);
                                Assert.IsNotNull(route);
                                this.CompareRoutes(referenceRoute, route);
                            }
                        }
                    }
                }
            }

            _pathsBeforeContraction.Remove(vertex);
        }
コード例 #15
0
        public void TestVerifiedContraction3TinyOneWay()
        {
            var graph = new MemoryDirectedGraph<CHEdgeData>();
            var vertex1 = graph.AddVertex(1, 0);
            var vertex2 = graph.AddVertex(2, 0);
            var vertex3 = graph.AddVertex(3, 0);
            var vertex4 = graph.AddVertex(4, 0);
            var vertex5 = graph.AddVertex(5, 0);

            graph.AddEdge(vertex1, vertex4, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex4, vertex1, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex1, vertex2, new CHEdgeData(1, true, true, false, 10)); // oneway forward
            graph.AddEdge(vertex2, vertex1, new CHEdgeData(1, false, false, true, 10)); // oneway backward.
            graph.AddEdge(vertex1, vertex3, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex3, vertex1, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex2, vertex3, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex3, vertex2, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex2, vertex5, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex5, vertex2, new CHEdgeData(1, false, true, true, 10));

            Assert.IsFalse(graph.ContainsEdges(vertex1, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex3, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex4, vertex1));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex2));
            Assert.IsFalse(graph.ContainsEdges(vertex2, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex3, vertex2));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex5, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex3));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex3));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex2, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex1, vertex5));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex5));

            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor = new CHPreProcessor(graph,
                new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator), witnessCalculator);
            preProcessor.Start();

            var router = new CHRouter();
            // expected: (4)-10s-(1)-10s-(2)-10s-(3) (30s in total).
            var path = router.Calculate(graph, 4, 5);
            Assert.IsNotNull(path);
            Assert.AreEqual(30, path.Weight);
            var pathArray = path.ToArrayWithWeight();
            Assert.AreEqual(4, pathArray.Length);
            float latitude, longitude;
            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(4, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);
            Assert.AreEqual(30, pathArray[3].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[3].Item1, out latitude, out longitude));
            Assert.AreEqual(5, latitude);

            // expected: (5)-10s-(2)-10s-(3)-10s-(1)-10s-(4) (40s in total).
            path = router.Calculate(graph, 5, 4);
            Assert.IsNotNull(path);
            Assert.AreEqual(40, path.Weight);
            pathArray = path.ToArrayWithWeight();
            Assert.AreEqual(5, pathArray.Length);
            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(5, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(3, latitude);
            Assert.AreEqual(30, pathArray[3].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[3].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
            Assert.AreEqual(40, pathArray[4].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[4].Item1, out latitude, out longitude));
            Assert.AreEqual(4, latitude);
        }
コード例 #16
0
        /// <summary>
        /// Called right after the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnAfterContractionEvent(uint vertex, KeyValuePair<uint, CHEdgeData>[] edges)
        {
            // create a new CHRouter
            CHRouter router = new CHRouter(_data);

            // calculate all the routes between the neighbours of the contracted vertex.
            foreach (KeyValuePair<uint, CHEdgeData> from in edges)
            {
                // initialize the from-list.
                PathSegmentVisitList from_list = new PathSegmentVisitList();
                from_list.UpdateVertex(new PathSegment<long>(from.Key));

                // initalize the from dictionary.
                Dictionary<uint, PathSegment<long>> from_dic = _paths_before_contraction[from.Key];
                foreach (KeyValuePair<uint, CHEdgeData> to in edges)
                {
                    // initialize the to-list.
                    PathSegmentVisitList to_list = new PathSegmentVisitList();
                    to_list.UpdateVertex(new PathSegment<long>(to.Key));

                    // calculate the route.
                    PathSegment<long> route = router.Calculate(_data, _interpreter, OsmSharp.Routing.VehicleEnum.Car, from_list, to_list, double.MaxValue);
                    if ((from_dic[to.Key] == null && route != null) ||
                        (from_dic[to.Key] != null && route == null) ||
                        ((from_dic[to.Key] != null && route != null) && from_dic[to.Key] != route))
                    { // the route match!
                        Assert.Fail("Routes are different before/after contraction!");
                    }
                }
            }
        }