示例#1
0
        /// <summary>
        /// Calculcates the metrics.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public override Dictionary <string, double> Calculate(Vehicle vehicle, AggregatedPoint p)
        {
            Dictionary <string, double> result = new Dictionary <string, double>();

            result.Add(DISTANCE_KEY, 0);
            result.Add(TIME_KEY, 0);

            Aggregated next = p;

            while (next != null)
            {
                if (next is AggregatedPoint)
                {
                    AggregatedPoint point = (next as AggregatedPoint);
                    this.CalculatePointMetrics(vehicle, result, point);
                }
                if (next is AggregatedArc)
                {
                    AggregatedArc arc = (next as AggregatedArc);
                    this.CalculateArcMetrics(vehicle, result, arc);
                }

                next = next.GetNext();
            }

            return(result);
        }
        public override void Succes()
        {
            // get the last arc and the last point.
            AggregatedArc   latest_arc   = (this.FinalMessages[this.FinalMessages.Count - 2] as MicroPlannerMessageArc).Arc;
            AggregatedPoint latest_point = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point;

            // count the number of streets in the same turning direction as the turn
            // that was found.
            int count = 0;

            if (MicroPlannerHelper.IsLeft(latest_point.Angle.Direction, this.Planner.Interpreter))
            {
                count = MicroPlannerHelper.GetLeft(this.FinalMessages, this.Planner.Interpreter);
            }
            else if (MicroPlannerHelper.IsRight(latest_point.Angle.Direction, this.Planner.Interpreter))
            {
                count = MicroPlannerHelper.GetRight(this.FinalMessages, this.Planner.Interpreter);
            }

            // construct the box indicating the location of the resulting find by this machine.
            GeoCoordinate    point1 = latest_point.Location;
            GeoCoordinateBox box    = new GeoCoordinateBox(
                new GeoCoordinate(point1.Latitude - 0.001f, point1.Longitude - 0.001f),
                new GeoCoordinate(point1.Latitude + 0.001f, point1.Longitude + 0.001f));

            //string next_street = latest_point.Next.Name;

            // let the scentence planner generate the correct information.
            this.Planner.SentencePlanner.GenerateRoundabout(box, count - 1, latest_point.Next.Tags);
        }
示例#3
0
        /// <summary>
        /// Called when this machine is succesfull.
        /// </summary>
        public override void Succes()
        {
            // get first point.
            AggregatedPoint firstPoint = null;

            if (this.FinalMessages[0] is MicroPlannerMessagePoint)
            { // machine started on a point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessagePoint).Point;
            }
            else
            { // get the previous point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessageArc).Arc.Previous;
            }

            var poisPoint = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point;

            var pois = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point.Points;

            // construct the box indicating the location of the resulting find by this machine.
            var point1 = pois[0].Location;
            var box    = new GeoCoordinateBox(
                new GeoCoordinate(point1.Latitude - 0.001f, point1.Longitude - 0.001f),
                new GeoCoordinate(point1.Latitude + 0.001f, point1.Longitude + 0.001f));

            // let the scentence planner generate the correct information.
            var metaData = new Dictionary <string, object>();

            metaData["direction"] = null;
            metaData["pois"]      = pois;
            metaData["type"]      = "poi";
            this.Planner.SentencePlanner.GenerateInstruction(metaData, firstPoint.SegmentIdx, poisPoint.SegmentIdx, box, pois);
        }
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="interpreter"></param>
        /// <param name="languageGenerator"></param>
        /// <returns></returns>
        public static List <Instruction> Generate(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator)
        {
            if (route == null)
            {
                throw new ArgumentNullException("route");
            }
            if (route.Vehicle == null)
            {
                throw new InvalidOperationException("Vehicle not set on route: Cannot generate instruction for a route without a vehicle!");
            }
            if (interpreter == null)
            {
                throw new ArgumentNullException("interpreter");
            }
            if (languageGenerator == null)
            {
                throw new ArgumentNullException("languageGenerator");
            }

            OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator =
                new OsmSharp.Routing.ArcAggregation.ArcAggregator(interpreter);
            AggregatedPoint point =
                aggregator.Aggregate(route);

            return(InstructionGenerator.Generate(point, interpreter, languageGenerator));
        }
