示例#1
0
        public void TestMultipleLevelHiearchy5()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 2, 30, null, 1);
            graph.AddEdge(1, 0, 10, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 20, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 4, 70, null, 3);
            graph.AddEdge(3, 2, 30, null, Constants.NO_VERTEX);
            graph.AddEdge(3, 4, 40, null, Constants.NO_VERTEX);

            // create algorithm and run.
            var algorithm = new Itinero.Algorithms.Contracted.BidirectionalDykstra(graph,
                                                                                   new EdgePath <float>[] { new EdgePath <float>(0) }, new EdgePath <float>[] { new EdgePath <float>(4) });

            algorithm.Run();

            // check results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);
            Assert.AreEqual(4, algorithm.Best);
            EdgePath <float> visit;

            Assert.IsTrue(algorithm.TryGetForwardVisit(0, out visit));
            Assert.AreEqual(0, visit.Weight);
            Assert.AreEqual(0, visit.Vertex);
            Assert.AreEqual(null, visit.From);
            Assert.IsTrue(algorithm.TryGetForwardVisit(2, out visit));
            Assert.AreEqual(30, visit.Weight);
            Assert.AreEqual(2, visit.Vertex);
            Assert.IsNotNull(visit.From);
            Assert.AreEqual(0, visit.From.Vertex);
            Assert.IsTrue(algorithm.TryGetForwardVisit(4, out visit));
            Assert.AreEqual(100, visit.Weight);
            Assert.AreEqual(4, visit.Vertex);
            Assert.IsNotNull(visit.From);
            Assert.AreEqual(2, visit.From.Vertex);

            Assert.IsTrue(algorithm.TryGetBackwardVisit(4, out visit));
            Assert.AreEqual(0, visit.Weight);
            Assert.AreEqual(4, visit.Vertex);
            Assert.AreEqual(null, visit.From);

            Assert.AreEqual(new List <uint>(new uint[] { 0, 1, 2, 3, 4 }), algorithm.GetPath());
        }
示例#2
0
        public void TestTwoEdgesLeftMiddleHighest()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(1, 0, 100, false, Constants.NO_VERTEX);
            graph.AddEdge(2, 1, 100, false, Constants.NO_VERTEX);

            // create algorithm and run.
            var algorithm = new Itinero.Algorithms.Contracted.BidirectionalDykstra(graph,
                                                                                   new EdgePath <float>[] { new EdgePath <float>(0) }, new EdgePath <float>[] { new EdgePath <float>(2) });

            algorithm.Run();

            // check results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);
            Assert.AreEqual(0, algorithm.Best);
            EdgePath <float> visit;

            Assert.IsTrue(algorithm.TryGetForwardVisit(0, out visit));
            Assert.AreEqual(0, visit.Weight);
            Assert.AreEqual(0, visit.Vertex);
            Assert.AreEqual(null, visit.From);

            Assert.IsTrue(algorithm.TryGetBackwardVisit(2, out visit));
            Assert.AreEqual(0, visit.Weight);
            Assert.AreEqual(2, visit.Vertex);
            Assert.AreEqual(null, visit.From);
            Assert.IsTrue(algorithm.TryGetBackwardVisit(1, out visit));
            Assert.AreEqual(100, visit.Weight);
            Assert.AreEqual(1, visit.Vertex);
            Assert.IsNotNull(visit.From);
            Assert.AreEqual(2, visit.From.Vertex);
            Assert.IsTrue(algorithm.TryGetBackwardVisit(0, out visit));
            Assert.AreEqual(200, visit.Weight);
            Assert.AreEqual(0, visit.Vertex);
            Assert.IsNotNull(visit.From);
            Assert.AreEqual(1, visit.From.Vertex);

            Assert.AreEqual(new List <uint>(new uint[] { 0, 1, 2 }), algorithm.GetPath());
        }
示例#3
0
        public void TestShorterEdgeOpposite()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(1, 0, 100, false, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 10, true, 3);
            graph.AddEdge(3, 0, 5, true, Constants.NO_VERTEX);
            graph.AddEdge(3, 1, 5, false, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 10, null, Constants.NO_VERTEX);
            graph.AddEdge(0, 2, 110, true, 1);
            graph.AddEdge(0, 2, 20, false, 1);

            // create algorithm and run.
            var algorithm = new Itinero.Algorithms.Contracted.BidirectionalDykstra(graph,
                                                                                   new EdgePath <float>[] { new EdgePath <float>(0) }, new EdgePath <float>[] { new EdgePath <float>(2) });

            algorithm.Run();

            // check results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);
            Assert.AreEqual(2, algorithm.Best);

            Assert.AreEqual(new List <uint>(new uint[] { 0, 1, 2 }), algorithm.GetPath());

            // create algorithm and run.
            algorithm = new Itinero.Algorithms.Contracted.BidirectionalDykstra(graph,
                                                                               new EdgePath <float>[] { new EdgePath <float>(2) }, new EdgePath <float>[] { new EdgePath <float>(0) });
            algorithm.Run();

            // check results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);
            Assert.AreEqual(2, algorithm.Best);

            Assert.AreEqual(new List <uint>(new uint[] { 2, 1, 3, 0 }), algorithm.GetPath());
        }