public void TestDistanceTo() { // build router db. var routerDb = new RouterDb(); routerDb.Network.AddVertex(0, 0, 0); routerDb.Network.AddVertex(1, .1f, .1f); routerDb.Network.AddEdge(0, 1, new EdgeData() { Distance = 1000, MetaId = routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("name", "Abelshausen Blvd."))), Profile = (ushort)routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("highway", "residential"))) }, new Coordinate(0.025f, 0.025f), new Coordinate(0.050f, 0.050f), new Coordinate(0.075f, 0.075f)); // mock profile. var profile = MockProfile.CarMock(); var point = new RouterPoint(0.04f, 0.04f, 0, (ushort)(0.4 * ushort.MaxValue)); var distance = point.DistanceTo(routerDb, 0); Assert.AreEqual(Coordinate.DistanceEstimateInMeter(new Coordinate(0, 0), new Coordinate(0.04f, 0.04f)), distance, 0.001); distance = point.DistanceTo(routerDb, 1); Assert.AreEqual(Coordinate.DistanceEstimateInMeter(new Coordinate(.1f, .1f), new Coordinate(0.04f, 0.04f)), distance, 0.001); }
public void TestWithinOneEdge() { // 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 }); routerDb.AddContracted(MockProfile.CarMock()); // run algorithm. var algorithm = new ManyToManyBidirectionalDykstra(new Router(routerDb), MockProfile.CarMock(), 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(MockProfile.CarMock().Factor(null).Value * 80, algorithm.Weights[0][0], 0.01); }
public void TestShapePointsTo() { var routerDb = new RouterDb(); routerDb.Network.AddVertex(0, 0, 0); routerDb.Network.AddVertex(1, .1f, .1f); routerDb.Network.AddEdge(0, 1, new EdgeData() { Distance = 1000, MetaId = routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("name", "Abelshausen Blvd."))), Profile = (ushort)routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("highway", "residential"))) }, new Coordinate(0.025f, 0.025f), new Coordinate(0.050f, 0.050f), new Coordinate(0.075f, 0.075f)); // mock profile. var profile = MockProfile.CarMock(); var point = new RouterPoint(0.04f, 0.04f, 0, (ushort)(0.4 * ushort.MaxValue)); var shape = point.ShapePointsTo(routerDb, 0); Assert.IsNotNull(shape); Assert.AreEqual(1, shape.Count); Assert.AreEqual(0.025, shape[0].Latitude, 0.001); Assert.AreEqual(0.025, shape[0].Longitude, 0.001); shape = point.ShapePointsTo(routerDb, 1); Assert.IsNotNull(shape); Assert.AreEqual(2, shape.Count); Assert.AreEqual(0.050, shape[0].Latitude, 0.001); Assert.AreEqual(0.050, shape[0].Longitude, 0.001); Assert.AreEqual(0.075, shape[1].Latitude, 0.001); Assert.AreEqual(0.075, shape[1].Longitude, 0.001); var point1 = new RouterPoint(0.04f, 0.04f, 0, (ushort)(0.4 * ushort.MaxValue)); var point2 = new RouterPoint(0.08f, 0.08f, 0, (ushort)(0.8 * ushort.MaxValue)); shape = point1.ShapePointsTo(routerDb, point2); Assert.IsNotNull(shape); Assert.AreEqual(2, shape.Count); Assert.AreEqual(0.050, shape[0].Latitude, 0.001); Assert.AreEqual(0.050, shape[0].Longitude, 0.001); Assert.AreEqual(0.075, shape[1].Latitude, 0.001); Assert.AreEqual(0.075, shape[1].Longitude, 0.001); shape = point2.ShapePointsTo(routerDb, point1); Assert.IsNotNull(shape); Assert.AreEqual(2, shape.Count); Assert.AreEqual(0.075, shape[0].Latitude, 0.001); Assert.AreEqual(0.075, shape[0].Longitude, 0.001); Assert.AreEqual(0.050, shape[1].Latitude, 0.001); Assert.AreEqual(0.050, shape[1].Longitude, 0.001); }
public void TestCustomResolverDelegate() { var routerDb = new RouterDb(); routerDb.AddSupportedProfile(MockProfile.CarMock()); var router = new Router(routerDb); var called = false; router.CreateCustomResolver = (latitude, longitude, isAcceptable, isBetter) => { called = true; return(new MockResolver(new RouterPoint(latitude, longitude, 0, 0))); }; router.Resolve(new Itinero.Profiles.Profile[] { MockProfile.CarMock() }, 0, 0); Assert.IsTrue(called); }
public void TestLocationOnNetwork() { var routerDb = new RouterDb(); routerDb.Network.AddVertex(0, 0, 0); routerDb.Network.AddVertex(1, .1f, -.1f); routerDb.Network.AddEdge(0, 1, new EdgeData() { Distance = 1000, MetaId = routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("name", "Abelshausen Blvd."))), Profile = (ushort)routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("highway", "residential"))) }, new Coordinate(0.025f, -0.025f), new Coordinate(0.050f, -0.050f), new Coordinate(0.075f, -0.075f)); // mock profile. var profile = MockProfile.CarMock(); var point = new RouterPoint(0.04f, -0.04f, 0, (ushort)(0.4 * ushort.MaxValue)); var location = point.LocationOnNetwork(routerDb); Assert.AreEqual(0.04f, location.Latitude, 0.001f); Assert.AreEqual(-0.04f, location.Longitude, 0.001f); point = new RouterPoint(0.08f, -0.08f, 0, (ushort)(0.8 * ushort.MaxValue)); location = point.LocationOnNetwork(routerDb); Assert.AreEqual(0.08f, location.Latitude, 0.001f); Assert.AreEqual(-0.08f, location.Longitude, 0.001f); point = new RouterPoint(0, 0, 0, 0); location = point.LocationOnNetwork(routerDb); Assert.AreEqual(0, location.Latitude, 0.001f); Assert.AreEqual(0, location.Longitude, 0.001f); point = new RouterPoint(.1f, -.1f, 0, ushort.MaxValue); location = point.LocationOnNetwork(routerDb); Assert.AreEqual(.1f, location.Latitude, 0.001f); Assert.AreEqual(-.1f, location.Longitude, 0.001f); }
public void TestWithinOneEdge() { // 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 ManyToMany(new Router(routerDb), MockProfile.CarMock(), new RouterPoint[] { 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, 0); Assert.IsNotNull(path); Assert.AreEqual(Constants.NO_VERTEX, path.Vertex); Assert.AreEqual(MockProfile.CarMock().Factor(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 TestPentagon() { var routerDb = new RouterDb(); routerDb.AddSupportedProfile(MockProfile.CarMock()); 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 DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100 * MockProfile.CarMock().Factor(null).Value, null, Constants.NO_VERTEX); graph.AddEdge(0, 4, 100 * MockProfile.CarMock().Factor(null).Value, null, Constants.NO_VERTEX); graph.AddEdge(2, 1, 100 * MockProfile.CarMock().Factor(null).Value, null, Constants.NO_VERTEX); graph.AddEdge(2, 3, 100 * MockProfile.CarMock().Factor(null).Value, null, Constants.NO_VERTEX); graph.AddEdge(3, 1, 200 * MockProfile.CarMock().Factor(null).Value, null, 2); graph.AddEdge(4, 1, 200 * MockProfile.CarMock().Factor(null).Value, null, 0); graph.AddEdge(4, 3, 100 * MockProfile.CarMock().Factor(null).Value, null, Constants.NO_VERTEX); routerDb.AddContracted(MockProfile.CarMock(), new ContractedDb(graph)); // create algorithm and run. var algorithm = new ManyToManyBidirectionalDykstra(new Router(routerDb), MockProfile.CarMock(), 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 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][0], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][1], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][2], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][3], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][4], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][0], 0.1); Assert.AreEqual(000 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][1], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][2], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][3], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][4], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][0], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][1], 0.1); Assert.AreEqual(000 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][2], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][3], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][4], 0.1); }
public void TestTwoEdgesLeftMiddleHighest() { // build graph. var oneway = MockProfile.CarMock(t => new Speed() { Value = MockProfile.CarMock().Speed(null).Value, Direction = 1 }); var routerDb = new RouterDb(); routerDb.AddSupportedProfile(oneway); 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 DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(1, 0, 100 * MockProfile.CarMock().Factor(null).Value, false, Constants.NO_VERTEX); graph.AddEdge(2, 1, 100 * MockProfile.CarMock().Factor(null).Value, false, Constants.NO_VERTEX); routerDb.AddContracted(MockProfile.CarMock(), new ContractedDb(graph)); // create algorithm and run. var algorithm = new ManyToManyBidirectionalDykstra(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 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][0], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][1], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][2], 0.1); Assert.AreEqual(float.MaxValue, algorithm.Weights[1][0]); Assert.AreEqual(000 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][1], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][2], 0.1); Assert.AreEqual(float.MaxValue, algorithm.Weights[2][0]); Assert.AreEqual(float.MaxValue, algorithm.Weights[2][1]); Assert.AreEqual(000 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][2], 0.1); }
public void TestThreeEdges() { // build graph. var routerDb = new RouterDb(); routerDb.AddSupportedProfile(MockProfile.CarMock()); 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.AddContracted(MockProfile.CarMock()); // run algorithm (0, 1, 2)->(0, 1, 2). var algorithm = new ManyToManyBidirectionalDykstra(new Router(routerDb), MockProfile.CarMock(), 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 * MockProfile.CarMock().Factor(null).Value, weights[0][1], 0.01); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[0][2], 0.01); Assert.AreEqual(3, weights[1].Length); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[1][0], 0.01); Assert.AreEqual(0, weights[1][1], 0.001); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[1][2], 0.01); Assert.AreEqual(3, weights[2].Length); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[2][0], 0.01); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[2][1], 0.01); Assert.AreEqual(0, weights[2][2], 0.001); }
public void TestToEdgePaths() { var distance = Coordinate.DistanceEstimateInMeter(new Coordinate(0, 0), new Coordinate(0.1f, 0.1f)); // build router db. var routerDb = new RouterDb(Itinero.Data.Edges.EdgeDataSerializer.MAX_DISTANCE); routerDb.Network.AddVertex(0, 0, 0); routerDb.Network.AddVertex(1, .1f, .1f); routerDb.Network.AddEdge(0, 1, new EdgeData() { Distance = distance, MetaId = routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("name", "Abelshausen Blvd."))), Profile = (ushort)routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("highway", "residential"))) }, new Coordinate(0.025f, 0.025f), new Coordinate(0.050f, 0.050f), new Coordinate(0.075f, 0.075f)); // mock profile. var profile = MockProfile.CarMock(); var point = new RouterPoint(0.04f, 0.04f, 0, (ushort)(0.4 * ushort.MaxValue)); var paths = point.ToEdgePaths(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), false); var factor = profile.Factor(new AttributeCollection( new Attribute("highway", "residential"))); var weight0 = Coordinate.DistanceEstimateInMeter(new Coordinate(0, 0), new Coordinate(0.04f, 0.04f)) * factor.Value; var weight1 = Coordinate.DistanceEstimateInMeter(new Coordinate(.1f, .1f), new Coordinate(0.04f, 0.04f)) * factor.Value; Assert.IsNotNull(paths); Assert.AreEqual(2, paths.Length); Assert.IsNotNull(paths.First(x => x.Vertex == 0)); Assert.AreEqual(weight0, paths.First(x => x.Vertex == 0).Weight, 0.01); Assert.IsNotNull(paths.First(x => x.Vertex == 0).From); Assert.AreEqual(Constants.NO_VERTEX, paths.First(x => x.Vertex == 0).From.Vertex); Assert.IsNotNull(paths.First(x => x.Vertex == 1)); Assert.AreEqual(weight1, paths.First(x => x.Vertex == 1).Weight, 0.01); Assert.IsNotNull(paths.First(x => x.Vertex == 1).From); Assert.AreEqual(Constants.NO_VERTEX, paths.First(x => x.Vertex == 1).From.Vertex); point = new RouterPoint(0, 0, 0, 0); paths = point.ToEdgePaths(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), true); Assert.IsNotNull(paths.First(x => x.Vertex == 0)); Assert.AreEqual(0, paths.First(x => x.Vertex == 0).Weight, 0.01); Assert.IsNull(paths.First(x => x.Vertex == 0).From); Assert.IsNotNull(paths.First(x => x.Vertex == 1)); Assert.AreEqual(distance * profile.Factor(null).Value, paths.First(x => x.Vertex == 1).Weight, 0.01); Assert.IsNotNull(paths.First(x => x.Vertex == 1).From); Assert.AreEqual(0, paths.First(x => x.Vertex == 1).From.Vertex); point = new RouterPoint(.1f, .1f, 0, ushort.MaxValue); paths = point.ToEdgePaths(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), true); Assert.IsNotNull(paths.First(x => x.Vertex == 0)); Assert.AreEqual(distance * profile.Factor(null).Value, paths.First(x => x.Vertex == 0).Weight, 0.01); Assert.IsNotNull(paths.First(x => x.Vertex == 0).From); Assert.AreEqual(1, paths.First(x => x.Vertex == 0).From.Vertex); Assert.IsNotNull(paths.First(x => x.Vertex == 1)); Assert.AreEqual(0, paths.First(x => x.Vertex == 1).Weight, 0.01); Assert.IsNull(paths.First(x => x.Vertex == 1).From); }
public void TestEdgePathTo() { // build router db. var routerDb = new RouterDb(); routerDb.Network.AddVertex(0, 0, 0); routerDb.Network.AddVertex(1, .1f, .1f); routerDb.Network.AddEdge(0, 1, new EdgeData() { Distance = 1000, MetaId = routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("name", "Abelshausen Blvd."))), Profile = (ushort)routerDb.EdgeProfiles.Add(new AttributeCollection( new Attribute("highway", "residential"))) }, new Coordinate(0.025f, 0.025f), new Coordinate(0.050f, 0.050f), new Coordinate(0.075f, 0.075f)); // mock profile. var profile = MockProfile.CarMock(); var point1 = new RouterPoint(0.01f, 0.01f, 0, (ushort)(0.1 * ushort.MaxValue)); var point2 = new RouterPoint(0.09f, 0.09f, 0, (ushort)(0.9 * ushort.MaxValue)); var path = point1.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point2); Assert.IsNotNull(path); Assert.AreEqual(800 * profile.Factor(new AttributeCollection( new Attribute("highway", "residential"))).Value, path.Weight, 0.001f); path = point2.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point1); Assert.IsNotNull(path); Assert.AreEqual(800 * profile.Factor(new AttributeCollection( new Attribute("highway", "residential"))).Value, path.Weight, 0.001f); path = point1.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point1); Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001f); path = point2.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point2); Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001f); // mock profile and force oneway forward. profile = MockProfile.CarMock(x => new Speed() { Value = 50f / 3.6f, Direction = 1 }); path = point1.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point2); Assert.IsNotNull(path); Assert.AreEqual(800 * profile.Factor(new AttributeCollection( new Attribute("highway", "residential"))).Value, path.Weight, 0.001f); path = point2.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point1); Assert.IsNull(path); path = point1.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point1); Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001f); path = point2.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point2); Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001f); // mock profile and force oneway backward. profile = MockProfile.CarMock(x => new Speed() { Value = 50f / 3.6f, Direction = 2 }); path = point1.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point2); Assert.IsNull(path); path = point2.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point1); Assert.IsNotNull(path); Assert.AreEqual(800 * profile.Factor(new AttributeCollection( new Attribute("highway", "residential"))).Value, path.Weight, 0.001f); path = point1.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point1); Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001f); path = point2.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point2); Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001f); // test the full edge. profile = MockProfile.CarMock(); point1 = new RouterPoint(0f, 0f, 0, 0); point2 = new RouterPoint(0.1f, 0.1f, 0, ushort.MaxValue); path = point1.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point2); Assert.IsNotNull(path); Assert.AreEqual(1000 * profile.Factor(null).Value, path.Weight, 0.001f); Assert.AreEqual(1, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001f); Assert.AreEqual(0, path.Vertex); path = path.From; Assert.IsNull(path); path = point2.EdgePathTo(routerDb, profile.DefaultWeightHandler(new Router(routerDb)), point1); Assert.IsNotNull(path); Assert.AreEqual(1000 * profile.Factor(null).Value, path.Weight, 0.001f); Assert.AreEqual(0, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001f); Assert.AreEqual(1, path.Vertex); path = path.From; Assert.IsNull(path); }
public void TestTwoEdgesRightHighest() { // build graph. var routerDb = new RouterDb(); routerDb.AddSupportedProfile(MockProfile.CarMock()); 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(0, 1, 100 * MockProfile.CarMock().Factor(null).Value, null); graph.AddEdge(1, 2, 100 * MockProfile.CarMock().Factor(null).Value, null); routerDb.AddContracted(MockProfile.CarMock(), new ContractedDb(graph)); // create algorithm and run. var algorithm = new ManyToManyBidirectionalDykstra(new Router(routerDb), MockProfile.CarMock(), 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 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][0], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][1], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[0][2], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][0], 0.1); Assert.AreEqual(000 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][1], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[1][2], 0.1); Assert.AreEqual(200 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][0], 0.1); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][1], 0.1); Assert.AreEqual(000 * MockProfile.CarMock().Factor(null).Value, algorithm.Weights[2][2], 0.1); }
public void TestThreeEdges() { // build graph. var routerDb = new RouterDb(); routerDb.AddSupportedProfile(MockProfile.CarMock()); 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)->(0, 1, 2). var algorithm = new ManyToMany(new Router(routerDb), MockProfile.CarMock(), (x) => new uint[0][], 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) }, float.MaxValue); 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 * MockProfile.CarMock().Factor(null).Value, weights[0][1], 0.001); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[0][2], 0.001); Assert.AreEqual(3, weights[1].Length); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[1][0], 0.001); Assert.AreEqual(0, weights[1][1], 0.001); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[1][2], 0.001); Assert.AreEqual(3, weights[2].Length); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[2][0], 0.001); Assert.AreEqual(100 * MockProfile.CarMock().Factor(null).Value, weights[2][1], 0.001); Assert.AreEqual(0, weights[2][2], 0.001); var path = algorithm.GetPath(0, 0); Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001); Assert.AreEqual(0, path.Vertex); path = path.From; Assert.IsNull(path); path = algorithm.GetPath(0, 1); Assert.IsNotNull(path); Assert.AreEqual(100 * MockProfile.CarMock().Factor(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(0, 2); Assert.IsNotNull(path); Assert.AreEqual(100 * MockProfile.CarMock().Factor(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); path = algorithm.GetPath(1, 0); Assert.IsNotNull(path); Assert.AreEqual(100 * MockProfile.CarMock().Factor(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, 1); 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, 2); Assert.IsNotNull(path); Assert.AreEqual(100 * MockProfile.CarMock().Factor(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); path = algorithm.GetPath(2, 0); Assert.IsNotNull(path); Assert.AreEqual(100 * MockProfile.CarMock().Factor(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(2, 1); Assert.IsNotNull(path); Assert.AreEqual(100 * MockProfile.CarMock().Factor(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); path = algorithm.GetPath(2, 2); Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.001); Assert.AreEqual(2, path.Vertex); path = path.From; Assert.IsNull(path); }