示例#5
0
        /// <summary>
        /// Aggregates a route by remove information useless to the generation of routing instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <returns></returns>
        public AggregatedPoint Aggregate(Route route)
        {
            // create the enumerator.
            var enumerator = new AggregatedPointEnumerator(route);

            AggregatedRoutePoint previous      = null;
            AggregatedRoutePoint current       = null;
            AggregatedRoutePoint next          = null;
            AggregatedPoint      previousPoint = null;
            AggregatedArc        previousArc   = null;
            AggregatedPoint      p             = null;

            // loop over all aggregated points.
            while (enumerator.MoveNext())
            {
                // get the next point.
                next = enumerator.Current;

                // process
                this.Process(route, previous, current, next, ref p, ref previousArc, ref previousPoint);

                // make the next, current and the current previous.
                previous = current;
                current  = next;
                next     = null;
            }

            // process once more, the current current has not been processed.
            this.Process(route, previous, current, next, ref p, ref previousArc, ref previousPoint);

            return(p);
        }
示例#6
0
        /// <summary>
        /// Calculates metrics for the given route.
        /// </summary>
        /// <param name="route"></param>
        /// <returns></returns>
        public Dictionary <string, double> Calculate(OsmSharpRoute route)
        {
            OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator =
                new OsmSharp.Routing.ArcAggregation.ArcAggregator(_interpreter);
            AggregatedPoint p = aggregator.Aggregate(route);

            return(this.Calculate(route.Vehicle, p));
        }
示例#7
0
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="interpreter"></param>
        /// <param name="languageGenerator"></param>
        /// <returns></returns>
        public static List <Instruction> Generate(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator)
        {
            OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator =
                new OsmSharp.Routing.ArcAggregation.ArcAggregator(interpreter);
            AggregatedPoint point =
                aggregator.Aggregate(route);

            return(InstructionGenerator.Generate(point, interpreter, languageGenerator));
        }
示例#8
0
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="planner"></param>
        /// <param name="route"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static List <Instruction> Generate(MicroPlanner planner, Route route, AggregatedPoint point)
        {
            if (point == null)
            {
                throw new ArgumentNullException("route");
            }
            if (planner == null)
            {
                throw new ArgumentNullException("planner");
            }

            return(planner.Plan(route, point));
        }
示例#9
0
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="point"></param>
        /// <param name="interpreter"></param>
        /// <param name="languageGenerator"></param>
        /// <returns></returns>
        public static List <Instruction> Generate(Route route, AggregatedPoint point, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator)
        {
            if (point == null)
            {
                throw new ArgumentNullException("route");
            }
            if (interpreter == null)
            {
                throw new ArgumentNullException("interpreter");
            }
            if (languageGenerator == null)
            {
                throw new ArgumentNullException("languageGenerator");
            }

            return(InstructionGenerator.Generate(new MicroPlanner(languageGenerator, interpreter), route, point));
        }
