Beispiel #1
0
        public void TestTwoNeighboursOneWay()
        {
            var tags    = new TagsTableCollectionIndex();
            var graph   = new DynamicGraphRouterDataSource <LiveEdge>(tags);
            var vertex1 = graph.AddVertex(0, 0);
            var vertex2 = graph.AddVertex(1, 1);
            var vertex3 = graph.AddVertex(2, 2);
            var edge    = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("FOW", "2"),
                                        Tag.Create("FRC", "3"),
                                        Tag.Create("ONEWAY", "FT")))
            };

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

            var encoder = new OpenLR.Referenced.MultiNet.ReferencedMultiNetEncoder(new BasicRouterDataSource <LiveEdge>(graph),
                                                                                   new EncoderMock());

            Assert.IsFalse(encoder.IsVertexValid(vertex2));
        }
Beispiel #2
0
        public void TestIsVertexValidRoundaboutExit()
        {
            var tags    = new TagsTableCollectionIndex();
            var graph   = new DynamicGraphRouterDataSource <LiveEdge>(tags);
            var vertex1 = graph.AddVertex(0, 0);
            var vertex2 = graph.AddVertex(1, 1);
            var vertex3 = graph.AddVertex(2, 2);
            var vertex4 = graph.AddVertex(3, 3);
            var edge    = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("highway", "tertiary")))
            };
            var onwayEdge = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("highway", "tertiary"),
                                        Tag.Create("oneway", "yes")))
            };

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

            var encoder = new OpenLR.Referenced.Osm.ReferencedOsmEncoder(new BasicRouterDataSource <LiveEdge>(graph),
                                                                         new EncoderMock());

            Assert.IsTrue(encoder.IsVertexValid(vertex3));
        }
        public void RoutingRegressionTest9ResolvingReverse()
        {
            // build a graph to encode from.
            var tags            = new TagsTableCollectionIndex();
            var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(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 LiveEdge() // 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>
        /// Deserializes all edges.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="size"></param>
        /// <param name="graph"></param>
        protected override void DeserializeEdges(LimitedStream stream, long size, DynamicGraphRouterDataSource <LiveEdge> graph)
        {
            var typeModel = RuntimeTypeModel.Create();

            typeModel.Add(typeof(SerializableEdge), true);
            typeModel.Add(typeof(GeoCoordinateSimple), true);

            long position = stream.Position;

            while (stream.Position < position + size)
            { // keep looping until the appropriate number of bytes have been read.
                var serializableEdges = typeModel.DeserializeWithSize(stream, null, typeof(SerializableEdge[])) as SerializableEdge[];
                for (int idx = 0; idx < serializableEdges.Length; idx++)
                {
                    ICoordinateCollection coordinateCollection = null;
                    if (serializableEdges[idx].Coordinates != null)
                    {
                        coordinateCollection = new CoordinateArrayCollection <GeoCoordinateSimple>(serializableEdges[idx].Coordinates);
                    }
                    graph.AddEdge(serializableEdges[idx].FromId, serializableEdges[idx].ToId,
                                  new LiveEdge()
                    {
                        Distance = serializableEdges[idx].Distance,
                        Value    = serializableEdges[idx].Value
                    }, coordinateCollection);
                }
            }
        }
Beispiel #5
0
        public void TestOneHop()
        {
            // build test data.
            var tagsIndex = new TagsTableCollectionIndex();
            var tags      = new TagsCollection(new Tag()
            {
                Key = "highway", Value = "residential"
            });
            var tagsId  = tagsIndex.Add(tags);
            var graph   = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex);
            var vertex1 = graph.AddVertex(50.909909938361324f, 4.452434778213501f);
            var vertex2 = graph.AddVertex(50.916698097895550f, 4.459059834480286f);

            graph.AddEdge(vertex1, vertex2,
                          new LiveEdge()
            {
                Distance = 890.65f,
                Forward  = true,
                Tags     = tagsId
            });

            // calculate route.
            var router = new BasicRouter();
            var route  = router.Calculate(new BasicRouterDataSource <LiveEdge>(graph),
                                          OsmSharp.Routing.Vehicle.Car, vertex1, vertex2, true);

            // verify result.
            Assert.IsNotNull(route);
            Assert.AreEqual(vertex2, route.Vertex);
            Assert.AreEqual(OsmSharp.Routing.Vehicle.Car.Weight(tags, 890.65f), route.Weight);
            Assert.AreEqual(vertex1, route.From.Vertex);
            Assert.AreEqual(0, route.From.Weight);
        }
Beispiel #6
0
        public void TestCarriageWaySplit()
        {
            var tags    = new TagsTableCollectionIndex();
            var graph   = new DynamicGraphRouterDataSource <LiveEdge>(tags);
            var vertex1 = graph.AddVertex(51.22218f, 5.87950f);
            var vertex2 = graph.AddVertex(51.22183f, 5.88044f);
            var vertex3 = graph.AddVertex(51.22149f, 5.88149f);
            var vertex4 = graph.AddVertex(51.22144f, 5.88147f);
            var edge1   = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("ONEWAY", string.Empty),
                                        Tag.Create("FRC", "2"),
                                        Tag.Create("FOW", "3")))
            };
            var edge2 = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("ONEWAY", "TF"),
                                        Tag.Create("FRC", "2"),
                                        Tag.Create("FOW", "2")))
            };
            var edge3 = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("ONEWAY", "FT"),
                                        Tag.Create("FRC", "2"),
                                        Tag.Create("FOW", "2")))
            };

            graph.AddEdge(vertex1, vertex2, edge1, null);
            graph.AddEdge(vertex2, vertex3, edge2, null);
            graph.AddEdge(vertex2, vertex4, edge3, null);

            var encoder = new OpenLR.Referenced.MultiNet.ReferencedMultiNetEncoder(new BasicRouterDataSource <LiveEdge>(graph),
                                                                                   new EncoderMock());

            Assert.IsFalse(encoder.IsVertexValid(vertex2));
        }
