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);
                }
            }
        }
Exemplo n.º 2
0
        public void TestTagIndexSerialization()
        {
            // set the seed manually.
            OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346);

            // build a tags index and keep what was added.
            var tagsIndex = new TagsIndex(new MemoryMappedStream(new MemoryStream()));
            var addedTags = new List <KeyValuePair <uint, TagsCollectionBase> >();

            for (int i = 0; i < 100; i++)
            {
                var tagsCollection    = new TagsCollection();
                var tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
                for (int idx = 0; idx < tagCollectionSize; idx++)
                {
                    var tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3);
                    tagsCollection.Add(
                        string.Format("key_{0}", tagValue),
                        string.Format("value_{0}", tagValue));
                }
                var addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
                for (int idx = 0; idx < addCount; idx++)
                {
                    var tagsId = tagsIndex.Add(tagsCollection);
                    addedTags.Add(new KeyValuePair <uint, TagsCollectionBase>(tagsId, tagsCollection));

                    var indexTags = tagsIndex.Get(tagsId);
                    Assert.AreEqual(tagsCollection.Count, indexTags.Count);
                    foreach (var tag in tagsCollection)
                    {
                        Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
                    }
                }
            }

            // serialize/deserialize.
            var deserializedTagsIndex = this.SerializeDeserialize(tagsIndex, false);

            // verify if what was added is still there.
            this.TestTagIndexContent(deserializedTagsIndex, addedTags);
        }
        public void TestTagIndexSerialization()
        {
            // set the seed manually.
            OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346);

            // build a tags index and keep what was added.
            var tagsIndex = new TagsIndex(new MemoryMappedStream(new MemoryStream()));
            var addedTags = new List<KeyValuePair<uint, TagsCollectionBase>>();
            for (int i = 0; i < 100; i++)
            {
                var tagsCollection = new TagsCollection();
                var tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
                for (int idx = 0; idx < tagCollectionSize; idx++)
                {
                    var tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3);
                    tagsCollection.Add(
                        string.Format("key_{0}", tagValue),
                        string.Format("value_{0}", tagValue));
                }
                var addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
                for (int idx = 0; idx < addCount; idx++)
                {
                    var tagsId = tagsIndex.Add(tagsCollection);
                    addedTags.Add(new KeyValuePair<uint, TagsCollectionBase>(tagsId, tagsCollection));

                    var indexTags = tagsIndex.Get(tagsId);
                    Assert.AreEqual(tagsCollection.Count, indexTags.Count);
                    foreach (var tag in tagsCollection)
                    {
                        Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
                    }
                }
            }

            // serialize/deserialize.
            var deserializedTagsIndex = this.SerializeDeserialize(tagsIndex, false);

            // verify if what was added is still there.
            this.TestTagIndexContent(deserializedTagsIndex, addedTags);
        }
Exemplo n.º 4
0
        /// <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!");
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
                }
            }
        }
Exemplo n.º 7
0
        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);
                }
            }
        }
Exemplo n.º 8
0
        public void TestSparseRemoval1Routing()
        {
            // use one edge definition everywhere.
            var tagsIndex = new TagsIndex();
            var tags = new TagsCollection(new Tag("highway","residential"));
            var edge = new Edge();
            edge.Forward = true;
            edge.Tags = tagsIndex.Add(tags);

            var graph = new Graph<Edge>();
            uint vertex1 = graph.AddVertex(51.267797f, 4.8013623f);
            uint vertex2 = graph.AddVertex(51.267702f, 4.8013396f);
            uint vertex3 = graph.AddVertex(51.267592f, 4.8013024f);

            graph.AddEdge(vertex1, vertex2, edge, null);
            graph.AddEdge(vertex2, vertex3, edge, null);
            graph.AddEdge(vertex3, vertex2, edge, null);

            // save vertex coordinates for later use.
            float latitude, longitude;
            graph.GetVertex(vertex1, out latitude, out longitude);
            var vertex1Coordinate = new GeoCoordinate(latitude, longitude);
            graph.GetVertex(vertex2, out latitude, out longitude);
            var vertex2Coordinate = new GeoCoordinate(latitude, longitude);
            graph.GetVertex(vertex3, out latitude, out longitude);
            var vertex3Coordinate = new GeoCoordinate(latitude, longitude);

            // execute pre-processor.
            var preProcessor = new GraphSimplificationPreprocessor(graph);
            preProcessor.Start();

            // create router.
            var source = new RouterDataSource<Edge>(
                graph, tagsIndex);
            var router = Router.CreateFrom(source, new OsmRoutingInterpreter());

            // test some basic routing requests.
            // 1 -> 3: 1 -> 2 -> 3.
            var resolved1 = router.Resolve(Vehicle.Car, vertex1Coordinate);
            var resolved3 = router.Resolve(Vehicle.Car, vertex3Coordinate);
            var route = router.Calculate(Vehicle.Car, resolved1, resolved3);
            
            // verify the simple route result.
            Assert.IsNotNull(route);
            Assert.AreEqual(3, route.Segments.Length);
            Assert.AreEqual(vertex1Coordinate.Latitude, route.Segments[0].Latitude);
            Assert.AreEqual(vertex1Coordinate.Longitude, route.Segments[0].Longitude);
            Assert.AreEqual(vertex2Coordinate.Latitude, route.Segments[1].Latitude);
            Assert.AreEqual(vertex2Coordinate.Longitude, route.Segments[1].Longitude);
            Assert.AreEqual(vertex3Coordinate.Latitude, route.Segments[2].Latitude);
            Assert.AreEqual(vertex3Coordinate.Longitude, route.Segments[2].Longitude);

            // 1 -> 2: 1 -> 2.
            router = Router.CreateFrom(source, new OsmRoutingInterpreter());
            resolved1 = router.Resolve(Vehicle.Car, vertex1Coordinate);
            var resolved2 = router.Resolve(Vehicle.Car, vertex2Coordinate);
            route = router.Calculate(Vehicle.Car, resolved1, resolved2);

            // verify the simple route result.
            Assert.IsNotNull(route);
            Assert.AreEqual(2, route.Segments.Length);
            Assert.AreEqual(vertex1Coordinate.Latitude, route.Segments[0].Latitude);
            Assert.AreEqual(vertex1Coordinate.Longitude, route.Segments[0].Longitude);
            Assert.AreEqual(vertex2Coordinate.Latitude, route.Segments[1].Latitude);
            Assert.AreEqual(vertex2Coordinate.Longitude, route.Segments[1].Longitude);
        }