示例#10
0
        /// <summary>
        /// Called when this machine is succesfull.
        /// </summary>
        public override void Succes()
        {
            // get first point.
            AggregatedPoint firstPoint = null;

            if (this.FinalMessages[0] is MicroPlannerMessagePoint)
            { // machine started on a point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessagePoint).Point;
            }
            else
            { // get the previous point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessageArc).Arc.Previous;
            }

            // get the last arc and the last point.
            var latestArc   = (this.FinalMessages[this.FinalMessages.Count - 2] as MicroPlannerMessageArc).Arc;
            var latestPoint = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point;

            // count the number of streets in the same turning direction as the turn
            // that was found.
            int count = 0;

            if (MicroPlannerHelper.IsLeft(latestPoint.Angle.Direction, this.Planner.Interpreter))
            {
                count = MicroPlannerHelper.GetLeft(this.FinalMessages, this.Planner.Interpreter);
            }
            else if (MicroPlannerHelper.IsRight(latestPoint.Angle.Direction, this.Planner.Interpreter))
            {
                count = MicroPlannerHelper.GetRight(this.FinalMessages, this.Planner.Interpreter);
            }

            // construct the box indicating the location of the resulting find by this machine.
            var point1 = latestPoint.Location;
            var box    = new GeoCoordinateBox(
                new GeoCoordinate(point1.Latitude - 0.001f, point1.Longitude - 0.001f),
                new GeoCoordinate(point1.Latitude + 0.001f, point1.Longitude + 0.001f));

            // let the scentence planner generate the correct information.
            var metaData = new Dictionary <string, object>();

            metaData["count"]  = count + 1;
            metaData["street"] = latestPoint.Next.Tags;
            metaData["pois"]   = latestPoint.Points;
            metaData["type"]   = "roundabout";
            this.Planner.SentencePlanner.GenerateInstruction(metaData, firstPoint.SegmentIdx, latestPoint.SegmentIdx, box, latestPoint.Points);
        }
示例#11
0
        /// <summary>
        /// Plans all the messages in the aggregated
        /// </summary>
        /// <param name="p"></param>
        public List <Instruction> Plan(AggregatedPoint p)
        {
            // set the current aggregated object.
            _current = p;

            // loop until the current object is null.
            while (_current != null)
            {
                while (_current != null)
                {
                    if (_current is AggregatedPoint)
                    {
                        if ((_current as AggregatedPoint).Location.Latitude == 51.254875183105469)
                        {
                            Console.WriteLine("BINGO!");
                        }
                    }
                    // plan the current message.
                    this.PlanNewMessage(_current);

                    // get the next object.
                    _current = _current.GetNext();
                }

                // show the latest success anyway.
                if (_latest_final >= 0)
                { // do the latest succes.
                    this.Success(_latest_machine);

                    // get the next object.
                    if (_current != null)
                    {
                        _current = _current.GetNext();
                    }
                }
                else if (_messages_stack.Count > 0)
                { // no machine matches everything until the end of the route.
                    throw new MicroPlannerException("No machine could be found matching the current stack of messages!", _messages_stack);
                }
            }

            // return the instructions list accumulated in the scentence planner.
            return(this.SentencePlanner.Instructions);
        }
        public override void Succes()
        {
            // get the last arc and the last point.
            AggregatedArc   latestArc         = (this.FinalMessages[this.FinalMessages.Count - 2] as MicroPlannerMessageArc).Arc;
            AggregatedPoint latestPoint       = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point;
            AggregatedArc   secondLatestArc   = (this.FinalMessages[this.FinalMessages.Count - 4] as MicroPlannerMessageArc).Arc;
            AggregatedPoint secondLatestPoint = (this.FinalMessages[this.FinalMessages.Count - 3] as MicroPlannerMessagePoint).Point;

            // count the number of streets in the same turning direction as the turn
            // that was found.
            int count = 0;

            if (MicroPlannerHelper.IsLeft(latestPoint.Angle.Direction, this.Planner.Interpreter))
            {
                count = MicroPlannerHelper.GetLeft(this.FinalMessages, this.Planner.Interpreter);
            }
            else if (MicroPlannerHelper.IsRight(latestPoint.Angle.Direction, this.Planner.Interpreter))
            {
                count = MicroPlannerHelper.GetRight(this.FinalMessages, this.Planner.Interpreter);
            }

            // construct the box indicating the location of the resulting find by this machine.
            GeoCoordinate    point1 = latestPoint.Location;
            GeoCoordinateBox box    = new GeoCoordinateBox(
                new GeoCoordinate(point1.Latitude - 0.001f, point1.Longitude - 0.001f),
                new GeoCoordinate(point1.Latitude + 0.001f, point1.Longitude + 0.001f));

            // get all the names/direction/counts.
            TagsCollectionBase nextName    = latestPoint.Next.Tags;
            TagsCollectionBase betweenName = latestArc.Tags;
            TagsCollectionBase beforeName  = secondLatestArc.Tags;

            int firstCount = count;

            RelativeDirection firstTurn  = secondLatestPoint.Angle;
            RelativeDirection secondTurn = latestPoint.Angle;

            // let the scentence planner generate the correct information.
            this.Planner.SentencePlanner.GenerateImmidiateTurn(latestPoint.EntryIdx, box, beforeName,
                                                               firstTurn, firstCount, secondTurn, betweenName, nextName, latestPoint.Points);
        }