Beispiel #7
0
        public void TestRoundaboutExit()
        {
            var tags    = new TagsTableCollectionIndex();
            var graph   = new DynamicGraphRouterDataSource <LiveEdge>(tags);
            var vertex1 = graph.AddVertex(51.22069f, 5.88442f);
            var vertex2 = graph.AddVertex(51.22056f, 5.88426f);
            var vertex3 = graph.AddVertex(51.22046f, 5.88434f);
            var vertex4 = graph.AddVertex(51.22059f, 5.88414f);
            var edge1   = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("ONEWAY", string.Empty),
                                        Tag.Create("FRC", "2"),
                                        Tag.Create("FOW", "3")))
            };
            var edge2 = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("ONEWAY", "TF"),
                                        Tag.Create("FRC", "2"),
                                        Tag.Create("FOW", "4")))
            };
            var edge3 = new LiveEdge()
            {
                Distance = 100,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("ONEWAY", "FT"),
                                        Tag.Create("FRC", "2"),
                                        Tag.Create("FOW", "4")))
            };

            graph.AddEdge(vertex1, vertex2, edge1, null);
            graph.AddEdge(vertex2, vertex3, edge2, null);
            graph.AddEdge(vertex2, vertex4, edge3, null);

            var encoder = new OpenLR.Referenced.MultiNet.ReferencedMultiNetEncoder(new BasicRouterDataSource <LiveEdge>(graph),
                                                                                   new EncoderMock());

            Assert.IsTrue(encoder.IsVertexValid(vertex2));
        }
Beispiel #8
0
        public void TestOneHopShape()
        {
            // build test data.
            var tagsIndex = new TagsTableCollectionIndex();
            var tags      = new TagsCollection(new Tag()
            {
                Key = "highway", Value = "residential"
            });
            var tagsId  = tagsIndex.Add(tags);
            var graph   = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex);
            var vertex1 = graph.AddVertex(50.909909938361324f, 4.452434778213501f);
            var vertex2 = graph.AddVertex(50.916698097895550f, 4.459059834480286f);

            graph.AddEdge(vertex1, vertex2,
                          new LiveEdge()
            {
                Distance = 890.65f,
                Forward  = true,
                Tags     = tagsId
            },
                          new CoordinateArrayCollection <GeoCoordinate>(
                              new GeoCoordinate [] {
                new GeoCoordinate(50.910408852752770, 4.4531670212745670),
                new GeoCoordinate(50.911362694534270, 4.4543391466140750),
                new GeoCoordinate(50.912018872212215, 4.4550552964210500),
                new GeoCoordinate(50.913280466188610, 4.4562461972236630),
                new GeoCoordinate(50.914614742177996, 4.4574183225631705),
                new GeoCoordinate(50.915686870323930, 4.4582659006118770),
                new GeoCoordinate(50.916354824109910, 4.4587942957878110)
            }));

            // calculate route.
            var router = new BasicRouter();
            var route  = router.Calculate(new BasicRouterDataSource <LiveEdge>(graph),
                                          OsmSharp.Routing.Vehicle.Car, vertex1, vertex2, true);

            // verify result.
            Assert.IsNotNull(route);
            Assert.AreEqual(vertex2, route.Vertex);
            Assert.AreEqual(OsmSharp.Routing.Vehicle.Car.Weight(tags, 890.65f), route.Weight);
            Assert.AreEqual(vertex1, route.From.Vertex);
            Assert.AreEqual(0, route.From.Weight);
        }
