public void TestWithinOneEdge() { // build graph. var routerDb = new RouterDb(); routerDb.AddSupportedVehicle(VehicleMock.Car()); routerDb.Network.AddVertex(0, 0, 0); routerDb.Network.AddVertex(1, 1, 1); routerDb.Network.AddEdge(0, 1, new Itinero.Data.Network.Edges.EdgeData() { Distance = 100, Profile = 0, MetaId = 0 }); // run algorithm. var algorithm = new OneToMany(new Router(routerDb), VehicleMock.Car().Fastest(), (x) => new uint[0][], new RouterPoint(0, 0, 0, ushort.MaxValue / 10), new RouterPoint[] { new RouterPoint(1, 1, 0, ushort.MaxValue / 10 * 9) }, float.MaxValue); algorithm.Run(); Assert.IsTrue(algorithm.HasRun); Assert.IsTrue(algorithm.HasSucceeded); var path = algorithm.GetPath(0); Assert.IsNotNull(path); Assert.AreEqual(Constants.NO_VERTEX, path.Vertex); Assert.AreEqual(VehicleMock.Car().Fastest().FactorAndSpeed(null).Value * 80, path.Weight, 0.01); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(Constants.NO_VERTEX, path.Vertex); Assert.AreEqual(0, path.Weight); path = path.From; Assert.IsNull(path); }
public void TestOneEdge() { // build graph. var routerDb = new RouterDb(); routerDb.AddSupportedProfile(MockProfile.CarMock()); 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 }); // run algorithm. var algorithm = new OneToMany(new Router(routerDb), MockProfile.CarMock(), new RouterPoint(0, 0, 0, 0), new RouterPoint[] { new RouterPoint(1, 1, 0, ushort.MaxValue) }, float.MaxValue); algorithm.Run(); Assert.IsTrue(algorithm.HasRun); Assert.IsTrue(algorithm.HasSucceeded); var path = algorithm.GetPath(0); Assert.IsNotNull(path); Assert.AreEqual(1, path.Vertex); Assert.AreEqual(MockProfile.CarMock().Factor(null).Value * 100, path.Weight); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Vertex); Assert.AreEqual(0, path.Weight); path = path.From; Assert.IsNull(path); }
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 }); // run algorithm 0->(1, 2). var algorithm = new OneToMany(new Router(routerDb), VehicleMock.Car().Fastest(), (x) => new uint[0][], routerDb.Network.CreateRouterPointForVertex(0), new RouterPoint[] { routerDb.Network.CreateRouterPointForVertex(1), routerDb.Network.CreateRouterPointForVertex(2) }, float.MaxValue); algorithm.Run(); Assert.IsTrue(algorithm.HasRun); Assert.IsTrue(algorithm.HasSucceeded); var weights = algorithm.Weights; Assert.IsNotNull(weights); Assert.AreEqual(2, weights.Length); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[0], 0.001); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[1], 0.001); var path = algorithm.GetPath(0); Assert.IsNotNull(path); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, path.Weight, 0.001); Assert.AreEqual(1, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001); Assert.AreEqual(0, path.Vertex); path = path.From; Assert.IsNull(path); path = algorithm.GetPath(1); Assert.IsNotNull(path); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, path.Weight, 0.001); Assert.AreEqual(2, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001); Assert.AreEqual(0, path.Vertex); path = path.From; Assert.IsNull(path); // run algorithm 1->(0, 2). algorithm = new OneToMany(new Router(routerDb), VehicleMock.Car().Fastest(), (x) => new uint[0][], routerDb.Network.CreateRouterPointForVertex(1), new RouterPoint[] { routerDb.Network.CreateRouterPointForVertex(0), routerDb.Network.CreateRouterPointForVertex(2) }, float.MaxValue); algorithm.Run(); Assert.IsTrue(algorithm.HasRun); Assert.IsTrue(algorithm.HasSucceeded); weights = algorithm.Weights; Assert.IsNotNull(weights); Assert.AreEqual(2, weights.Length); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[0], 0.001); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[1], 0.001); path = algorithm.GetPath(0); Assert.IsNotNull(path); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, path.Weight, 0.001); Assert.AreEqual(0, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001); Assert.AreEqual(1, path.Vertex); path = path.From; Assert.IsNull(path); path = algorithm.GetPath(1); Assert.IsNotNull(path); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, path.Weight, 0.001); Assert.AreEqual(2, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001); Assert.AreEqual(1, path.Vertex); path = path.From; Assert.IsNull(path); // run algorithm 2->(0, 1). algorithm = new OneToMany(new Router(routerDb), VehicleMock.Car().Fastest(), (x) => new uint[0][], routerDb.Network.CreateRouterPointForVertex(2), new RouterPoint[] { routerDb.Network.CreateRouterPointForVertex(0), routerDb.Network.CreateRouterPointForVertex(1) }, float.MaxValue); algorithm.Run(); Assert.IsTrue(algorithm.HasRun); Assert.IsTrue(algorithm.HasSucceeded); weights = algorithm.Weights; Assert.IsNotNull(weights); Assert.AreEqual(2, weights.Length); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[0], 0.001); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, weights[1], 0.001); path = algorithm.GetPath(0); Assert.IsNotNull(path); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, path.Weight, 0.001); Assert.AreEqual(0, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001); Assert.AreEqual(2, path.Vertex); path = path.From; Assert.IsNull(path); path = algorithm.GetPath(1); Assert.IsNotNull(path); Assert.AreEqual(100 * VehicleMock.Car().Fastest().FactorAndSpeed(null).Value, path.Weight, 0.001); Assert.AreEqual(1, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001); Assert.AreEqual(2, path.Vertex); path = path.From; Assert.IsNull(path); }