示例#13
0
        /// <summary>
        /// Called when this machine is succesfull.
        /// </summary>
        public override void Succes()
        {
            // get first point.
            AggregatedPoint firstPoint = null;

            if (this.FinalMessages[0] is MicroPlannerMessagePoint)
            { // machine started on a point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessagePoint).Point;
            }
            else
            { // get the previous point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessageArc).Arc.Previous;
            }

            var poisPoint   = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point;
            var previousArc = (this.FinalMessages[this.FinalMessages.Count - 2] as MicroPlannerMessageArc).Arc;

            // get the pois list.
            var pois = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point.Points;

            // get the angle from the pois point.
            var direction = poisPoint.Angle;

            // calculate the box.
            var coordinates = new List <GeoCoordinate>();

            foreach (ArcAggregation.Output.PointPoi poi in pois)
            {
                coordinates.Add(poi.Location);
            }
            coordinates.Add(poisPoint.Location);
            var box = new GeoCoordinateBox(coordinates.ToArray());

            // let the scentence planner generate the correct information.
            var metaData = new Dictionary <string, object>();

            metaData["direction"] = direction;
            metaData["pois"]      = pois;
            metaData["type"]      = "poi";
            this.Planner.SentencePlanner.GenerateInstruction(metaData, firstPoint.SegmentIdx, poisPoint.SegmentIdx, box, pois);
        }
示例#14
0
        /// <summary>
        /// Returns the boundingbox for the current message consumed in this machine.
        /// </summary>
        /// <returns></returns>
        protected GeoCoordinateBox GetBoxForCurrentMessages()
        {
            if (this.FinalMessages.Count == 0)
            {
                return(null);
            }

            var route = this.FinalMessages[0].Route;

            // get first and last point.
            AggregatedPoint firstPoint = null;

            if (this.FinalMessages[0] is MicroPlannerMessagePoint)
            { // machine started on a point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessagePoint).Point;
            }
            else
            { // get the previous point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessageArc).Arc.Previous;
            }
            AggregatedPoint lastPoint = null;

            if (this.FinalMessages[this.FinalMessages.Count - 1] is MicroPlannerMessagePoint)
            { // machine ended on a point.
                lastPoint = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point;
            }
            else
            { // machine ended on an arc.
                lastPoint = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessageArc).Arc.Next;
            }

            // build the boundingbox.
            var points = new List <GeoCoordinate>();

            for (int segmentIdx = firstPoint.SegmentIdx; segmentIdx <= lastPoint.SegmentIdx; segmentIdx++)
            {
                var segment = route.Segments[segmentIdx];
                points.Add(new GeoCoordinate(segment.Latitude, segment.Longitude));
            }
            return(new GeoCoordinateBox(points.ToArray()));
        }
示例#15
0
        /// <summary>
        /// Plans all the messages in the aggregated
        /// </summary>
        /// <param name="route"></param>
        /// <param name="p"></param>
        public List <Instruction> Plan(Route route, AggregatedPoint p)
        {
            // set the current aggregated object.
            _current = p;

            // loop until the current object is null.
            while (_current != null)
            {
                while (_current != null)
                {
                    // plan the current message.
                    this.PlanNewMessage(route, _current);

                    // get the next object.
                    _current = _current.GetNext();
                }

                // show the latest success anyway.
                if (_latestFinal >= 0)
                { // do the latest succes.
                    this.Success(_latestMachine);

                    // get the next object.
                    if (_current != null)
                    {
                        _current = _current.GetNext();
                    }
                }
                else if (_messagesStack.Count > 0)
                { // no machine matches everything until the end of the route.
                    throw new MicroPlannerException("No machine could be found matching the current stack of messages!", _messagesStack);
                }
            }

            // return the instructions list accumulated in the scentence planner.
            return(this.SentencePlanner.Instructions);
        }
