Exemple #1
0
 /// <summary>
 /// Resets the messages stack.
 /// </summary>
 private void ResetMessagesStack(bool reset_errors)
 {
     _invalid_machines = new List<MicroPlannerMachine>();
     _valid_machines = new List<MicroPlannerMachine>();
     _messagesStack = new List<MicroPlannerMessage>();
     _latest_final = -1;
     _latest_machine = null;
 }
Exemple #2
0
        /// <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;
        }
Exemple #3
0
        /// <summary>
        /// Reports when a machine resets (meaning it reached an invalid state).
        /// </summary>
        /// <param name="machine"></param>
        internal void ReportReset(MicroPlannerMachine machine)
        {
            // the machine cannot be used anymore until a reset occurs.
            _invalid_machines.Add(machine);

            // check if the latest machine is now successfull.
            if (_latest_machine != null)
            {
                this.CheckMachine(_latest_machine);
            }

            // check to see if not all machine are invalid!
            if (_invalid_machines.Count == _machines.Count)
            {
                if(_latest_machine == null)
                { // all machine went in error!
                    throw new MicroPlannerException("No machine could be found matching the current stack of messages!", _messagesStack);
                }
                else
                { // start all over with the current stack of messages.
                    this.Success(machine);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Reports a final state to this microplanner when some machine reaches it.
        /// </summary>
        /// <param name="machine"></param>
        /// <param name="messages"></param>
        internal void ReportFinal(MicroPlannerMachine machine, IList<MicroPlannerMessage> messages)
        {
            if (_latest_final == _messagesStack.Count - 1)
            { // check if a machine with the same match length has higher priority.
                if (_latest_machine.Priority >= machine.Priority)
                { // the current machine has the same match length and has higher or the same priority.
                    return;
                }
            }

            // update the latest final value.
            _latest_final = _messagesStack.Count - 1;
            _latest_machine = machine;

            // add the machine to the valid machines.
            _valid_machines.Add(machine);

            // check and see if all other machines with higher priority are invalid.
            this.CheckMachine(machine);
        }
Exemple #5
0
        /// <summary>
        /// Checks the machine for success.
        /// </summary>
        internal void CheckMachine(MicroPlannerMachine machine)
        {
            // check the other machines and their priorities.
            int priority = machine.Priority;
            foreach (MicroPlannerMachine other_machine in _machines)
            {
                if (!_invalid_machines.Contains(other_machine))
                {
                    if (other_machine.Priority > priority)
                    { // not sure this machine's final state is actually the final state.
                        return;
                    }
                }
            }

            // no other machines exist with higher priority.
            this.Success(machine);
        }
Exemple #6
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;
        }