Beispiel #9
0
        /// <summary>
        /// Deserializes all edges.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="size"></param>
        /// <param name="graph"></param>
        protected override void DeserializeEdges(LimitedStream stream, long size, DynamicGraphRouterDataSource <CHEdgeData> graph)
        {
            var typeModel = RuntimeTypeModel.Create();

            typeModel.Add(typeof(SerializableEdge), true);

            long position = stream.Position;

            while (stream.Position < position + size)
            { // keep looping until the appropriate number of bytes have been read.
                var serializableEdges = typeModel.DeserializeWithSize(stream, null, typeof(SerializableEdge[])) as SerializableEdge[];
                for (int idx = 0; idx < serializableEdges.Length; idx++)
                {
                    graph.AddEdge(serializableEdges[idx].FromId, serializableEdges[idx].ToId,
                                  new CHEdgeData()
                    {
                        ContractedVertexId = serializableEdges[idx].ContractedVertexId,
                        Direction          = serializableEdges[idx].Direction,
                        Tags   = serializableEdges[idx].Tags,
                        Weight = serializableEdges[idx].Weight
                    }, null);
                }
            }
        }
        public void RoutingRegressionTest10ResolvingReverse()
        {
            // build a graph to encode from.
            var tags = new TagsTableCollectionIndex();
            var graphDataSource = new DynamicGraphRouterDataSource<LiveEdge>(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 LiveEdge() // 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 TagsTableCollectionIndex();
            var graphDataSource = new DynamicGraphRouterDataSource<LiveEdge>(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 LiveEdge() // 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);
                }
            }
        }
        public void RoutingRegressionTest11ResolvingReverse()
        {
            // build a graph to encode from.
            var tags = new TagsTableCollectionIndex();
            var graphDataSource = new DynamicGraphRouterDataSource<LiveEdge>(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 LiveEdge() // 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<LiveEdge>>(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<LiveEdge>>(graphDataSource.GetEdges(2));
            Assert.AreEqual(1, edges.Count);
            Assert.AreEqual(false, edges[0].EdgeData.Forward);

            edges = new List<Edge<LiveEdge>>(graphDataSource.GetEdges(3));
            Assert.AreEqual(1, edges.Count);
            Assert.AreEqual(true, edges[0].EdgeData.Forward);
        }
Beispiel #13
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 TagsTableCollectionIndex();

            // 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.AddEdge(vertexNoname1, vertexNoname2, new LiveEdge()
            {
                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 LiveEdge()
            {
                Forward = true,
                Tags = tagsIndex.Add(tags)
            }, null);

            IRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            // creates the data.
            IRoutingAlgorithm<LiveEdge> 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!");
        }
Beispiel #14
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 TagsTableCollectionIndex();

            // 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.AddEdge(vertexNoname1, vertexNoname2, new LiveEdge()
            {
                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 LiveEdge()
            {
                Forward = true,
                Tags    = tagsIndex.Add(tags)
            }, null);

            IRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            // creates the data.
            IRoutingAlgorithm <LiveEdge> 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!");
        }