示例#16
0
        /// <summary>
        /// Processes a part of the route.
        /// </summary>
        private void Process(Route route, AggregatedRoutePoint previous, AggregatedRoutePoint current,
                             AggregatedRoutePoint next, ref AggregatedPoint p, ref AggregatedArc previousArc, ref AggregatedPoint previousPoint)
        {
            // process the current point.
            if (current != null)
            {
                if (previous == null)
                { // point is always significant, it is the starting point!
                    // create point.
                    p              = new AggregatedPoint();
                    p.Angle        = null;
                    p.ArcsNotTaken = null;
                    p.Location     = new GeoCoordinate(current.Segment.Latitude, current.Segment.Longitude);
                    p.Points       = new List <PointPoi>();
                    p.SegmentIdx   = current.SegmentIndex;

                    if (current.Segment.Points != null)
                    {
                        foreach (var routePoint in current.Segment.Points)
                        {
                            var poi = new PointPoi();
                            poi.Name     = routePoint.Name;
                            poi.Tags     = routePoint.Tags.ConvertTo();
                            poi.Location = new GeoCoordinate(routePoint.Latitude, routePoint.Longitude);
                            poi.Angle    = null; // there is no previous point; no angle is specified.
                            p.Points.Add(poi);
                        }
                    }

                    previousPoint = p;
                }
                else
                { // test if point is significant.
                    var nextArc = this.CreateArcAndPoint(route, previous, current, next);

                    // test if the next point is significant.
                    if (previousArc == null)
                    { // this arc is always significant; it is the first arc.
                        previousPoint.Next = nextArc;
                        previousArc        = nextArc;
                    }
                    else
                    {     // there is a previous arc; a test can be done if the current point is significant.
                        if (this.IsSignificant(previousArc, nextArc))
                        { // the arc is significant; append it to the previous arc.
                            previousArc.Next.Next = nextArc;
                            previousArc           = nextArc;
                            previousPoint         = nextArc.Next;
                        }
                        else
                        { // if the arc is not significant compared to the previous one, the previous one can extend until the next point.
                          // THIS IS THE AGGREGATION STEP!

                            // add distance.
                            var distanceToNext = previousArc.Next.Location.DistanceReal(nextArc.Next.Location);
                            previousArc.Distance = previousArc.Distance + distanceToNext;

                            // set point.
                            previousArc.Next = nextArc.Next;
                        }
                    }
                }
            }
        }
示例#17
0
 /// <summary>
 /// Generates instructions.
 /// </summary>
 /// <param name="point"></param>
 /// <param name="interpreter"></param>
 /// <param name="language_generator"></param>
 /// <returns></returns>
 public static List <Instruction> Generate(AggregatedPoint point, IRoutingInterpreter interpreter, ILanguageGenerator language_generator)
 {
     MicroPlanning.MicroPlanner planner = new MicroPlanning.MicroPlanner(language_generator, interpreter);
     return(planner.Plan(point));
 }
