Пример #1
0
        public void TestWithinOneEdge()
        {
            // build graph.
            var routerDb = new RouterDb();

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

            // run algorithm.
            var algorithm = new ManyToManyWeightsBidirectionalDykstra(new Router(routerDb), VehicleMock.Car().Fastest(),
                                                                      new RouterPoint[] { new RouterPoint(0, 0, 0, ushort.MaxValue / 10) },
                                                                      new RouterPoint[] { new RouterPoint(1, 1, 0, ushort.MaxValue / 10 * 9) });

            algorithm.Run();

            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);

            Assert.IsNotNull(algorithm.Weights);
            Assert.AreEqual(1, algorithm.Weights.Length);
            Assert.AreEqual(1, algorithm.Weights[0].Length);
            Assert.AreEqual(VehicleMock.Car().Fastest().FactorAndSpeed(null).Value * 80, algorithm.Weights[0][0], SecondsTolerance);
        }
Пример #2
0
        public void TestPentagon()
        {
            var routerDb = new RouterDb();

            routerDb.AddSupportedVehicle(VehicleMock.Car());
            routerDb.Network.AddVertex(0, 0, 0);
            routerDb.Network.AddVertex(1, 1, 1);
            routerDb.Network.AddVertex(2, 2, 2);
            routerDb.Network.AddVertex(3, 3, 3);
            routerDb.Network.AddVertex(4, 4, 4);
            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, 3, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 100,
                Profile  = 0,
                MetaId   = 0
            });
            routerDb.Network.AddEdge(3, 4, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 100,
                Profile  = 0,
                MetaId   = 0
            });
            routerDb.Network.AddEdge(4, 0, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 100,
                Profile  = 0,
                MetaId   = 0
            });

            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null);
            graph.AddEdge(0, 4, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null);
            graph.AddEdge(2, 1, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null);
            graph.AddEdge(2, 3, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null);
            graph.AddEdge(3, 1, 200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null, 2, null, null);
            graph.AddEdge(4, 1, 200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null, 0, null, null);
            graph.AddEdge(4, 3, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null);
            routerDb.AddContracted(VehicleMock.Car().Fastest(), new ContractedDb(graph));

            // create algorithm and run.
            var algorithm = new ManyToManyWeightsBidirectionalDykstra(new Router(routerDb), VehicleMock.Car().Fastest(),
                                                                      new RouterPoint[] {
                routerDb.Network.CreateRouterPointForVertex(0),
                routerDb.Network.CreateRouterPointForVertex(1),
                routerDb.Network.CreateRouterPointForVertex(2),
                routerDb.Network.CreateRouterPointForVertex(3),
                routerDb.Network.CreateRouterPointForVertex(4)
            },
                                                                      new RouterPoint[] {
                routerDb.Network.CreateRouterPointForVertex(0),
                routerDb.Network.CreateRouterPointForVertex(1),
                routerDb.Network.CreateRouterPointForVertex(2),
                routerDb.Network.CreateRouterPointForVertex(3),
                routerDb.Network.CreateRouterPointForVertex(4)
            });

            algorithm.Run();

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

            Assert.IsNotNull(algorithm.Weights);
            Assert.AreEqual(5, algorithm.Weights.Length);

            Assert.AreEqual(5, algorithm.Weights[0].Length);
            Assert.AreEqual(5, algorithm.Weights[1].Length);
            Assert.AreEqual(5, algorithm.Weights[2].Length);
            Assert.AreEqual(5, algorithm.Weights[3].Length);
            Assert.AreEqual(5, algorithm.Weights[4].Length);

            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][0], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][1], SecondsTolerance);
            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][2], SecondsTolerance);
            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][3], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][4], SecondsTolerance);

            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][0], SecondsTolerance);
            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][1], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][2], SecondsTolerance);
            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][3], SecondsTolerance);
            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][4], SecondsTolerance);

            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][0], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][1], SecondsTolerance);
            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][2], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][3], SecondsTolerance);
            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][4], SecondsTolerance);
        }
