/// <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> /// 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; }
/// <summary> /// Creates and plans a new message. /// </summary> /// <param name="aggregated"></param> private void PlanNewMessage(Route route, Aggregated aggregated) { // create the message. MicroPlannerMessage message = null; if (aggregated is AggregatedPoint) { var point = new MicroPlannerMessagePoint(route); point.Point = aggregated as AggregatedPoint; message = point; } else if (aggregated is AggregatedArc) { var arc = new MicroPlannerMessageArc(route); arc.Arc = aggregated as AggregatedArc; message = arc; } // plan the message. this.Plan(message); }