示例#18
0
        /// <summary>
        /// Generates an arc and it's next point from the current aggregated point.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="previous"></param>
        /// <param name="current"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        internal AggregatedArc CreateArcAndPoint(Route route, AggregatedRoutePoint previous,
                                                 AggregatedRoutePoint current, AggregatedRoutePoint next)
        {
            // create the arc.
            var a = new AggregatedArc();

            a.Name    = current.Segment.Name;
            a.Names   = current.Segment.Names.ConvertTo();
            a.Tags    = current.Segment.Tags.ConvertToTagsCollection();
            a.Vehicle = string.IsNullOrWhiteSpace(route.Vehicle) ? current.Segment.Vehicle : route.Vehicle;
            if (previous != null)
            {
                var previousCoordinate = new GeoCoordinate(previous.Segment.Latitude, previous.Segment.Longitude);
                var currentCoordinate  = new GeoCoordinate(current.Segment.Latitude, current.Segment.Longitude);

                var distance = previousCoordinate.DistanceReal(currentCoordinate);
                a.Distance = distance;
            }

            // create the point.
            var p = new AggregatedPoint();

            p.Location   = new GeoCoordinate(current.Segment.Latitude, current.Segment.Longitude);
            p.Points     = new List <PointPoi>();
            p.SegmentIdx = current.SegmentIndex;
            if (previous != null && next != null && next.Segment != null)
            {
                var previousCoordinate = new GeoCoordinate(previous.Segment.Latitude, previous.Segment.Longitude);
                var nextCoordinate     = new GeoCoordinate(next.Segment.Latitude, next.Segment.Longitude);

                p.Angle = RelativeDirectionCalculator.Calculate(previousCoordinate, p.Location, nextCoordinate);
            }
            if (current.Segment.SideStreets != null && current.Segment.SideStreets.Length > 0)
            {
                p.ArcsNotTaken = new List <KeyValuePair <RelativeDirection, AggregatedArc> >();
                foreach (var sideStreet in current.Segment.SideStreets)
                {
                    var side = new AggregatedArc();
                    side.Name  = sideStreet.Name;
                    side.Names = sideStreet.Names.ConvertTo();
                    side.Tags  = sideStreet.Tags.ConvertToTagsCollection();

                    RelativeDirection sideDirection = null;
                    if (previous != null)
                    {
                        var previousCoordinate = new GeoCoordinate(previous.Segment.Latitude, previous.Segment.Longitude);
                        var nextCoordinate     = new GeoCoordinate(sideStreet.Latitude, sideStreet.Longitude);

                        sideDirection = RelativeDirectionCalculator.Calculate(previousCoordinate, p.Location, nextCoordinate);
                    }

                    p.ArcsNotTaken.Add(new KeyValuePair <RelativeDirection, AggregatedArc>(sideDirection, side));
                }
            }
            if (current.Segment.Points != null)
            {
                foreach (var routePoint in current.Segment.Points)
                {
                    var poi = new PointPoi();
                    poi.Name     = routePoint.Name;
                    poi.Tags     = routePoint.Tags.ConvertTo();
                    poi.Location = new GeoCoordinate(routePoint.Latitude, routePoint.Longitude);

                    var previousCoordinate = new GeoCoordinate(previous.Segment.Latitude, previous.Segment.Longitude);
                    var currentCoordinate  = new GeoCoordinate(current.Segment.Latitude, current.Segment.Longitude);
                    poi.Angle = RelativeDirectionCalculator.Calculate(previousCoordinate, currentCoordinate, poi.Location);

                    p.Points.Add(poi);
                }
            }

            // link the arc to the point.
            a.Next = p;

            return(a);
        }
 /// <summary>
 /// Generates instructions.
 /// </summary>
 /// <param name="aggregatePoint"></param>
 /// <param name="interpreter"></param>
 /// <returns></returns>
 public static List <Instruction> Generate(AggregatedPoint aggregatePoint, IRoutingInterpreter interpreter)
 {
     return(InstructionGenerator.Generate(aggregatePoint, interpreter,
                                          new OsmSharp.Routing.Instructions.LanguageGeneration.Defaults.SimpleEnglishLanguageGenerator()));
 }