Пример #3
0
        public void TestThreeEdges()
        {
            // build graph.
            var routerDb = new RouterDb();

            routerDb.AddSupportedVehicle(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(VehicleMock.Car().Fastest());

            // run algorithm (0, 1, 2)->(0, 1, 2).
            var algorithm = new ManyToManyWeightsBidirectionalDykstra(new Router(routerDb), VehicleMock.Car().Fastest(),
                                                                      new RouterPoint[] {
                routerDb.Network.CreateRouterPointForVertex(0),
                routerDb.Network.CreateRouterPointForVertex(1),
                routerDb.Network.CreateRouterPointForVertex(2)
            },
                                                                      new RouterPoint[] {
                routerDb.Network.CreateRouterPointForVertex(0),
                routerDb.Network.CreateRouterPointForVertex(1),
                routerDb.Network.CreateRouterPointForVertex(2)
            });

            algorithm.Run(); Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);

            var weights = algorithm.Weights;

            Assert.IsNotNull(weights);
            Assert.AreEqual(3, weights.Length);
            Assert.AreEqual(3, weights[0].Length);
            Assert.AreEqual(0, weights[0][0], 0.001);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[0][1], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[0][2], SecondsTolerance);
            Assert.AreEqual(3, weights[1].Length);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[1][0], SecondsTolerance);
            Assert.AreEqual(0, weights[1][1], 0.001);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[1][2], SecondsTolerance);
            Assert.AreEqual(3, weights[2].Length);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[2][0], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[2][1], SecondsTolerance);
            Assert.AreEqual(0, weights[2][2], 0.001);
        }
Пример #4
0
        public void TestTwoEdgesLeftMiddleHighest()
        {
            // build graph.
            var oneway = VehicleMock.Car(t => new FactorAndSpeed()
            {
                Value       = VehicleMock.Car().Fastest().FactorAndSpeed(null).Value,
                SpeedFactor = VehicleMock.Car().Fastest().FactorAndSpeed(null).SpeedFactor,
                Direction   = 1
            }).Fastest();
            var routerDb = new RouterDb();

            routerDb.AddSupportedVehicle(oneway.Parent);
            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
            });

            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(1, 0, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, false);
            graph.AddEdge(2, 1, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, false);
            routerDb.AddContracted(VehicleMock.Car().Fastest(), new ContractedDb(graph));

            // create algorithm and run.
            var algorithm = new ManyToManyWeightsBidirectionalDykstra(new Router(routerDb), oneway,
                                                                      new RouterPoint[] {
                routerDb.Network.CreateRouterPointForVertex(0),
                routerDb.Network.CreateRouterPointForVertex(1),
                routerDb.Network.CreateRouterPointForVertex(2)
            },
                                                                      new RouterPoint[] {
                routerDb.Network.CreateRouterPointForVertex(0),
                routerDb.Network.CreateRouterPointForVertex(1),
                routerDb.Network.CreateRouterPointForVertex(2)
            });

            algorithm.Run();

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

            Assert.IsNotNull(algorithm.Weights);
            Assert.AreEqual(3, algorithm.Weights.Length);
            Assert.AreEqual(3, algorithm.Weights[0].Length);
            Assert.AreEqual(3, algorithm.Weights[1].Length);
            Assert.AreEqual(3, algorithm.Weights[2].Length);

            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][0], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][1], SecondsTolerance);
            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][2], SecondsTolerance);
            Assert.AreEqual(float.MaxValue, algorithm.Weights[1][0]);
            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][1], SecondsTolerance);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][2], SecondsTolerance);
            Assert.AreEqual(float.MaxValue, algorithm.Weights[2][0]);
            Assert.AreEqual(float.MaxValue, algorithm.Weights[2][1]);
            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][2], SecondsTolerance);
        }
Пример #5
0
        public void TestTwoEdgesMiddleHighest()
        {
            // build graph.
            var routerDb = new RouterDb();

            routerDb.AddSupportedVehicle(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
            });

            // build graph.
            var graph = new DirectedDynamicGraph();

            graph.AddEdge(0, 1, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null);
            graph.AddEdge(2, 1, 100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, null);
            routerDb.AddContracted(VehicleMock.Car().Fastest(), new ContractedDb(graph));

            // create algorithm and run.
            var algorithm = new ManyToManyWeightsBidirectionalDykstra(new Router(routerDb), VehicleMock.Car().Fastest(),
                                                                      new RouterPoint[] {
                routerDb.Network.CreateRouterPointForVertex(0),
                routerDb.Network.CreateRouterPointForVertex(1),
                routerDb.Network.CreateRouterPointForVertex(2)
            },
                                                                      new RouterPoint[] {
                routerDb.Network.CreateRouterPointForVertex(0),
                routerDb.Network.CreateRouterPointForVertex(1),
                routerDb.Network.CreateRouterPointForVertex(2)
            });

            algorithm.Run();

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

            Assert.IsNotNull(algorithm.Weights);
            Assert.AreEqual(3, algorithm.Weights.Length);
            Assert.AreEqual(3, algorithm.Weights[0].Length);
            Assert.AreEqual(3, algorithm.Weights[1].Length);
            Assert.AreEqual(3, algorithm.Weights[2].Length);

            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][0], 0.1);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][1], 0.1);
            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[0][2], 0.1);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][0], 0.1);
            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][1], 0.1);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[1][2], 0.1);
            Assert.AreEqual(200 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][0], 0.1);
            Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][1], 0.1);
            Assert.AreEqual(000 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, algorithm.Weights[2][2], 0.1);
        }