Exemple #1
0
        public void TestUTurn()
        {
            // build graph.
            var routerDb = new RouterDb();

            routerDb.AddSupportedVehicle(Profiles.VehicleMock.Car());
            routerDb.Network.AddVertex(0, 0, 0);
            routerDb.Network.AddVertex(1, 1, 1);
            routerDb.Network.AddVertex(2, 2, 2);
            routerDb.Network.AddEdge(0, 1, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 100,
                Profile  = 0,
                MetaId   = 0
            });
            routerDb.Network.AddEdge(1, 2, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 100,
                Profile  = 0,
                MetaId   = 0
            });
            routerDb.Network.AddEdge(2, 0, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 100,
                Profile  = 0,
                MetaId   = 0
            });
            routerDb.AddEdgeBasedContractedForTesting(Profiles.VehicleMock.Car().Fastest());
            Itinero.Data.Contracted.ContractedDb contractedDb;
            routerDb.TryGetContracted(Profiles.VehicleMock.Car().Fastest(), out contractedDb);

            var dykstra = new Itinero.Algorithms.Contracted.EdgeBased.Dykstra(contractedDb.EdgeBasedGraph,
                                                                              new EdgePath <float>[] { new EdgePath <float>(0, 100 * Profiles.VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, -1, new EdgePath <float>(1)) },
                                                                              (i) => null, false);

            dykstra.Run();

            EdgePath <float> path;

            Assert.IsTrue(dykstra.TryGetVisit(0, out path));
            Assert.AreEqual(0, path.Vertex);
            Assert.AreEqual(1, path.From.Vertex);

            Assert.IsTrue(dykstra.TryGetVisit(1, out path));
            Assert.AreEqual(1, path.Vertex);
            Assert.AreEqual(2, path.From.Vertex);
            Assert.AreEqual(0, path.From.From.Vertex);
            Assert.AreEqual(1, path.From.From.From.Vertex);

            Assert.IsTrue(dykstra.TryGetVisit(2, out path));
            Assert.AreEqual(2, path.Vertex);
            Assert.AreEqual(0, path.From.Vertex);
            Assert.AreEqual(1, path.From.From.Vertex);
        }
Exemple #2
0
        public void TestTwoEdgesMiddleHighest()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100, null);
            graph.AddEdge(2, 1, 100, null);

            // create algorithm and run.
            var algorithm = new Itinero.Algorithms.Contracted.EdgeBased.Dykstra(graph,
                                                                                new EdgePath <float>[] { new EdgePath <float>(0) },
                                                                                (v) => null, true);

            algorithm.Run();

            // check results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);

            EdgePath <float> visit;

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

            // create algorithm and run.
            algorithm = new Itinero.Algorithms.Contracted.EdgeBased.Dykstra(graph,
                                                                            new EdgePath <float>[] { new EdgePath <float>(0) },
                                                                            (v) => null, false);
            algorithm.Run();

            // check results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);

            Assert.IsTrue(algorithm.TryGetVisit(0, out visit));
            Assert.AreEqual(0, visit.Weight);
            Assert.AreEqual(0, visit.Vertex);
            Assert.AreEqual(null, visit.From);
            Assert.IsTrue(algorithm.TryGetVisit(1, out visit));
            Assert.AreEqual(100, visit.Weight);
            Assert.AreEqual(1, visit.Vertex);
            Assert.IsNotNull(visit.From);
            Assert.AreEqual(0, visit.From.Vertex);
            Assert.IsFalse(algorithm.TryGetVisit(2, out visit));
        }
Exemple #3
0
        /// <summary>
        /// Executes the actual run.
        /// </summary>
        protected override void DoRun()
        {
            // put in default weights and weights for one-edge-paths.
            _paths = new Solution[_sources.Length][];
            for (var i = 0; i < _sources.Length; i++)
            {
                var source = _sources[i];
                _paths[i] = new Solution[_targets.Length];
                for (var j = 0; j < _targets.Length; j++)
                {
                    var target = _targets[j];

                    if (target.EdgeId == source.EdgeId)
                    {
                        var path = source.EdgePathTo(_routerDb, _weightHandler, target);
                        if (path != null)
                        {
                            _paths[i][j] = new Solution()
                            {
                                Path = path
                            };
                        }
                    }
                }
            }

            // do forward searches into buckets.
            for (var i = 0; i < _sources.Length; i++)
            {
                var forward = new Dykstra <T>(_graph, _weightHandler, _sources[i].ToEdgePaths(_routerDb, _weightHandler, true), _routerDb.GetGetRestrictions(_profile, null), false, _max);
                forward.WasFound += (path) =>
                {
                    return(this.ForwardVertexFound(i, path));
                };
                forward.Run();
            }

            // do backward searches into buckets.
            for (var i = 0; i < _targets.Length; i++)
            {
                var backward = new Dykstra <T>(_graph, _weightHandler, _targets[i].ToEdgePaths(_routerDb, _weightHandler, false), _routerDb.GetGetRestrictions(_profile, null), true, _max);
                backward.WasFound += (path) =>
                {
                    return(this.BackwardVertexFound(i, path));
                };
                backward.Run();
            }
            this.HasSucceeded = true;
        }