示例#20
0
        /// <summary>
        /// Called when this machine is succesfull.
        /// </summary>
        public override void Succes()
        {
            // get first point.
            AggregatedPoint firstPoint = null;

            if (this.FinalMessages[0] is MicroPlannerMessagePoint)
            { // machine started on a point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessagePoint).Point;
            }
            else
            { // get the previous point.
                firstPoint = (this.FinalMessages[0] as MicroPlannerMessageArc).Arc.Previous;
            }

            // get the last arc and the last point.
            var latestArc   = (this.FinalMessages[this.FinalMessages.Count - 2] as MicroPlannerMessageArc).Arc;
            var latestPoint = (this.FinalMessages[this.FinalMessages.Count - 1] as MicroPlannerMessagePoint).Point;

            // count the number of streets in the same turning direction as the turn
            // that was found.
            int count = 0;

            if (MicroPlannerHelper.IsLeft(latestPoint.Angle.Direction, this.Planner.Interpreter))
            {
                count = MicroPlannerHelper.GetLeft(this.FinalMessages, this.Planner.Interpreter);
            }
            else if (MicroPlannerHelper.IsRight(latestPoint.Angle.Direction, this.Planner.Interpreter))
            {
                count = MicroPlannerHelper.GetRight(this.FinalMessages, this.Planner.Interpreter);
            }

            // construct the box indicating the location of the resulting find by this machine.
            var point1 = latestPoint.Location;
            var box    = new GeoCoordinateBox(
                new GeoCoordinate(point1.Latitude - 0.001f, point1.Longitude - 0.001f),
                new GeoCoordinate(point1.Latitude + 0.001f, point1.Longitude + 0.001f));

            // descide what type of instruction to request be generated.
            var metaData              = new Dictionary <string, object>();
            var streetFrom            = latestArc.Tags;
            var streetTo              = latestPoint.Next.Tags;
            var streetCountTurn       = 0;
            var streetCountBeforeTurn = count;
            var direction             = latestPoint.Angle;

            metaData["count_before"] = streetCountBeforeTurn;
            metaData["direction"]    = direction;
            if (streetFrom == streetTo)
            {
                if (streetCountTurn == 0)
                {// there are no other streets between the one being turned into and the street coming from in the same
                    // direction as the turn.
                    metaData["type"] = "direct_follow_turn";
                }
                else
                { // there is another street; this is tricky to explain.
                    metaData["type"] = "indirect_follow_turn";
                }
            }
            else
            {
                if (streetCountTurn == 0)
                { // there are no other streets between the one being turned into and the street coming from in the same
                    // direction as the turn.
                    metaData["type"] = "direct_turn";
                }
                else
                { // there is another street; this is tricky to explain.
                    metaData["type"] = "indirect_turn";
                }
            }

            // let the scentence planner generate the correct information.
            metaData["street"] = streetTo;
            metaData["pois"]   = latestPoint.Points;
            this.Planner.SentencePlanner.GenerateInstruction(metaData, firstPoint.SegmentIdx, latestPoint.SegmentIdx, box, latestPoint.Points);
        }
