Exemple #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;
        }
Exemple #2
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;
        }
Exemple #3
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;

                    }
                }
            }
        }
        /// <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);
        }
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="point"></param>
        /// <param name="interpreter"></param>
        /// <returns></returns>
        public static List<Instruction> Generate(Route route, AggregatedPoint point, IRoutingInterpreter interpreter)
        {
			return InstructionGenerator.Generate(route, point, interpreter,
                new OsmSharp.Routing.Instructions.LanguageGeneration.Defaults.EnglishLanguageGenerator());
        }
        /// <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);
        }
 /// <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);