/// <summary>
        /// The given machine was successfull.
        /// </summary>
        /// <param name="machine"></param>
        internal void Success(MicroPlannerMachine machine)
        {
            OsmSharp.Logging.Log.TraceEvent("MicroPlanner", TraceEventType.Information,
                                            machine.ToString());

            // reset the current point/arc.
            if (_messagesStack.Count > _latest_final + 1)
            {
                MicroPlannerMessage message = _messagesStack[_latest_final];
                if (message is MicroPlannerMessageArc)
                {
                    _current = (message as MicroPlannerMessageArc).Arc;
                }
                if (message is MicroPlannerMessagePoint)
                {
                    _current = (message as MicroPlannerMessagePoint).Point;
                }
            }

            // reset the mesages stack.
            this.ResetMessagesStack(true);

            // tell the machine again it was successfull.
            machine.Succes();

            // re-initialize the machines.
            this.InitializeMachines();

            _succes = true;
        }
        /// <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 #3
0
        /// <summary>
        /// The given machine was successfull.
        /// </summary>
        /// <param name="machine"></param>
        internal void Success(MicroPlannerMachine machine)
        {
            // reset the current point/arc.
            if (_messagesStack.Count > _latestFinal + 1)
            {
                MicroPlannerMessage message = _messagesStack[_latestFinal];
                if (message is MicroPlannerMessageArc)
                {
                    _current = (message as MicroPlannerMessageArc).Arc;
                }
                if (message is MicroPlannerMessagePoint)
                {
                    _current = (message as MicroPlannerMessagePoint).Point;
                }
            }

            // reset the mesages stack.
            this.ResetMessagesStack(true);

            // tell the machine again it was successfull.
            machine.Succes();
            machine.IsSuccesfull = true;

            // re-initialize the machines.
            _machines.Clear();
            this.InitializeMachines(_machines);

            _succes = true;
        }
Exemple #4
0
 public override void WriteToStream(IndentStream stream)
 {
     stream.Write($"{Token.ToUpper()}");
     stream.Write("(");
     Aggregated.WriteToStream(stream);
     stream.Write(" FOR ");
     Column.WriteToStream(stream);
     stream.Write(" IN (");
     PivotedColumns.WriteToStreamWithComma(stream);
     stream.Write(")");
     stream.Write(") AS ");
     AliasName.WriteToStream(stream);
 }
Exemple #5
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);
        }
        /// <summary>
        /// Creates and plans a new message.
        /// </summary>
        /// <param name="aggregated"></param>
        private void PlanNewMessage(Aggregated aggregated)
        {
            // create the message.
            MicroPlannerMessage message = null;

            if (aggregated is AggregatedPoint)
            {
                MicroPlannerMessagePoint point = new MicroPlannerMessagePoint();
                point.Point = aggregated as AggregatedPoint;

                message = point;
            }
            else if (aggregated is AggregatedArc)
            {
                MicroPlannerMessageArc arc = new MicroPlannerMessageArc();
                arc.Arc = aggregated as AggregatedArc;

                message = arc;
            }

            // plan the message.
            this.Plan(message);
        }
Exemple #7
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);
        }
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>true if the enumerator was successfully advanced to the next element; false if
        /// the enumerator has passed the end of the collection.</returns>
        /// <exception cref="InvalidOperationException">The collection was modified after the enumerator was created.</exception>
        public async Task <bool> MoveNextAsync()
        {
            Dictionary <string, List <object> > Aggregated = null;
            ObjectProperties Variables = null;
            IElement         E;

            object[] Last = null;
            int      i, c = this.groupBy.Length;
            object   o1, o2;

            while (this.processLast || await e.MoveNextAsync())
            {
                this.processLast = false;

                Variables = new ObjectProperties(e.Current, this.variables);

                if (Last is null)
                {
                    Last = new object[c];

                    for (i = 0; i < c; i++)
                    {
                        E       = this.groupBy[i].Evaluate(Variables);
                        Last[i] = E.AssociatedObjectValue;
                    }
                }
                else
                {
                    for (i = 0; i < c; i++)
                    {
                        E = this.groupBy[i].Evaluate(Variables);

                        o1 = Last[i];
                        o2 = E.AssociatedObjectValue;

                        if (o1 is null ^ o2 is null)
                        {
                            break;
                        }

                        if (o1 != null && !o1.Equals(o2))
                        {
                            break;
                        }
                    }

                    if (i < c)
                    {
                        this.processLast = true;
                        break;
                    }
                }

                o1 = e.Current;

                Type T = o1.GetType();
                if (T != this.lastType)
                {
                    this.lastType   = T;
                    this.properties = T.GetRuntimeProperties();
                    this.fields     = T.GetRuntimeFields();
                }

                if (Aggregated is null)
                {
                    Aggregated = new Dictionary <string, List <object> >();
                }

                foreach (PropertyInfo PI in this.properties)
                {
                    if (!PI.CanRead || !PI.CanWrite)
                    {
                        continue;
                    }

                    if (!Aggregated.TryGetValue(PI.Name, out List <object> List))
                    {
                        List = new List <object>();
                        Aggregated[PI.Name] = List;
                    }

                    List.Add(PI.GetValue(o1));
                }

                foreach (FieldInfo FI in this.fields)
                {
                    if (!Aggregated.TryGetValue(FI.Name, out List <object> List))
                    {
                        List = new List <object>();
                        Aggregated[FI.Name] = List;
                    }

                    List.Add(FI.GetValue(o1));
                }
            }

            if (Aggregated is null)
            {
                return(false);
            }

            Dictionary <string, object> Result = new Dictionary <string, object>();
            bool First = true;

            foreach (KeyValuePair <string, List <object> > Rec in Aggregated)
            {
                object[] A = Rec.Value.ToArray();
                Result[Rec.Key] = A;

                if (First)
                {
                    First             = false;
                    Result[" First "] = A;
                }
            }

            if (this.groupNames != null)
            {
                for (i = 0; i < c; i++)
                {
                    ScriptNode Node = this.groupNames[i];
                    if (Node is null)
                    {
                        continue;
                    }

                    if (Node is VariableReference Ref)
                    {
                        Result[Ref.VariableName] = Last[i];
                    }
                    else
                    {
                        E = this.groupNames[i]?.Evaluate(Variables);
                        if (E != null && E is StringValue S)
                        {
                            Result[S.Value] = Last[i];
                        }
                    }
                }
            }

            this.current = Result;

            return(true);
        }