示例#21
0
        /// <summary>
        /// Generates an arc and it's next point from the current aggregated point.
        /// </summary>
        /// <param name="previous"></param>
        /// <param name="current"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        internal AggregatedArc CreateArcAndPoint(AggregatedRoutePoint previous, AggregatedRoutePoint current, AggregatedRoutePoint next)
        {
            // create the arc.
            AggregatedArc a = new AggregatedArc();

            a.Name  = current.Entry.WayFromName;
            a.Names = current.Entry.WayFromNames.ConvertTo();
            a.Tags  = current.Entry.Tags.ConvertToTagsCollection();
            if (previous != null)
            {
                GeoCoordinate previous_coordinate =
                    new GeoCoordinate(previous.Entry.Latitude, previous.Entry.Longitude);
                GeoCoordinate current_coordinate = new GeoCoordinate(current.Entry.Latitude, current.Entry.Longitude);

                Meter distance = previous_coordinate.DistanceReal(current_coordinate);
                a.Distance = distance;
            }


            // create the point.
            AggregatedPoint p = new AggregatedPoint();

            p.Location = new GeoCoordinate(current.Entry.Latitude, current.Entry.Longitude);
            p.Points   = new List <PointPoi>();
            if (previous != null && next != null && next.Entry != null)
            {
                GeoCoordinate previous_coordinate =
                    new GeoCoordinate(previous.Entry.Latitude, previous.Entry.Longitude);
                GeoCoordinate next_coordinate =
                    new GeoCoordinate(next.Entry.Latitude, next.Entry.Longitude);

                p.Angle = RelativeDirectionCalculator.Calculate(previous_coordinate, p.Location, next_coordinate);
            }
            if (current.Entry.SideStreets != null && current.Entry.SideStreets.Length > 0)
            {
                p.ArcsNotTaken = new List <KeyValuePair <RelativeDirection, AggregatedArc> >();
                foreach (RoutePointEntrySideStreet side_street in current.Entry.SideStreets)
                {
                    AggregatedArc side = new AggregatedArc();
                    side.Name  = side_street.WayName;
                    side.Names = side_street.WayNames.ConvertTo();
                    side.Tags  = side_street.Tags.ConvertToTagsCollection();

                    RelativeDirection side_direction = null;
                    if (previous != null)
                    {
                        GeoCoordinate previous_coordinate =
                            new GeoCoordinate(previous.Entry.Latitude, previous.Entry.Longitude);
                        GeoCoordinate next_coordinate =
                            new GeoCoordinate(side_street.Latitude, side_street.Longitude);

                        side_direction = RelativeDirectionCalculator.Calculate(previous_coordinate, p.Location, next_coordinate);
                    }

                    p.ArcsNotTaken.Add(new KeyValuePair <RelativeDirection, AggregatedArc>(side_direction, side));
                }
            }
            if (current.Entry.Points != null)
            {
                foreach (RoutePoint route_point in current.Entry.Points)
                {
                    PointPoi poi = new PointPoi();
                    poi.Name     = route_point.Name;
                    poi.Tags     = route_point.Tags.ConvertTo();
                    poi.Location = new GeoCoordinate(route_point.Latitude, route_point.Longitude);

                    GeoCoordinate previous_coordinate =
                        new GeoCoordinate(previous.Entry.Latitude, previous.Entry.Longitude);
                    GeoCoordinate current_coordinate = new GeoCoordinate(current.Entry.Latitude, current.Entry.Longitude);
                    poi.Angle = RelativeDirectionCalculator.Calculate(previous_coordinate, current_coordinate, poi.Location);

                    p.Points.Add(poi);
                }
            }

            // link the arc to the point.
            a.Next = p;

            return(a);
        }
 /// <summary>
 /// Does the metric calculations.
 /// </summary>
 /// <param name="vehicle"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 public abstract Dictionary <string, double> Calculate(Vehicle vehicle, AggregatedPoint p);
示例#23
0
        /// <summary>
        /// Calculate metrics for a given turn.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="result"></param>
        /// <param name="point"></param>
        private void CalculatePointMetrics(Vehicle vehicle, Dictionary <string, double> result, AggregatedPoint point)
        {
            if (point.Angle != null)
            {
                if (AggregatedHelper.IsTurn(point.Angle.Direction))
                {
                    // no calculations for distance.

                    // update the time.
                    Second second = 0;
                    // ESTIMATE THE INCREASE IN TIME.
                    // TODO: ASSUMED DRIVING ON THE RIGHT; UPDATE TO MAKE CONFIGURABLE.
                    switch (point.Angle.Direction)
                    {
                    case OsmSharp.Math.Geo.Meta.RelativeDirectionEnum.Left:
                    case OsmSharp.Math.Geo.Meta.RelativeDirectionEnum.SharpLeft:
                    case OsmSharp.Math.Geo.Meta.RelativeDirectionEnum.SlightlyLeft:
                        second = 25;
                        break;

                    case OsmSharp.Math.Geo.Meta.RelativeDirectionEnum.Right:
                    case OsmSharp.Math.Geo.Meta.RelativeDirectionEnum.SharpRight:
                    case OsmSharp.Math.Geo.Meta.RelativeDirectionEnum.SlightlyRight:
                        second = 5;
                        break;

                    case OsmSharp.Math.Geo.Meta.RelativeDirectionEnum.TurnBack:
                        second = 30;
                        break;
                    }
                    result[TIME_KEY] = result[TIME_KEY] + second.Value;
                }
                else
                {
                    if (point.ArcsNotTaken != null && point.ArcsNotTaken.Count > 0)
                    { // very simple estimate.
                        Second second = 0;

                        second = 5;

                        result[TIME_KEY] = result[TIME_KEY] + second.Value;
                    }
                }
            }
        }