public void ReverseAfterStoppingTest() { var navigatorMock = new NavigatorMock(); var inputMock = new InputMock(); var obstacleDetectorMock = new ObstacleDetectorMock(); var vehicleMock = new VehicleMock(); navigatorMock.DirectionToReturn = new Vector(1, 0); var driver = new Skywalker.Driver.Driver(inputMock, vehicleMock, navigatorMock); driver.Start(); Thread.Sleep(100); Assert.IsTrue((int)vehicleMock.SpeedSetTo == 100); obstacleDetectorMock.FireObjectDetection(); Thread.Sleep(100); Assert.IsTrue((int)vehicleMock.SpeedSetTo == 0); navigatorMock.DirectionToReturn = new Vector(0, 0); Thread.Sleep(100); navigatorMock.DirectionToReturn = new Vector(0, -1); Thread.Sleep(100); Assert.IsTrue((int)vehicleMock.SpeedSetTo == 100); Assert.IsTrue(vehicleMock.RotationSetTo.Y > 1 - 0.001 && vehicleMock.RotationSetTo.Y < 1 + 0.001); }
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); }
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 = VehicleMock.Car().Fastest(); 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 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 = VehicleMock.Car().Fastest(); 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 TestAddStopLinksDb() { // build a simple network and connections db. var routerDb = new RouterDb(); routerDb.LoadTestNetwork( System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( "Itinero.Transit.Test.test_data.networks.network1.geojson")); var transitDb = new TransitDb(); var feed = DummyGTFSFeedBuilder.OneConnection( TimeOfDay.FromTotalSeconds(0), TimeOfDay.FromTotalSeconds(3600)); feed.Stops.Get(0).Latitude = 51.22965768754021f; feed.Stops.Get(0).Longitude = 4.460974931716918f; feed.Stops.Get(1).Latitude = 51.229617377118906f; feed.Stops.Get(1).Longitude = 4.463152885437011f; transitDb.LoadFrom(feed); var db = new MultimodalDb(routerDb, transitDb); // add stop links. var profile = VehicleMock.Car().Fastest(); db.AddStopLinksDb(profile); // check result. var stopLinksDb = db.GetStopLinksDb(profile); Assert.IsNotNull(stopLinksDb); var stop0 = db.TransitDb.SearchFirstStopsWithTags((t) => { return(t.Contains("id", "0")); }); var stop1 = db.TransitDb.SearchFirstStopsWithTags((t) => { return(t.Contains("id", "1")); }); var stopLinksDbEnumerator = stopLinksDb.GetEnumerator(); stopLinksDbEnumerator.MoveTo(stop0); Assert.AreEqual(1, stopLinksDbEnumerator.Count); Assert.IsTrue(stopLinksDbEnumerator.MoveNext()); Assert.AreEqual(0, stopLinksDbEnumerator.EdgeId); Assert.AreEqual(0, stopLinksDbEnumerator.Offset); stopLinksDbEnumerator.MoveTo(stop1); Assert.AreEqual(1, stopLinksDbEnumerator.Count); Assert.IsTrue(stopLinksDbEnumerator.MoveNext()); Assert.AreEqual(0, stopLinksDbEnumerator.EdgeId); Assert.AreEqual(ushort.MaxValue, stopLinksDbEnumerator.Offset); }
public void TestCustomResolverDelegate() { var routerDb = new RouterDb(); routerDb.AddSupportedVehicle(VehicleMock.Car()); 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[] { VehicleMock.Car().Fastest() }, 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 = VehicleMock.Car().Fastest(); 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 StopOnObjectDetectionTest() { var navigatorMock = new NavigatorMock(); var inputMock = new InputMock(); var obstacleDetectorMock = new ObstacleDetectorMock(); var vehicleMock = new VehicleMock(); navigatorMock.DirectionToReturn = new Vector(0, 0); var driver = new Skywalker.Driver.Driver(inputMock, vehicleMock, navigatorMock); driver.Start(); Thread.Sleep(100); Assert.IsTrue((int)vehicleMock.SpeedSetTo == 100); obstacleDetectorMock.FireObjectDetection(); Thread.Sleep(100); Assert.IsTrue((int)vehicleMock.SpeedSetTo == 0); }
public void TurningTest() { var navigatorMock = new NavigatorMock(); var inputMock = new InputMock(); var obstacleDetectorMock = new ObstacleDetectorMock(); var vehicleMock = new VehicleMock(); navigatorMock.DirectionToReturn = new Vector(1, 0); var driver = new Skywalker.Driver.Driver(inputMock, vehicleMock, navigatorMock); driver.Start(); Thread.Sleep(100); Assert.IsTrue(vehicleMock.RotationSetTo.X > 1 - 0.001 && vehicleMock.RotationSetTo.X < 1 + 0.001); navigatorMock.DirectionToReturn = new Vector(-1, 0);; Thread.Sleep(100); Assert.IsTrue(vehicleMock.RotationSetTo.X > -1 - 0.001 && vehicleMock.RotationSetTo.X < -1 + 0.001); }
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 TestNetwork2() { var routerDb = new RouterDb(); routerDb.LoadTestNetwork( Assembly.GetExecutingAssembly().GetManifestResourceStream( "Itinero.Transit.Test.test_data.networks.network2.geojson")); var profile = VehicleMock.Car(x => new FactorAndSpeed() { Direction = 0, Value = 10f, SpeedFactor = 10f }).Fastest(); var stopLocation = new Coordinate(51.229621576122774f, 4.464208334684372f); var stopLinksDb = new StopLinksDb(1, routerDb, profile); stopLinksDb.Add(0, new RouterPoint((float)stopLocation.Latitude, (float)stopLocation.Longitude, 1, ushort.MaxValue / 2)); var transitDb = new TransitDb(); var multimodalDb = new MultimodalDb(routerDb, transitDb); multimodalDb.AddStopLinksDb(stopLinksDb); multimodalDb.TransitDb.AddStop(51.229621576122774f, 4.464208334684372f, 0); var stopFound = false; var distanceToStop = Coordinate.DistanceEstimateInMeter(routerDb.Network.GetVertex(0), routerDb.Network.GetVertex(1)) + Coordinate.DistanceEstimateInMeter(routerDb.Network.GetVertex(1), stopLocation); var closestStopSearch = new ClosestStopsSearch(multimodalDb, profile, routerDb.Network.CreateRouterPointForVertex(0, 1), 3600, false); closestStopSearch.StopFound = (uint stopId, float seconds) => { Assert.AreEqual(0, stopId); Assert.AreEqual(distanceToStop * 10, seconds, 1); stopFound = true; return(false); }; closestStopSearch.Run(); Assert.IsTrue(stopFound); var path = closestStopSearch.GetPath(0); Assert.IsNotNull(path); Assert.AreEqual(distanceToStop * 10, path.Weight, 1); Assert.AreEqual(Itinero.Constants.NO_VERTEX, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(Coordinate.DistanceEstimateInMeter(routerDb.Network.GetVertex(0), routerDb.Network.GetVertex(1)) * 10, path.Weight, 1); Assert.AreEqual(1, path.Vertex); path = path.From; Assert.IsNotNull(path); Assert.AreEqual(0, path.Weight, 0.01); Assert.AreEqual(0, path.Vertex); path = path.From; Assert.IsNull(path); }
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); }
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); }
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); }
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 = VehicleMock.Car().Fastest(); 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 = VehicleMock.Car(x => new FactorAndSpeed() { Value = 1 / 50f / 3.6f, SpeedFactor = 1 / 50f / 3.6f, Direction = 1 }).Fastest(); 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 = VehicleMock.Car(x => new FactorAndSpeed() { Value = 1 / 50f / 3.6f, SpeedFactor = 1 / 50f / 3.6f, Direction = 2 }).Fastest(); 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 = VehicleMock.Car().Fastest(); 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 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); }
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); }
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 = VehicleMock.Car().Fastest(); 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 TestSourceEdgeHasStop() { var routerDb = new RouterDb(); routerDb.Network.AddVertex(0, 51.27018537520318f, 4.799609184265137f); routerDb.Network.AddVertex(1, 51.2682252886248f, 4.793150424957275f); routerDb.Network.AddEdge(0, 1, new Itinero.Data.Network.Edges.EdgeData() { Profile = 0, MetaId = 0, Distance = 500 }, null); routerDb.EdgeProfiles.Add(new AttributeCollection()); routerDb.EdgeMeta.Add(new AttributeCollection()); var profile = VehicleMock.Car(x => new FactorAndSpeed() { Direction = 0, Value = .1f, SpeedFactor = .1f }).Fastest(); var stopLinksDb = new StopLinksDb(1, routerDb, profile); stopLinksDb.Add(0, new RouterPoint(51.269138216062984f, 4.796175956726074f, 0, ushort.MaxValue / 2)); var transitDb = new TransitDb(); var multimodalDb = new MultimodalDb(routerDb, transitDb); multimodalDb.AddStopLinksDb(stopLinksDb); multimodalDb.TransitDb.AddStop(51.269138216062984f, 4.796175956726074f, 0); var stopFound = false; var closestStopSearch = new ClosestStopsSearch(multimodalDb, profile, new RouterPoint(51.269138216062984f, 4.796175956726074f, 0, ushort.MaxValue / 2), 1800, false); closestStopSearch.StopFound = (uint stopId, float seconds) => { if (!stopFound) { Assert.AreEqual(0, stopId); Assert.AreEqual(0, seconds); stopFound = true; } return(false); }; closestStopSearch.Run(); Assert.IsTrue(closestStopSearch.HasRun); Assert.IsTrue(closestStopSearch.HasSucceeded); Assert.IsTrue(stopFound); var path = closestStopSearch.GetPath(0); Assert.IsNotNull(path); Assert.AreEqual(Itinero.Constants.NO_VERTEX, path.Vertex); Assert.IsNull(path.From); Assert.AreEqual(0, path.Weight); var point = closestStopSearch.GetTargetPoint(0); Assert.IsNotNull(point); Assert.AreEqual(0, point.EdgeId); Assert.AreEqual(ushort.MaxValue / 2, point.Offset); stopFound = false; closestStopSearch = new ClosestStopsSearch(multimodalDb, profile, new RouterPoint(51.27018537520318f, 4.799609184265137f, 0, 0), 1800, false); closestStopSearch.StopFound = (uint stopId, float seconds) => { Assert.AreEqual(0, stopId); Assert.AreEqual(profile.Factor(null).Value * 250, seconds, .1f); stopFound = true; return(false); }; closestStopSearch.Run(); Assert.IsTrue(stopFound); path = closestStopSearch.GetPath(0); Assert.IsNotNull(path); Assert.AreEqual(Itinero.Constants.NO_VERTEX, path.Vertex); Assert.IsNotNull(path.From); Assert.AreEqual(0, path.From.Vertex); Assert.AreEqual(profile.Factor(null).Value * 250, path.Weight, .1f); point = closestStopSearch.GetTargetPoint(0); Assert.IsNotNull(point); Assert.AreEqual(0, point.EdgeId); Assert.AreEqual(ushort.MaxValue / 2, point.Offset); }