public void RoutingRegressionTest9ResolvingReverse() { // build a graph to encode from. var tags = new TagsIndex(); var graphDataSource = new RouterDataSource <Edge>(new Graph <Edge>(), tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edge = new Edge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; graphDataSource.AddEdge(vertex1, vertex2, edge, null); graphDataSource.AddEdge(vertex3, vertex1, edge, null); // {RectF:[(3,71326552867889,51,048498214689),(3,73326552867889,51,068498214689)]} var edges = graphDataSource.GetEdges(new GeoCoordinateBox( new GeoCoordinate(51.068498214689, 3.73326552867889), new GeoCoordinate(51.048498214689, 3.71326552867889))); while (edges.MoveNext()) { if (edges.Vertex1 == 1 && edges.Vertex2 == 2) { Assert.IsTrue(edges.EdgeData.Forward); } else if (edges.Vertex1 == 2 && edges.Vertex2 == 1) { Assert.IsFalse(edges.EdgeData.Forward); } if (edges.Vertex1 == 1 && edges.Vertex2 == 3) { Assert.IsFalse(edges.EdgeData.Forward); } else if (edges.Vertex1 == 3 && edges.Vertex2 == 1) { Assert.IsTrue(edges.EdgeData.Forward); } } }
/// <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); TagsCollectionBase pointTags = new TagsCollection(); pointTags["name"] = pointName; TagsCollectionBase tags = new TagsCollection(); tags["highway"] = highway; //tags["name"] = name; var tagsIndex = new TagsIndex(); // do the data processing. var data = new RouterDataSource <Edge>(new Graph <Edge>(), tagsIndex); uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude); uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude); data.AddEdge(vertexNoname1, vertexNoname2, new Edge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); tags = new TagsCollection(); 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.AddEdge(vertexName1, vertexName2, new Edge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); IRoutingInterpreter interpreter = new OsmRoutingInterpreter(); // creates the data. IRoutingAlgorithm <Edge> router = new Dykstra(); 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; var result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags, null); 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 RoutingRegressionTest11ResolvingReverse() { // build a graph to encode from. var tags = new TagsIndex(); var graphDataSource = new RouterDataSource<Edge>(new Graph<Edge>(), tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edgeData = new Edge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; var shape1 = new CoordinateArrayCollection<OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 1, Longitude = 1 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 2, Longitude = 2 } }); var shape2 = new CoordinateArrayCollection<OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 3, Longitude = 3 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 4, Longitude = 4 } }); graphDataSource.AddEdge(vertex1, vertex2, edgeData, shape1); graphDataSource.AddEdge(vertex3, vertex1, edgeData, shape2); var edges = new List<Edge<Edge>>(graphDataSource.GetEdges(1)); Assert.AreEqual(2, edges.Count); foreach(var edge in edges) { if (edge.Neighbour == 2) { Assert.AreEqual(true, edge.EdgeData.Forward); } else if(edge.Neighbour == 3) { Assert.AreEqual(false, edge.EdgeData.Forward); } } edges = new List<Edge<Edge>>(graphDataSource.GetEdges(2)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(false, edges[0].EdgeData.Forward); edges = new List<Edge<Edge>>(graphDataSource.GetEdges(3)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(true, edges[0].EdgeData.Forward); }
public void RoutingRegressionTest10ResolvingReverse() { // build a graph to encode from. var tags = new TagsIndex(); var graphDataSource = new RouterDataSource<Edge>(new Graph<Edge>(), tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edge = new Edge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; var shape1 = new CoordinateArrayCollection<OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 1, Longitude = 1 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 2, Longitude = 2 } }); var shape2 = new CoordinateArrayCollection<OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 3, Longitude = 3 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 4, Longitude = 4 } }); graphDataSource.AddEdge(vertex1, vertex2, edge, shape1); graphDataSource.AddEdge(vertex3, vertex1, edge, shape2); // {RectF:[(3,71326552867889,51,048498214689),(3,73326552867889,51,068498214689)]} var edges = graphDataSource.GetEdges(new GeoCoordinateBox( new GeoCoordinate(51.068498214689, 3.73326552867889), new GeoCoordinate(51.048498214689, 3.71326552867889))); while (edges.MoveNext()) { if (edges.Vertex1 == 1 && edges.Vertex2 == 2) { Assert.IsTrue(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(1, shapes[0].Latitude); Assert.AreEqual(1, shapes[0].Longitude); Assert.AreEqual(2, shapes[1].Latitude); Assert.AreEqual(2, shapes[1].Longitude); } else if (edges.Vertex1 == 2 && edges.Vertex2 == 1) { Assert.IsFalse(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(2, shapes[0].Latitude); Assert.AreEqual(2, shapes[0].Longitude); Assert.AreEqual(1, shapes[1].Latitude); Assert.AreEqual(1, shapes[1].Longitude); } if (edges.Vertex1 == 1 && edges.Vertex2 == 3) { Assert.IsFalse(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(4, shapes[0].Latitude); Assert.AreEqual(4, shapes[0].Longitude); Assert.AreEqual(3, shapes[1].Latitude); Assert.AreEqual(3, shapes[1].Longitude); } else if (edges.Vertex1 == 3 && edges.Vertex2 == 1) { Assert.IsTrue(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(3, shapes[0].Latitude); Assert.AreEqual(3, shapes[0].Longitude); Assert.AreEqual(4, shapes[1].Latitude); Assert.AreEqual(4, shapes[1].Longitude); } } }
public void RoutingRegressionTest9ResolvingReverse() { // build a graph to encode from. var tags = new TagsIndex(); var graphDataSource = new RouterDataSource<Edge>(new Graph<Edge>(), tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edge = new Edge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; graphDataSource.AddEdge(vertex1, vertex2, edge, null); graphDataSource.AddEdge(vertex3, vertex1, edge, null); // {RectF:[(3,71326552867889,51,048498214689),(3,73326552867889,51,068498214689)]} var edges = graphDataSource.GetEdges(new GeoCoordinateBox( new GeoCoordinate(51.068498214689, 3.73326552867889), new GeoCoordinate(51.048498214689, 3.71326552867889))); while(edges.MoveNext()) { if(edges.Vertex1 == 1 && edges.Vertex2 == 2) { Assert.IsTrue(edges.EdgeData.Forward); } else if(edges.Vertex1 == 2 && edges.Vertex2 == 1) { Assert.IsFalse(edges.EdgeData.Forward); } if (edges.Vertex1 == 1 && edges.Vertex2 == 3) { Assert.IsFalse(edges.EdgeData.Forward); } else if (edges.Vertex1 == 3 && edges.Vertex2 == 1) { Assert.IsTrue(edges.EdgeData.Forward); } } }
/// <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); TagsCollectionBase pointTags = new TagsCollection(); pointTags["name"] = pointName; TagsCollectionBase tags = new TagsCollection(); tags["highway"] = highway; //tags["name"] = name; var tagsIndex = new TagsIndex(); // do the data processing. var data = new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex); uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude); uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude); data.AddEdge(vertexNoname1, vertexNoname2, new Edge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); tags = new TagsCollection(); 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.AddEdge(vertexName1, vertexName2, new Edge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); IRoutingInterpreter interpreter = new OsmRoutingInterpreter(); // creates the data. IRoutingAlgorithm<Edge> router = new Dykstra(); 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; var result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags, null); 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 RoutingRegressionTest11ResolvingReverse() { // build a graph to encode from. var tags = new TagsIndex(); var graphDataSource = new RouterDataSource <Edge>(new Graph <Edge>(), tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edgeData = new Edge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; var shape1 = new CoordinateArrayCollection <OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 1, Longitude = 1 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 2, Longitude = 2 } }); var shape2 = new CoordinateArrayCollection <OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 3, Longitude = 3 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 4, Longitude = 4 } }); graphDataSource.AddEdge(vertex1, vertex2, edgeData, shape1); graphDataSource.AddEdge(vertex3, vertex1, edgeData, shape2); var edges = new List <Edge <Edge> >(graphDataSource.GetEdges(1)); Assert.AreEqual(2, edges.Count); foreach (var edge in edges) { if (edge.Neighbour == 2) { Assert.AreEqual(true, edge.EdgeData.Forward); } else if (edge.Neighbour == 3) { Assert.AreEqual(false, edge.EdgeData.Forward); } } edges = new List <Edge <Edge> >(graphDataSource.GetEdges(2)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(false, edges[0].EdgeData.Forward); edges = new List <Edge <Edge> >(graphDataSource.GetEdges(3)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(true, edges[0].EdgeData.Forward); }
public void RoutingRegressionTest10ResolvingReverse() { // build a graph to encode from. var tags = new TagsIndex(); var graphDataSource = new RouterDataSource <Edge>(new Graph <Edge>(), tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edge = new Edge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; var shape1 = new CoordinateArrayCollection <OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 1, Longitude = 1 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 2, Longitude = 2 } }); var shape2 = new CoordinateArrayCollection <OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 3, Longitude = 3 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 4, Longitude = 4 } }); graphDataSource.AddEdge(vertex1, vertex2, edge, shape1); graphDataSource.AddEdge(vertex3, vertex1, edge, shape2); // {RectF:[(3,71326552867889,51,048498214689),(3,73326552867889,51,068498214689)]} var edges = graphDataSource.GetEdges(new GeoCoordinateBox( new GeoCoordinate(51.068498214689, 3.73326552867889), new GeoCoordinate(51.048498214689, 3.71326552867889))); while (edges.MoveNext()) { if (edges.Vertex1 == 1 && edges.Vertex2 == 2) { Assert.IsTrue(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(1, shapes[0].Latitude); Assert.AreEqual(1, shapes[0].Longitude); Assert.AreEqual(2, shapes[1].Latitude); Assert.AreEqual(2, shapes[1].Longitude); } else if (edges.Vertex1 == 2 && edges.Vertex2 == 1) { Assert.IsFalse(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(2, shapes[0].Latitude); Assert.AreEqual(2, shapes[0].Longitude); Assert.AreEqual(1, shapes[1].Latitude); Assert.AreEqual(1, shapes[1].Longitude); } if (edges.Vertex1 == 1 && edges.Vertex2 == 3) { Assert.IsFalse(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(4, shapes[0].Latitude); Assert.AreEqual(4, shapes[0].Longitude); Assert.AreEqual(3, shapes[1].Latitude); Assert.AreEqual(3, shapes[1].Longitude); } else if (edges.Vertex1 == 3 && edges.Vertex2 == 1) { Assert.IsTrue(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(3, shapes[0].Latitude); Assert.AreEqual(3, shapes[0].Longitude); Assert.AreEqual(4, shapes[1].Latitude); Assert.AreEqual(4, shapes[1].Longitude); } } }