public void TestRandomBlockTagSerializaton() { SimpleTagsIndex tagsIndex = new SimpleTagsIndex(); SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); for (int i = 0; i < 100; i++) { int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1; for (int idx = 0; idx < tagCollectionSize; idx++) { int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10); tagsCollection.Add( string.Format("key_{0}", tagValue), string.Format("value_{0}", tagValue)); } uint tagsId = tagsIndex.Add(tagsCollection); } ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserializeBlock(tagsIndex, 10, 0); Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } }
/// <summary> /// Tests the edge matcher in combination with dykstra routing. /// </summary> /// <param name="name"></param> /// <param name="highway"></param> /// <param name="vehicle"></param> /// <param name="matcher"></param> /// <param name="pointName"></param> /// <param name="notFound"></param> private void TestResolveOnEdgeSingle(string name, string highway, Vehicle vehicle, IEdgeMatcher matcher, string pointName, bool notFound) { var fromName = new GeoCoordinate(51.0003, 4.0007); var toName = new GeoCoordinate(51.0003, 4.0008); var fromNoname = new GeoCoordinate(51.0, 4.0007); var toNoname = new GeoCoordinate(51.0, 4.0008); TagsCollection pointTags = new SimpleTagsCollection(); pointTags["name"] = pointName; TagsCollection tags = new SimpleTagsCollection(); tags["highway"] = highway; //tags["name"] = name; var tagsIndex = new SimpleTagsIndex(); // do the data processing. var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex); uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude); uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude); data.AddArc(vertexNoname1, vertexNoname2, new LiveEdge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); tags = new SimpleTagsCollection(); tags["highway"] = highway; tags["name"] = name; uint vertexName1 = data.AddVertex((float)fromName.Latitude, (float)fromName.Longitude); uint vertexName2 = data.AddVertex((float)toName.Latitude, (float)toName.Longitude); data.AddArc(vertexName1, vertexName2, new LiveEdge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); IRoutingInterpreter interpreter = new OsmRoutingInterpreter(); // creates the data. IBasicRouter<LiveEdge> router = new DykstraRoutingLive(); var nonameLocation = new GeoCoordinate( (fromNoname.Latitude + toNoname.Latitude) / 2.0, (fromNoname.Longitude + toNoname.Longitude) / 2.0); // var nameLocation = new GeoCoordinate( // (fromName.Latitude + toName.Latitude) / 2.0, // (fromName.Longitude + toName.Longitude) / 2.0); const float delta = 0.01f; SearchClosestResult result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags); if (result.Distance < double.MaxValue) { // there is a result. Assert.IsFalse(notFound, "A result was found but was supposed not to be found!"); if (name == pointName) { // the name location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertexName1 || result.Vertex1 == vertexName2); Assert.IsTrue(result.Vertex2 == vertexName1 || result.Vertex2 == vertexName2); } else { // the noname location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertexNoname1 || result.Vertex1 == vertexNoname2); Assert.IsTrue(result.Vertex2 == vertexNoname1 || result.Vertex2 == vertexNoname2); } return; } Assert.IsTrue(notFound, "A result was not found but was supposed to be found!"); }
public void TestSimpleTagSerializatonNonBeginPosition() { SimpleTagsIndex tagsIndex = new SimpleTagsIndex(); SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); tagsCollection.Add("key1", "value1"); uint tagsId = tagsIndex.Add(tagsCollection); ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, 1201); Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } }
public void TestRandomPartialTagSerializaton() { SimpleTagsIndex tagsIndex = new SimpleTagsIndex(); SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); for (int i = 0; i < 100; i++) { int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1; for (int idx = 0; idx < tagCollectionSize; idx++) { int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10); tagsCollection.Add( string.Format("key_{0}", tagValue), string.Format("value_{0}", tagValue)); } uint tagsId = tagsIndex.Add(tagsCollection); } uint from = 40; uint to = 50; ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } from = 0; to = 100; tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } from = 10; to = 1000; tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } }