/// <summary>
        /// Calculates routes, generates instructions and compares instructions.
        /// </summary>
        /// <param name="embeddedXml"></param>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        protected void DoInstructionComparisonTest(string embeddedXml, GeoCoordinate point1, GeoCoordinate point2)
        {
            Meter delta = 1;

            var interpreter = new OsmRoutingInterpreter();

            var router = this.CreateRouter(interpreter,
                                           embeddedXml);
            var referenceRouter = this.CreateReferenceRouter(interpreter,
                                                             embeddedXml);

            // resolve the three points in question.
            var point1resolved = router.Resolve(Vehicle.Car, point1, true);
            var point2resolved = router.Resolve(Vehicle.Car, point2, true);

            // calculate two smaller routes.
            var route12 = router.Calculate(Vehicle.Car,
                                           point1resolved, point2resolved);

            // resolve the three points in question.
            RouterPoint pointReference1resolved = referenceRouter.Resolve(Vehicle.Car, point1, true);
            RouterPoint pointReference2resolved = referenceRouter.Resolve(Vehicle.Car, point2, true);

            // test the resolved points.
            Assert.AreEqual(0, point1resolved.Location.DistanceReal(pointReference1resolved.Location).Value, delta.Value);
            Assert.AreEqual(0, point2resolved.Location.DistanceReal(pointReference2resolved.Location).Value, delta.Value);

            // calculate two smaller routes.
            Route routeReference12 = referenceRouter.Calculate(Vehicle.Car,
                                                               pointReference1resolved, pointReference2resolved);

            // compares the two routes.
            this.CompareRoutes(routeReference12, route12);

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate the instructions.
            var instructions          = InstructionGenerator.Generate(route12, interpreter, languageGenerator);
            var instructionsReference = InstructionGenerator.Generate(routeReference12, interpreter, languageGenerator);

            Assert.AreEqual(instructions.Count, instructionsReference.Count);
            for (int idx = 0; idx < instructions.Count; idx++)
            {
                Assert.AreEqual(instructions[idx].Location.Center,
                                instructionsReference[idx].Location.Center);
                Assert.AreEqual(instructions[idx].Text,
                                instructionsReference[idx].Text);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Issue with generation instructions but where streetnames seem to be stripped.
        /// Some streetnames are missing from the instructions.
        /// </summary>
        protected void DoInstructionRegressionTest1()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            Router router = this.CreateRouter(interpreter, "OsmSharp.Test.Unittests.test_routing_regression1.osm");

            // resolve the three points in question.
            GeoCoordinate point35         = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint   point35resolved = router.Resolve(Vehicle.Car, point35, true);
            GeoCoordinate point45         = new GeoCoordinate(51.01315, 3.999588);
            RouterPoint   point45resolved = router.Resolve(Vehicle.Car, point45, true);
            GeoCoordinate point40         = new GeoCoordinate(51.01250, 4.000013);
            RouterPoint   point40resolved = router.Resolve(Vehicle.Car, point40, true);

            // calculate two smaller routes.
            Route route3545             = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
            Route route4540             = router.Calculate(Vehicle.Car, point45resolved, point40resolved);
            Route route3540concatenated = Route.Concatenate(route3545, route4540, true);

            Route route3540 = router.Calculate(Vehicle.Car, point35resolved, point40resolved);

            // check if both routes are equal.
            Assert.AreEqual(route3540.Entries.Length, route3540concatenated.Entries.Length);
            for (int idx = 0; idx < route3540.Entries.Length; idx++)
            {
                Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance);
                Assert.AreEqual(route3540.Entries[idx].Latitude, route3540concatenated.Entries[idx].Latitude);
                Assert.AreEqual(route3540.Entries[idx].Longitude, route3540concatenated.Entries[idx].Longitude);
                Assert.AreEqual(route3540.Entries[idx].Time, route3540concatenated.Entries[idx].Time);
                Assert.AreEqual(route3540.Entries[idx].Type, route3540concatenated.Entries[idx].Type);
                Assert.AreEqual(route3540.Entries[idx].WayFromName, route3540concatenated.Entries[idx].WayFromName);

                // something that is allowed to be different in this case!
                // route3540.Entries[idx].Points != null

                //    // check sidestreets.
                //    if (route3540.Entries[idx].SideStreets != null &&
                //        route3540.Entries[idx].SideStreets.Length > 0)
                //    { // check if the sidestreets represent the same information.
                //        for (int metricIdx = 0; metricIdx < route3540concatenated.Entries[idx].SideStreets.Length; metricIdx++)
                //        {
                //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].WayName,
                //                route3540concatenated.Entries[idx].SideStreets[metricIdx].WayName);
                //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].Latitude,
                //                route3540concatenated.Entries[idx].SideStreets[metricIdx].Latitude);
                //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].Longitude,
                //                route3540concatenated.Entries[idx].SideStreets[metricIdx].Longitude);
                //        }
                //    }
                //    else
                //    {
                //        Assert.IsTrue(route3540concatenated.Entries[idx].SideStreets == null ||
                //            route3540concatenated.Entries[idx].SideStreets.Length == 0);
                //    }


                //    if (route3540.Entries[idx].Tags != null &&
                //        route3540.Entries[idx].Tags.Length > 0)
                //    { // check if the Tags represent the same information.
                //        for (int metricIdx = 0; metricIdx < route3540concatenated.Entries[idx].Tags.Length; metricIdx++)
                //        {
                //            Assert.AreEqual(route3540.Entries[idx].Tags[metricIdx].Key,
                //                route3540concatenated.Entries[idx].Tags[metricIdx].Key);
                //            Assert.AreEqual(route3540.Entries[idx].Tags[metricIdx].Value,
                //                route3540concatenated.Entries[idx].Tags[metricIdx].Value);
                //        }
                //    }
                //    else
                //    {
                //        Assert.IsTrue(route3540concatenated.Entries[idx].Tags == null ||
                //            route3540concatenated.Entries[idx].Tags.Length == 0);
                //    }

                //    Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance);
            }
            if (route3540.Tags != null &&
                route3540.Tags.Length > 0)
            {
                for (int tagIdx = 0; tagIdx < route3540.Tags.Length; tagIdx++)
                {
                    if (route3540.Tags[tagIdx].Key != "debug_route")
                    {
                        Assert.AreEqual(route3540.Tags[tagIdx].Key, route3540concatenated.Tags[tagIdx].Key);
                        Assert.AreEqual(route3540.Tags[tagIdx].Value, route3540concatenated.Tags[tagIdx].Value);
                    }
                }
            }
            else
            {
                Assert.IsTrue(route3540concatenated.Tags == null ||
                              route3540concatenated.Tags.Length == 0);
            }
            if (route3540.Metrics != null)
            {
                for (int metricIdx = 0; metricIdx < route3540concatenated.Entries.Length; metricIdx++)
                {
                    Assert.AreEqual(route3540.Metrics[metricIdx].Key, route3540concatenated.Metrics[metricIdx].Key);
                    Assert.AreEqual(route3540.Metrics[metricIdx].Value, route3540concatenated.Metrics[metricIdx].Value);
                }
            }
            else
            {
                Assert.IsNull(route3540concatenated.Metrics);
            }

            // remove the point in between, the only difference between the regular and the concatenated route.
            route3540concatenated.Entries[7].Points = null;

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate the instructions.
            List <Instruction> instructions =
                InstructionGenerator.Generate(route3540, interpreter, languageGenerator);
            List <Instruction> instructionsConcatenated =
                InstructionGenerator.Generate(route3540concatenated, interpreter, languageGenerator);

            Assert.AreEqual(instructions.Count, instructionsConcatenated.Count);
            for (int idx = 0; idx < instructions.Count; idx++)
            {
                Assert.AreEqual(instructions[idx].Location.Center,
                                instructionsConcatenated[idx].Location.Center);
                Assert.AreEqual(instructions[idx].Text,
                                instructionsConcatenated[idx].Text);
            }
        }
        /// <summary>
        /// Issue with generation of instruction between different algorithms.
        /// </summary>
        protected void DoInstructionRegressionTest2()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            Router router = this.CreateRouter(interpreter,
                "OsmSharp.Test.Unittests.test_routing_regression1.osm");
            Router referenceRouter = this.CreateReferenceRouter(interpreter,
                "OsmSharp.Test.Unittests.test_routing_regression1.osm");

            // resolve the three points in question.
            GeoCoordinate point1 = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint point1resolved = router.Resolve(Vehicle.Car, point1);
            GeoCoordinate point2 = new GeoCoordinate(51.01250, 4.000013);
            RouterPoint point2resolved = router.Resolve(Vehicle.Car, point2);

            // calculate two smaller routes.
            Route route12 = router.Calculate(Vehicle.Car,
                point1resolved, point2resolved);

            // resolve the three points in question.
            GeoCoordinate pointReference1 = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint pointReference1resolved = referenceRouter.Resolve(Vehicle.Car, point1);
            GeoCoordinate pointReference2 = new GeoCoordinate(51.01250, 4.000013);
            RouterPoint pointReference2resolved = referenceRouter.Resolve(Vehicle.Car, point2);

            // calculate two smaller routes.
            Route routeReference12 = referenceRouter.Calculate(Vehicle.Car,
                pointReference1resolved, pointReference2resolved);

            // compares the two routes.
            this.CompareRoutes(routeReference12, route12);

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate the instructions.
            List<Instruction> instructions =
                InstructionGenerator.Generate(route12, interpreter, languageGenerator);
            List<Instruction> instructionsReference =
                InstructionGenerator.Generate(routeReference12, interpreter, languageGenerator);

            Assert.AreEqual(instructions.Count, instructionsReference.Count);
            for (int idx = 0; idx < instructions.Count; idx++)
            {
                Assert.AreEqual(instructions[idx].Location.Center,
                    instructionsReference[idx].Location.Center);
                Assert.AreEqual(instructions[idx].Text,
                    instructionsReference[idx].Text);
            }
        }
        /// <summary>
        /// Issue with generation instructions but where streetnames seem to be stripped.
        /// Some streetnames are missing from the instructions.
        /// </summary>
        protected void DoInstructionRegressionTest1()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            Router router = this.CreateRouter(interpreter, "OsmSharp.Test.Unittests.test_routing_regression1.osm");

            // resolve the three points in question.
            GeoCoordinate point35 = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint point35resolved = router.Resolve(Vehicle.Car, point35);
            GeoCoordinate point45 = new GeoCoordinate(51.01315, 3.999588);
            RouterPoint point45resolved = router.Resolve(Vehicle.Car, point45);
            GeoCoordinate point40 = new GeoCoordinate(51.01250, 4.000013);
            RouterPoint point40resolved = router.Resolve(Vehicle.Car, point40);

            // calculate two smaller routes.
            Route route3545 = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
            Route route4540 = router.Calculate(Vehicle.Car, point45resolved, point40resolved);
            Route route3540concatenated = Route.Concatenate(route3545, route4540);

            Route route3540 = router.Calculate(Vehicle.Car, point35resolved, point40resolved);

            // check if both routes are equal.
            Assert.AreEqual(route3540.Entries.Length, route3540concatenated.Entries.Length);
            for (int idx = 0; idx < route3540.Entries.Length; idx++)
            {
                Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance);
                Assert.AreEqual(route3540.Entries[idx].Latitude, route3540concatenated.Entries[idx].Latitude);
                Assert.AreEqual(route3540.Entries[idx].Longitude, route3540concatenated.Entries[idx].Longitude);
                Assert.AreEqual(route3540.Entries[idx].Time, route3540concatenated.Entries[idx].Time);
                Assert.AreEqual(route3540.Entries[idx].Type, route3540concatenated.Entries[idx].Type);
                Assert.AreEqual(route3540.Entries[idx].WayFromName, route3540concatenated.Entries[idx].WayFromName);

                // something that is allowed to be different in this case!
                // route3540.Entries[idx].Points != null

            //    // check sidestreets.
            //    if (route3540.Entries[idx].SideStreets != null &&
            //        route3540.Entries[idx].SideStreets.Length > 0)
            //    { // check if the sidestreets represent the same information.
            //        for (int metricIdx = 0; metricIdx < route3540concatenated.Entries[idx].SideStreets.Length; metricIdx++)
            //        {
            //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].WayName,
            //                route3540concatenated.Entries[idx].SideStreets[metricIdx].WayName);
            //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].Latitude,
            //                route3540concatenated.Entries[idx].SideStreets[metricIdx].Latitude);
            //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].Longitude,
            //                route3540concatenated.Entries[idx].SideStreets[metricIdx].Longitude);
            //        }
            //    }
            //    else
            //    {
            //        Assert.IsTrue(route3540concatenated.Entries[idx].SideStreets == null ||
            //            route3540concatenated.Entries[idx].SideStreets.Length == 0);
            //    }

            //    if (route3540.Entries[idx].Tags != null &&
            //        route3540.Entries[idx].Tags.Length > 0)
            //    { // check if the Tags represent the same information.
            //        for (int metricIdx = 0; metricIdx < route3540concatenated.Entries[idx].Tags.Length; metricIdx++)
            //        {
            //            Assert.AreEqual(route3540.Entries[idx].Tags[metricIdx].Key,
            //                route3540concatenated.Entries[idx].Tags[metricIdx].Key);
            //            Assert.AreEqual(route3540.Entries[idx].Tags[metricIdx].Value,
            //                route3540concatenated.Entries[idx].Tags[metricIdx].Value);
            //        }
            //    }
            //    else
            //    {
            //        Assert.IsTrue(route3540concatenated.Entries[idx].Tags == null ||
            //            route3540concatenated.Entries[idx].Tags.Length == 0);
            //    }

            //    Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance);
            }
            if (route3540.Tags != null &&
                route3540.Tags.Length > 0)
            {
                for (int tagIdx = 0; tagIdx < route3540.Tags.Length; tagIdx++)
                {
                    if (route3540.Tags[tagIdx].Key != "debug_route")
                    {
                        Assert.AreEqual(route3540.Tags[tagIdx].Key, route3540concatenated.Tags[tagIdx].Key);
                        Assert.AreEqual(route3540.Tags[tagIdx].Value, route3540concatenated.Tags[tagIdx].Value);
                    }
                }
            }
            else
            {
                Assert.IsTrue(route3540concatenated.Tags == null ||
                    route3540concatenated.Tags.Length == 0);
            }
            if (route3540.Metrics != null)
            {
                for (int metricIdx = 0; metricIdx < route3540concatenated.Entries.Length; metricIdx++)
                {
                    Assert.AreEqual(route3540.Metrics[metricIdx].Key, route3540concatenated.Metrics[metricIdx].Key);
                    Assert.AreEqual(route3540.Metrics[metricIdx].Value, route3540concatenated.Metrics[metricIdx].Value);
                }
            }
            else
            {
                Assert.IsNull(route3540concatenated.Metrics);
            }

            // remove the point in between, the only difference between the regular and the concatenated route.
            route3540concatenated.Entries[7].Points = null;

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate the instructions.
            List<Instruction> instructions =
                InstructionGenerator.Generate(route3540, interpreter, languageGenerator);
            List<Instruction> instructionsConcatenated =
                InstructionGenerator.Generate(route3540concatenated, interpreter, languageGenerator);

            Assert.AreEqual(instructions.Count, instructionsConcatenated.Count);
            for (int idx = 0; idx < instructions.Count; idx++)
            {
                Assert.AreEqual(instructions[idx].Location.Center,
                    instructionsConcatenated[idx].Location.Center);
                Assert.AreEqual(instructions[idx].Text,
                    instructionsConcatenated[idx].Text);
            }
        }
Esempio n. 5
0
        public void TestSimpleTurn()
        {
            var route = new Route();
            route.Vehicle = Vehicle.Car.UniqueName;
            route.Segments = new RouteSegment[3];
            route.Segments[0] = new RouteSegment()
            {
                Distance = 0,
                Latitude = 50.999f,
                Longitude = 4,
                Points = new RoutePoint[] { 
                    new RoutePoint() 
                    {
                        Latitude = 50.999f,
                        Longitude = 4,
                        Name = "Start"
                    }},
                SideStreets = null,
                Type = RouteSegmentType.Start
            };
            route.Segments[1] = new RouteSegment()
            {
                Distance = 0,
                Latitude = 51,
                Longitude = 4,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "Street A" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                Type = RouteSegmentType.Along,
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                }
            };
            route.Segments[2] = new RouteSegment()
            {
                Distance = 0,
                Latitude = 51,
                Longitude = 4.001f,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "Street B" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                Type = RouteSegmentType.Stop,
                Points = new RoutePoint[] { 
                    new RoutePoint() 
                    {
                        Latitude = 51,
                        Longitude = 4.001f,
                        Name = "Stop"
                    }},
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List<Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[1].Text);
        }
Esempio n. 6
0
        public void TestRoundaboutExtended()
        {
            var westWest = new GeoCoordinate(51, 3.998);
            var west = new GeoCoordinate(51, 3.999);
            var eastEast = new GeoCoordinate(51, 4.002);
            var east = new GeoCoordinate(51, 4.001);
            var north = new GeoCoordinate(51.001, 4);
            var northNorth = new GeoCoordinate(51.002, 4);
            var south = new GeoCoordinate(50.999, 4);
            var southSouth = new GeoCoordinate(50.998, 4);
            var southSouthSouth = new GeoCoordinate(50.997, 4);
            var center = new GeoCoordinate(51, 4);

            var route = new Route();
            route.Vehicle = Vehicle.Car.UniqueName;
            route.Segments = new RouteSegment[6];
            route.Segments[0] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Points = new RoutePoint[] { 
                    new RoutePoint() 
                    {
                        Latitude = (float)southSouthSouth.Latitude,
                        Longitude = (float)southSouthSouth.Longitude,
                        Name = "Start"
                    }},
                SideStreets = null,
                Type = RouteSegmentType.Start
            };
            route.Segments[1] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "SouthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = null,
                Type = RouteSegmentType.Along
            };
            route.Segments[2] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)south.Latitude,
                Longitude = (float)south.Longitude,
                Type = RouteSegmentType.Along,
                Name = "SouthStreet",
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "SouthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    },
                    new RouteSegmentBranch() { 
                        Latitude = (float)east.Latitude,
                        Longitude = (float)east.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                }
            };
            route.Segments[3] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)east.Latitude,
                Longitude = (float)east.Longitude,
                Type = RouteSegmentType.Along,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "junction", Value = "roundabout" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = (float)eastEast.Latitude,
                        Longitude = (float)eastEast.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "EastStreet" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "EastStreet"
                    }
                }
            };
            route.Segments[4] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)north.Latitude,
                Longitude = (float)north.Longitude,
                Type = RouteSegmentType.Along,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "junction", Value = "roundabout" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        }
                    }
                }
            };
            route.Segments[5] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)northNorth.Latitude,
                Longitude = (float)northNorth.Longitude,
                Type = RouteSegmentType.Stop,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "NorthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                Points = new RoutePoint[] { 
                    new RoutePoint() 
                    {
                        Latitude = (float)north.Latitude,
                        Longitude = (float)north.Longitude,
                        Name = "Stop"
                    }}
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List<Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateRoundabout:3", instructions[1].Text);
        }
        /// <summary>
        /// Calculates routes, generates instructions and compares instructions.
        /// </summary>
        /// <param name="embeddedXml"></param>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        protected void DoInstructionComparisonTest(string embeddedXml, GeoCoordinate point1, GeoCoordinate point2)
        {
            Meter delta = 1;

            var interpreter = new OsmRoutingInterpreter();

            var router = this.CreateRouter(interpreter,
                embeddedXml);
            var referenceRouter = this.CreateReferenceRouter(interpreter,
                embeddedXml);

            // resolve the three points in question.
            var point1resolved = router.Resolve(Vehicle.Car, point1, true);
            var point2resolved = router.Resolve(Vehicle.Car, point2, true);

            // calculate two smaller routes.
            var route12 = router.Calculate(Vehicle.Car,
                point1resolved, point2resolved);

            // resolve the three points in question.
            RouterPoint pointReference1resolved = referenceRouter.Resolve(Vehicle.Car, point1, true);
            RouterPoint pointReference2resolved = referenceRouter.Resolve(Vehicle.Car, point2, true);

            // test the resolved points.
            Assert.AreEqual(0, point1resolved.Location.DistanceReal(pointReference1resolved.Location).Value, delta.Value);
            Assert.AreEqual(0, point2resolved.Location.DistanceReal(pointReference2resolved.Location).Value, delta.Value);

            // calculate two smaller routes.
            Route routeReference12 = referenceRouter.Calculate(Vehicle.Car,
                pointReference1resolved, pointReference2resolved);

            // compares the two routes.
            this.CompareRoutes(routeReference12, route12);

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate the instructions.
            var instructions =  InstructionGenerator.Generate(route12, interpreter, languageGenerator);
            var instructionsReference = InstructionGenerator.Generate(routeReference12, interpreter, languageGenerator);

            Assert.AreEqual(instructions.Count, instructionsReference.Count);
            for (int idx = 0; idx < instructions.Count; idx++)
            {
                Assert.AreEqual(instructions[idx].Location.Center,
                    instructionsReference[idx].Location.Center);
                Assert.AreEqual(instructions[idx].Text,
                    instructionsReference[idx].Text);
            }
        }
Esempio n. 8
0
        public void TestRoundabout()
        {
            GeoCoordinate westWest = new GeoCoordinate(51, 3.998);
            GeoCoordinate west = new GeoCoordinate(51, 3.999);
            GeoCoordinate eastEast = new GeoCoordinate(51, 4.002);
            GeoCoordinate east = new GeoCoordinate(51, 4.001);
            GeoCoordinate north = new GeoCoordinate(51.001, 4);
            GeoCoordinate northNorth = new GeoCoordinate(51.002, 4);
            GeoCoordinate south = new GeoCoordinate(50.999, 4);
            GeoCoordinate southSouth = new GeoCoordinate(50.998, 4);
            GeoCoordinate center = new GeoCoordinate(51, 4);

            Route route = new Route();
            route.Vehicle = Vehicle.Car;
            route.Entries = new RoutePointEntry[5];
            route.Entries[0] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Points = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude = (float)southSouth.Latitude,
                        Longitude = (float)southSouth.Longitude,
                        Name = "Start"
                    }},
                SideStreets = null,
                Type = RoutePointEntryType.Start
            };
            route.Entries[1] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)south.Latitude,
                Longitude = (float)south.Longitude,
                Type = RoutePointEntryType.Along,
                WayFromName = "SouthStreet",
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "SouthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet() {
                        Latitude = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        WayName = "Street B"
                    },
                    new RoutePointEntrySideStreet() {
                        Latitude = (float)east.Latitude,
                        Longitude = (float)east.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        WayName = "Street B"
                    }
                }
            };
            route.Entries[2] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)east.Latitude,
                Longitude = (float)east.Longitude,
                Type = RoutePointEntryType.Along,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "junction", Value = "roundabout" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet() {
                        Latitude = (float)eastEast.Latitude,
                        Longitude = (float)eastEast.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "EastStreet" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        WayName = "EastStreet"
                    }
                }
            };
            route.Entries[3] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)north.Latitude,
                Longitude = (float)north.Longitude,
                Type = RoutePointEntryType.Along,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "junction", Value = "roundabout" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet() {
                        Latitude = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        }
                    }
                }
            };
            route.Entries[4] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)northNorth.Latitude,
                Longitude = (float)northNorth.Longitude,
                Type = RoutePointEntryType.Stop,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "NorthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                Points = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude = (float)north.Latitude,
                        Longitude = (float)north.Longitude,
                        Name = "Stop"
                    }}
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List<Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateRoundabout:1", instructions[1].Text);
        }
Esempio n. 9
0
        public void TestSimpleTurn()
        {
            var route = new Route();

            route.Vehicle     = Vehicle.Car.UniqueName;
            route.Segments    = new RouteSegment[3];
            route.Segments[0] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = 50.999f,
                Longitude = 4,
                Points    = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude  = 50.999f,
                        Longitude = 4,
                        Name      = "Start"
                    }
                },
                SideStreets = null,
                Type        = RouteSegmentType.Start
            };
            route.Segments[1] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = 51,
                Longitude = 4,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "name", Value = "Street A"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                Type        = RouteSegmentType.Along,
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch()
                    {
                        Latitude  = 51,
                        Longitude = 3.999f,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "name", Value = "Street B"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        },
                        Name = "Street B"
                    }
                }
            };
            route.Segments[2] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = 51,
                Longitude = 4.001f,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "name", Value = "Street B"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                Type   = RouteSegmentType.Stop,
                Points = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude  = 51,
                        Longitude = 4.001f,
                        Name      = "Stop"
                    }
                },
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List <Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);

            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[1].Text);
        }
Esempio n. 10
0
        public void TestRoundaboutExtended()
        {
            var westWest        = new GeoCoordinate(51, 3.998);
            var west            = new GeoCoordinate(51, 3.999);
            var eastEast        = new GeoCoordinate(51, 4.002);
            var east            = new GeoCoordinate(51, 4.001);
            var north           = new GeoCoordinate(51.001, 4);
            var northNorth      = new GeoCoordinate(51.002, 4);
            var south           = new GeoCoordinate(50.999, 4);
            var southSouth      = new GeoCoordinate(50.998, 4);
            var southSouthSouth = new GeoCoordinate(50.997, 4);
            var center          = new GeoCoordinate(51, 4);

            var route = new Route();

            route.Vehicle     = Vehicle.Car.UniqueName;
            route.Segments    = new RouteSegment[6];
            route.Segments[0] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Points    = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude  = (float)southSouthSouth.Latitude,
                        Longitude = (float)southSouthSouth.Longitude,
                        Name      = "Start"
                    }
                },
                SideStreets = null,
                Type        = RouteSegmentType.Start
            };
            route.Segments[1] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "name", Value = "SouthStreet"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                SideStreets = null,
                Type        = RouteSegmentType.Along
            };
            route.Segments[2] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = (float)south.Latitude,
                Longitude = (float)south.Longitude,
                Type      = RouteSegmentType.Along,
                Name      = "SouthStreet",
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "name", Value = "SouthStreet"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch()
                    {
                        Latitude  = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "junction", Value = "roundabout"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        },
                        Name = "Street B"
                    },
                    new RouteSegmentBranch()
                    {
                        Latitude  = (float)east.Latitude,
                        Longitude = (float)east.Longitude,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "junction", Value = "roundabout"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        },
                        Name = "Street B"
                    }
                }
            };
            route.Segments[3] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = (float)east.Latitude,
                Longitude = (float)east.Longitude,
                Type      = RouteSegmentType.Along,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "junction", Value = "roundabout"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch()
                    {
                        Latitude  = (float)eastEast.Latitude,
                        Longitude = (float)eastEast.Longitude,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "name", Value = "EastStreet"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        },
                        Name = "EastStreet"
                    }
                }
            };
            route.Segments[4] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = (float)north.Latitude,
                Longitude = (float)north.Longitude,
                Type      = RouteSegmentType.Along,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "junction", Value = "roundabout"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch()
                    {
                        Latitude  = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "junction", Value = "roundabout"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        }
                    }
                }
            };
            route.Segments[5] = new RouteSegment()
            {
                Distance  = 0,
                Latitude  = (float)northNorth.Latitude,
                Longitude = (float)northNorth.Longitude,
                Type      = RouteSegmentType.Stop,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "name", Value = "NorthStreet"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                Points = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude  = (float)north.Latitude,
                        Longitude = (float)north.Longitude,
                        Name      = "Stop"
                    }
                }
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List <Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);

            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateRoundabout:3", instructions[1].Text);
        }