Exemplo n.º 9
0
        public void TestSparseRemoval1Routing()
        {
            // use one edge definition everywhere.
            var tagsIndex = new TagsIndex();
            var tags      = new TagsCollection(new Tag("highway", "residential"));
            var edge      = new Edge();

            edge.Forward = true;
            edge.Tags    = tagsIndex.Add(tags);

            var  graph   = new Graph <Edge>();
            uint vertex1 = graph.AddVertex(51.267797f, 4.8013623f);
            uint vertex2 = graph.AddVertex(51.267702f, 4.8013396f);
            uint vertex3 = graph.AddVertex(51.267592f, 4.8013024f);

            graph.AddEdge(vertex1, vertex2, edge, null);
            graph.AddEdge(vertex2, vertex3, edge, null);
            graph.AddEdge(vertex3, vertex2, edge, null);

            // save vertex coordinates for later use.
            float latitude, longitude;

            graph.GetVertex(vertex1, out latitude, out longitude);
            var vertex1Coordinate = new GeoCoordinate(latitude, longitude);

            graph.GetVertex(vertex2, out latitude, out longitude);
            var vertex2Coordinate = new GeoCoordinate(latitude, longitude);

            graph.GetVertex(vertex3, out latitude, out longitude);
            var vertex3Coordinate = new GeoCoordinate(latitude, longitude);

            // execute pre-processor.
            var preProcessor = new GraphSimplificationPreprocessor(graph);

            preProcessor.Start();

            // create router.
            var source = new RouterDataSource <Edge>(
                graph, tagsIndex);
            var router = Router.CreateFrom(source, new OsmRoutingInterpreter());

            // test some basic routing requests.
            // 1 -> 3: 1 -> 2 -> 3.
            var resolved1 = router.Resolve(Vehicle.Car, vertex1Coordinate);
            var resolved3 = router.Resolve(Vehicle.Car, vertex3Coordinate);
            var route     = router.Calculate(Vehicle.Car, resolved1, resolved3);

            // verify the simple route result.
            Assert.IsNotNull(route);
            Assert.AreEqual(3, route.Segments.Length);
            Assert.AreEqual(vertex1Coordinate.Latitude, route.Segments[0].Latitude);
            Assert.AreEqual(vertex1Coordinate.Longitude, route.Segments[0].Longitude);
            Assert.AreEqual(vertex2Coordinate.Latitude, route.Segments[1].Latitude);
            Assert.AreEqual(vertex2Coordinate.Longitude, route.Segments[1].Longitude);
            Assert.AreEqual(vertex3Coordinate.Latitude, route.Segments[2].Latitude);
            Assert.AreEqual(vertex3Coordinate.Longitude, route.Segments[2].Longitude);

            // 1 -> 2: 1 -> 2.
            router    = Router.CreateFrom(source, new OsmRoutingInterpreter());
            resolved1 = router.Resolve(Vehicle.Car, vertex1Coordinate);
            var resolved2 = router.Resolve(Vehicle.Car, vertex2Coordinate);

            route = router.Calculate(Vehicle.Car, resolved1, resolved2);

            // verify the simple route result.
            Assert.IsNotNull(route);
            Assert.AreEqual(2, route.Segments.Length);
            Assert.AreEqual(vertex1Coordinate.Latitude, route.Segments[0].Latitude);
            Assert.AreEqual(vertex1Coordinate.Longitude, route.Segments[0].Longitude);
            Assert.AreEqual(vertex2Coordinate.Latitude, route.Segments[1].Latitude);
            Assert.AreEqual(vertex2Coordinate.Longitude, route.Segments[1].Longitude);
        }
Exemplo n.º 10
0
        /// <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);
                }
            }
        }