Beispiel #15
0
        public void DecodeReferencedPointAlongLineLocation()
        {
            double delta = 0.0001;

            // build the location to decode.
            var location = new PointAlongLineLocation();

            location.First            = new LocationReferencePoint();
            location.First.Coordinate = new Coordinate()
            {
                Latitude = 49.60597, Longitude = 6.12829
            };
            location.First.DistanceToNext     = 92;
            location.First.FuntionalRoadClass = FunctionalRoadClass.Frc2;
            location.First.FormOfWay          = FormOfWay.MultipleCarriageWay;
            location.First.LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc2;
            location.First.Bearing   = 203;
            location.Last            = new LocationReferencePoint();
            location.Last.Coordinate = new Coordinate()
            {
                Latitude = 49.60521, Longitude = 6.12779
            };
            location.Last.DistanceToNext      = 10;
            location.Last.FuntionalRoadClass  = FunctionalRoadClass.Frc2;
            location.Last.FormOfWay           = FormOfWay.MultipleCarriageWay;
            location.Last.Bearing             = 23;
            location.PositiveOffsetPercentage = (float)((28.0 / 92.0) * 100.0);
            location.Orientation = Orientation.FirstToSecond;
            location.SideOfRoad  = SideOfRoad.Left;

            // build a graph to decode onto.
            var tags            = new TagsTableCollectionIndex();
            var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags);
            var vertex1         = graphDataSource.AddVertex(49.60597f, 6.12829f);
            var vertex2         = graphDataSource.AddVertex(49.60521f, 6.12779f);

            graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Distance = 10,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            }, null);
            graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge()
            {
                Distance = 10,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            }, null);

            // decode the location
            var graph              = new BasicRouterDataSource <LiveEdge>(graphDataSource);
            var decoder            = new PointAlongLineDecoder();
            var router             = new BasicRouter();
            var mainDecoder        = new ReferencedOsmDecoder(graph, new BinaryDecoder());
            var referencedDecoder  = new ReferencedPointAlongLineDecoder(mainDecoder, decoder);
            var referencedLocation = referencedDecoder.Decode(location);

            // confirm result.
            Assert.IsNotNull(referencedLocation);
            Assert.IsNotNull(referencedLocation.Route);
            Assert.IsNotNull(referencedLocation.Route.Edges);
            Assert.AreEqual(vertex1, referencedLocation.Route.Vertices[0]);
            Assert.AreEqual(vertex2, referencedLocation.Route.Vertices[1]);
            var longitudeReference = (location.Last.Coordinate.Longitude - location.First.Coordinate.Longitude) * (location.PositiveOffsetPercentage.Value / 100.0) + location.First.Coordinate.Longitude;
            var latitudeReference  = (location.Last.Coordinate.Latitude - location.First.Coordinate.Latitude) * (location.PositiveOffsetPercentage.Value / 100.0) + location.First.Coordinate.Latitude;

            Assert.AreEqual(longitudeReference, referencedLocation.Longitude, delta);
            Assert.AreEqual(latitudeReference, referencedLocation.Latitude, delta);
            Assert.AreEqual(Orientation.FirstToSecond, referencedLocation.Orientation);
        }
        public void EncodedReferencedPointAlongLineLocation()
        {
            // build a graph to encode from.
            var  tags            = new TagsTableCollectionIndex();
            var  graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags);
            uint vertex1         = graphDataSource.AddVertex(49.60597f, 6.12829f);
            uint vertex2         = graphDataSource.AddVertex(49.60521f, 6.12779f);

            graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Distance = 10,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("BAANSUBSRT", "VBD"),
                                        Tag.Create("WEGBEHSRT", "R"),
                                        Tag.Create("WEGNUMMER", string.Empty),
                                        Tag.Create("RIJRICHTNG", "N")))
            }, null);
            graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge()
            {
                Distance = 10,
                Forward  = false,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("BAANSUBSRT", "VBD"),
                                        Tag.Create("WEGBEHSRT", "R"),
                                        Tag.Create("WEGNUMMER", string.Empty),
                                        Tag.Create("RIJRICHTNG", "N"),
                                        Tag.Create("HECTOLTTR", string.Empty)))
            }, null);

            // create a referenced location and encode it.
            var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource);
            var referencedPointAlongLineLocation = new ReferencedPointAlongLine();

            referencedPointAlongLineLocation.Route          = new ReferencedLine(graph);
            referencedPointAlongLineLocation.Route.Edges    = new LiveEdge[1];
            referencedPointAlongLineLocation.Route.Edges[0] = new LiveEdge()
            {
                Distance = 10,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(
                                        Tag.Create("BAANSUBSRT", "VBD"),
                                        Tag.Create("WEGBEHSRT", "R"),
                                        Tag.Create("WEGNUMMER", string.Empty),
                                        Tag.Create("RIJRICHTNG", "N"),
                                        Tag.Create("HECTOLTTR", string.Empty)))
            };
            referencedPointAlongLineLocation.Route.EdgeShapes    = new GeoCoordinateSimple[1][];
            referencedPointAlongLineLocation.Route.EdgeShapes[0] = new GeoCoordinateSimple[0];
            referencedPointAlongLineLocation.Route.Vertices      = new long[2];
            referencedPointAlongLineLocation.Route.Vertices[0]   = vertex1;
            referencedPointAlongLineLocation.Route.Vertices[1]   = vertex2;
            referencedPointAlongLineLocation.Latitude            = (49.60597f + 49.60521f) / 2f;
            referencedPointAlongLineLocation.Longitude           = (6.12829f + 6.12779f) / 2f;

            // encode location.
            var encoder           = new PointAlongLineEncoder();
            var mainEncoder       = new ReferencedNWBEncoder(graph, null);
            var referencedEncoder = new ReferencedPointAlongLineEncoder(mainEncoder, encoder);
            var location          = referencedEncoder.EncodeReferenced(referencedPointAlongLineLocation);

            // test result.
            Assert.IsNotNull(location);
            Assert.AreEqual(SideOfRoad.OnOrAbove, location.SideOfRoad);
            Assert.AreEqual(Orientation.NoOrientation, location.Orientation);
            Assert.AreEqual(50, location.PositiveOffsetPercentage.Value, 0.5f);

            Assert.AreEqual(49.60597f, location.First.Coordinate.Latitude);
            Assert.AreEqual(6.12829f, location.First.Coordinate.Longitude);
            Assert.AreEqual(91, location.First.DistanceToNext);
            Assert.AreEqual(FormOfWay.SlipRoad, location.First.FormOfWay);
            Assert.AreEqual(FunctionalRoadClass.Frc0, location.First.FuntionalRoadClass);
            Assert.AreEqual(FunctionalRoadClass.Frc0, location.First.LowestFunctionalRoadClassToNext);

            Assert.AreEqual(49.60521f, location.Last.Coordinate.Latitude);
            Assert.AreEqual(6.12779f, location.Last.Coordinate.Longitude);

            // TODO: encode location with a point on or at the first and last points.
        }
        public void EncodeReferencedPointAlongLineLocation()
        {
            // build a graph to encode from.
            var  tags            = new TagsTableCollectionIndex();
            var  graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags);
            uint vertex1         = graphDataSource.AddVertex(49.60597f, 6.12829f);
            uint vertex2         = graphDataSource.AddVertex(49.60521f, 6.12779f);

            graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Distance = 10,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            }, null);
            graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge()
            {
                Distance = 10,
                Forward  = false,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            }, null);

            // create a referenced location and encode it.
            var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource);
            var referencedPointAlongLineLocation = new ReferencedPointAlongLine();

            referencedPointAlongLineLocation.Route          = new ReferencedLine(graph);
            referencedPointAlongLineLocation.Route.Edges    = new LiveEdge[1];
            referencedPointAlongLineLocation.Route.Edges[0] = new LiveEdge()
            {
                Distance = 10,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            };
            referencedPointAlongLineLocation.Route.EdgeShapes    = new GeoCoordinateSimple[1][];
            referencedPointAlongLineLocation.Route.EdgeShapes[0] = new GeoCoordinateSimple[0];
            referencedPointAlongLineLocation.Route.Vertices      = new long[2];
            referencedPointAlongLineLocation.Route.Vertices[0]   = vertex1;
            referencedPointAlongLineLocation.Route.Vertices[1]   = vertex2;
            referencedPointAlongLineLocation.Latitude            = (49.60597f + 49.60521f) / 2f;
            referencedPointAlongLineLocation.Longitude           = (6.12829f + 6.12779f) / 2f;

            // encode location.
            var encoder           = new PointAlongLineEncoder();
            var router            = new Dykstra();
            var mainEncoder       = new ReferencedOsmEncoder(graph, null);
            var referencedEncoder = new ReferencedPointAlongLineEncoder(mainEncoder, encoder);
            var location          = referencedEncoder.EncodeReferenced(referencedPointAlongLineLocation);

            // test result.
            Assert.IsNotNull(location);
            Assert.AreEqual(SideOfRoad.OnOrAbove, location.SideOfRoad);
            Assert.AreEqual(Orientation.NoOrientation, location.Orientation);
            Assert.AreEqual(50, location.PositiveOffsetPercentage.Value, 0.5f);

            Assert.AreEqual(49.60597f, location.First.Coordinate.Latitude);
            Assert.AreEqual(6.12829f, location.First.Coordinate.Longitude);
            Assert.AreEqual(91, location.First.DistanceToNext);
            Assert.AreEqual(203, location.First.Bearing);
            Assert.AreEqual(FormOfWay.SingleCarriageWay, location.First.FormOfWay);
            Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.FuntionalRoadClass);
            Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.LowestFunctionalRoadClassToNext);

            Assert.AreEqual(49.60521f, location.Last.Coordinate.Latitude);
            Assert.AreEqual(6.12779f, location.Last.Coordinate.Longitude);
            Assert.AreEqual(23, location.Last.Bearing);

            // encode location with a point on the first point.
            referencedPointAlongLineLocation                = new ReferencedPointAlongLine();
            referencedPointAlongLineLocation.Route          = new ReferencedLine(graph);
            referencedPointAlongLineLocation.Route.Edges    = new LiveEdge[1];
            referencedPointAlongLineLocation.Route.Edges[0] = new LiveEdge()
            {
                Distance = 10,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            };
            referencedPointAlongLineLocation.Route.EdgeShapes    = new GeoCoordinateSimple[1][];
            referencedPointAlongLineLocation.Route.EdgeShapes[0] = new GeoCoordinateSimple[0];
            referencedPointAlongLineLocation.Route.Vertices      = new long[2];
            referencedPointAlongLineLocation.Route.Vertices[0]   = vertex1;
            referencedPointAlongLineLocation.Route.Vertices[1]   = vertex2;
            referencedPointAlongLineLocation.Latitude            = 49.60597f;
            referencedPointAlongLineLocation.Longitude           = 6.12829f;

            // encode location.
            location = referencedEncoder.EncodeReferenced(referencedPointAlongLineLocation);

            // test result.
            Assert.IsNotNull(location);
            Assert.AreEqual(SideOfRoad.OnOrAbove, location.SideOfRoad);
            Assert.AreEqual(Orientation.NoOrientation, location.Orientation);
            Assert.AreEqual(0, location.PositiveOffsetPercentage);

            Assert.AreEqual(49.60597f, location.First.Coordinate.Latitude);
            Assert.AreEqual(6.12829f, location.First.Coordinate.Longitude);
            Assert.AreEqual(91, location.First.DistanceToNext);
            Assert.AreEqual(FormOfWay.SingleCarriageWay, location.First.FormOfWay);
            Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.FuntionalRoadClass);
            Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.LowestFunctionalRoadClassToNext);

            Assert.AreEqual(49.60521f, location.Last.Coordinate.Latitude);
            Assert.AreEqual(6.12779f, location.Last.Coordinate.Longitude);

            // encode location with a point on the last point.
            referencedPointAlongLineLocation                = new ReferencedPointAlongLine();
            referencedPointAlongLineLocation.Route          = new ReferencedLine(graph);
            referencedPointAlongLineLocation.Route.Edges    = new LiveEdge[1];
            referencedPointAlongLineLocation.Route.Edges[0] = new LiveEdge()
            {
                Distance = 10,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            };
            referencedPointAlongLineLocation.Route.EdgeShapes    = new GeoCoordinateSimple[1][];
            referencedPointAlongLineLocation.Route.EdgeShapes[0] = new GeoCoordinateSimple[0];
            referencedPointAlongLineLocation.Route.Vertices      = new long[2];
            referencedPointAlongLineLocation.Route.Vertices[0]   = vertex1;
            referencedPointAlongLineLocation.Route.Vertices[1]   = vertex2;
            referencedPointAlongLineLocation.Latitude            = 49.60521f;
            referencedPointAlongLineLocation.Longitude           = 6.12779f;

            // encode location.
            location = referencedEncoder.EncodeReferenced(referencedPointAlongLineLocation);

            // test result.
            Assert.IsNotNull(location);
            Assert.AreEqual(SideOfRoad.OnOrAbove, location.SideOfRoad);
            Assert.AreEqual(Orientation.NoOrientation, location.Orientation);
            Assert.AreEqual(99, location.PositiveOffsetPercentage.Value);

            Assert.AreEqual(49.60597f, location.First.Coordinate.Latitude);
            Assert.AreEqual(6.12829f, location.First.Coordinate.Longitude);
            Assert.AreEqual(91, location.First.DistanceToNext);
            Assert.AreEqual(FormOfWay.SingleCarriageWay, location.First.FormOfWay);
            Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.FuntionalRoadClass);
            Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.LowestFunctionalRoadClassToNext);

            Assert.AreEqual(49.60521f, location.Last.Coordinate.Latitude);
            Assert.AreEqual(6.12779f, location.Last.Coordinate.Longitude);
        }
Beispiel #18
0
        public void DecodeReferencedLineLocation()
        {
            // build the location to decode.
            var location = new LineLocation();

            location.First            = new LocationReferencePoint();
            location.First.Coordinate = new Coordinate()
            {
                Latitude = 49.60851, Longitude = 6.12683
            };
            location.First.DistanceToNext     = 517;
            location.First.FuntionalRoadClass = FunctionalRoadClass.Frc3;
            location.First.FormOfWay          = FormOfWay.MultipleCarriageWay;
            location.First.LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc3;
            location.First.Bearing              = 0;
            location.Intermediate               = new LocationReferencePoint[1];
            location.Intermediate[0]            = new LocationReferencePoint();
            location.Intermediate[0].Coordinate = new Coordinate()
            {
                Latitude = 49.60398, Longitude = 6.12838
            };
            location.Intermediate[0].DistanceToNext     = 104;
            location.Intermediate[0].FuntionalRoadClass = FunctionalRoadClass.Frc3;
            location.Intermediate[0].FormOfWay          = FormOfWay.SingleCarriageWay;
            location.Intermediate[0].LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc5;
            location.Intermediate[0].Bearing = 0;
            location.Last            = new LocationReferencePoint();
            location.Last            = new LocationReferencePoint();
            location.Last.Coordinate = new Coordinate()
            {
                Latitude = 49.60305, Longitude = 6.12817
            };
            location.Last.DistanceToNext     = 0;
            location.Last.FuntionalRoadClass = FunctionalRoadClass.Frc5;
            location.Last.FormOfWay          = FormOfWay.SingleCarriageWay;
            location.Last.Bearing            = 0;

            // build a graph to decode onto.
            var  tags            = new TagsTableCollectionIndex();
            var  graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags);
            uint vertex1         = graphDataSource.AddVertex(49.60851f, 6.12683f);
            uint vertex2         = graphDataSource.AddVertex(49.60398f, 6.12838f);
            uint vertex3         = graphDataSource.AddVertex(49.60305f, 6.12817f);

            graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge()
            {
                Distance = 517,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            }, null);
            graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge()
            {
                Distance = 517,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            }, null);
            graphDataSource.AddEdge(vertex2, vertex3, new LiveEdge()
            {
                Distance = 104,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            }, null);
            graphDataSource.AddEdge(vertex3, vertex2, new LiveEdge()
            {
                Distance = 104,
                Forward  = true,
                Tags     = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary")))
            }, null);

            // decode the location
            var graph              = new BasicRouterDataSource <LiveEdge>(graphDataSource);
            var decoder            = new LineLocationDecoder();
            var router             = new BasicRouter();
            var mainDecoder        = new ReferencedOsmDecoder(graph, new BinaryDecoder());
            var referencedDecoder  = new ReferencedLineDecoder(mainDecoder, decoder);
            var referencedLocation = referencedDecoder.Decode(location);

            // confirm result.
            Assert.IsNotNull(referencedLocation);
            Assert.IsNotNull(referencedLocation.Vertices);
            Assert.AreEqual(3, referencedLocation.Vertices.Length);
            Assert.IsNotNull(referencedLocation.Edges);
            Assert.AreEqual(2, referencedLocation.Edges.Length);
        }
        public void RoutingRegressionTest11ResolvingReverse()
        {
            // build a graph to encode from.
            var tags            = new TagsTableCollectionIndex();
            var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(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 LiveEdge() // 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 <LiveEdge> >(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 <LiveEdge> >(graphDataSource.GetEdges(2));
            Assert.AreEqual(1, edges.Count);
            Assert.AreEqual(false, edges[0].EdgeData.Forward);

            edges = new List <Edge <LiveEdge> >(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 TagsTableCollectionIndex();
            var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(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 LiveEdge() // 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);
                }
            }
        }