Esempio n. 11
0
        public void TestRoundabout()
        {
            GeoCoordinate westWest   = new GeoCoordinate(51, 3.998);
            GeoCoordinate west       = new GeoCoordinate(51, 3.999);
            GeoCoordinate eastEast   = new GeoCoordinate(51, 4.002);
            GeoCoordinate east       = new GeoCoordinate(51, 4.001);
            GeoCoordinate north      = new GeoCoordinate(51.001, 4);
            GeoCoordinate northNorth = new GeoCoordinate(51.002, 4);
            GeoCoordinate south      = new GeoCoordinate(50.999, 4);
            GeoCoordinate southSouth = new GeoCoordinate(50.998, 4);
            GeoCoordinate center     = new GeoCoordinate(51, 4);

            Route route = new Route();

            route.Vehicle    = Vehicle.Car;
            route.Entries    = new RoutePointEntry[5];
            route.Entries[0] = new RoutePointEntry()
            {
                Distance  = 0,
                Latitude  = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Points    = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude  = (float)southSouth.Latitude,
                        Longitude = (float)southSouth.Longitude,
                        Name      = "Start"
                    }
                },
                SideStreets = null,
                Type        = RoutePointEntryType.Start
            };
            route.Entries[1] = new RoutePointEntry()
            {
                Distance    = 0,
                Latitude    = (float)south.Latitude,
                Longitude   = (float)south.Longitude,
                Type        = RoutePointEntryType.Along,
                WayFromName = "SouthStreet",
                Tags        = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "name", Value = "SouthStreet"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet()
                    {
                        Latitude  = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "junction", Value = "roundabout"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        },
                        WayName = "Street B"
                    },
                    new RoutePointEntrySideStreet()
                    {
                        Latitude  = (float)east.Latitude,
                        Longitude = (float)east.Longitude,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "junction", Value = "roundabout"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        },
                        WayName = "Street B"
                    }
                }
            };
            route.Entries[2] = new RoutePointEntry()
            {
                Distance  = 0,
                Latitude  = (float)east.Latitude,
                Longitude = (float)east.Longitude,
                Type      = RoutePointEntryType.Along,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "junction", Value = "roundabout"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet()
                    {
                        Latitude  = (float)eastEast.Latitude,
                        Longitude = (float)eastEast.Longitude,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "name", Value = "EastStreet"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        },
                        WayName = "EastStreet"
                    }
                }
            };
            route.Entries[3] = new RoutePointEntry()
            {
                Distance  = 0,
                Latitude  = (float)north.Latitude,
                Longitude = (float)north.Longitude,
                Type      = RoutePointEntryType.Along,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "junction", Value = "roundabout"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet()
                    {
                        Latitude  = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags      = new RouteTags[] {
                            new RouteTags()
                            {
                                Key = "junction", Value = "roundabout"
                            },
                            new RouteTags()
                            {
                                Key = "highway", Value = "residential"
                            }
                        }
                    }
                }
            };
            route.Entries[4] = new RoutePointEntry()
            {
                Distance  = 0,
                Latitude  = (float)northNorth.Latitude,
                Longitude = (float)northNorth.Longitude,
                Type      = RoutePointEntryType.Stop,
                Tags      = new RouteTags[] {
                    new RouteTags()
                    {
                        Key = "name", Value = "NorthStreet"
                    },
                    new RouteTags()
                    {
                        Key = "highway", Value = "residential"
                    }
                },
                Points = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude  = (float)north.Latitude,
                        Longitude = (float)north.Longitude,
                        Name      = "Stop"
                    }
                }
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List <Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);

            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateRoundabout:1", instructions[1].Text);
        }