예제 #1
0
        public void sendActionDoneMessage(ActionNode action, ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the action finished
            TimeExpression timestamp = action.CurrentExecution.Finish;

            procMsg.Timestamp = timestamp;

            //set ACLMessage content
            string content = "((done (action ";

            content        += agt.name;
            content        += " ";
            content        += "(" + clean(action.name) + ")";
            content        += ")))";
            procMsg.Content = content;
            //MascaretApplication.Instance.VRComponentFactory.Log(content);

            //send message to other agents
            List <AID> agents = procInfo.getOtherAgents();

            for (int iA = 0; iA < agents.Count; iA++)
            {
                procMsg.Receivers.Add(agents[iA]);
            }
            agt.send(procMsg);
        }
예제 #2
0
        public void pushProcedureToDo(Procedure proc, OrganisationalEntity org, Role role, Dictionary <String, ValueSpecification> parameters)
        {
            Agent agt = (Agent)(this.Host);

            ProcedureExecution procInfo = new ProcedureExecution(proc, org, agt);

            procInfo.buildAffectations(parameters, this.Host);

            /* Search if the current agent have something to do in this procedure */
            List <ActivityPartition> parts = proc.Activity.Partitions;
            bool found = false;

            for (int iP = 0; iP < parts.Count; iP++)
            {
                if (parts[iP].name == role.name)
                {
                    //   file.WriteLine("[ProceduralBehavior Info] Found a role " + role.name + " in procedure " + proc.name); file.Flush();
                    found = true;
                }
            }

            runningProcedures.Add(procInfo);
            ispause = false;

            if (!found)
            {
                //inform all agents that this agent's role in this procedure has ended (used to unblock tokens in ProcedureExecution)
                sendProcedureDoneMessage(procInfo);
                runningProcedures.RemoveAt(runningProcedures.Count - 1); //remove it..
                // ispause = true;
            }
        }
예제 #3
0
        public void sendActionRealisationMessage(ActionNode action, ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the action start
            TimeExpression timestamp = action.CurrentExecution.Start;

            procMsg.Timestamp = timestamp;

            //set ACLMessage content
            string content = "((action ";

            content        += agt.name;
            content        += " ";
            content        += "(" + clean(action.name) + ")";
            content        += "))";
            procMsg.Content = content;

            //send message to other agents
            List <AID> agents = procInfo.getOtherAgents();

            for (int iA = 0; iA < agents.Count; iA++)
            {
                procMsg.Receivers.Add(agents[iA]);
            }
            agt.send(procMsg);
        }
예제 #4
0
        public void onActionRunning(AID agent, string actionName)
        {
            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];

                procInfo.informActionRunning(agent, actionName);
            }
        }
예제 #5
0
 public void stopAll()
 {
     for (int iP = 0; iP < runningProcedures.Count; iP++)
     {
         ProcedureExecution procInfo = runningProcedures[iP];
         procInfo.stop();
     }
     runningProcedures.Clear();
 }
예제 #6
0
        public void onActionDone(AID agent, ActionNode action)
        {
            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];

                procInfo.informActionDone(agent, action);
            }
            ispause = false;
        }
예제 #7
0
        public void onBehaviorStop(BehaviorExecution be)
        {
            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];
                procInfo.informActionDone(((Agent)(this.Host)).Aid, behaviorToNode[be]);
                sendActionDoneMessage(behaviorToNode[be], procInfo);
            }

            //restart();
            ispause = false;
        }
예제 #8
0
        public void sendProcedureDoneMessage(ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the procedure finish
            TimeExpression timestamp = BehaviorScheduler.Instance.getCurrentVirtualTime();

            procMsg.Timestamp = timestamp;

            string content = "((done (action ";

            content        += agt.name;
            content        += " ";
            content        += "(" + clean(procInfo.procedure.name) + ")";
            content        += ")))";
            procMsg.Content = content;

            procMsg.Receivers.Add(MascaretApplication.Instance.Agent.Aid);

            agt.send(procMsg);
        }
예제 #9
0
        public void stop(Procedure procedure)
        {
            List <ProcedureExecution> exec = new List <ProcedureExecution>(); // Procedure still running

            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];
                if (procInfo.procedure == procedure)
                {
                    procInfo.stop();
                }
                else
                {
                    exec.Add(procInfo);
                }
            }

            // We put back still running procedure in the vector
            runningProcedures.Clear();
            for (int iP = 0; iP < exec.Count; iP++)
            {
                runningProcedures.Add(exec[iP]);
            }
        }
예제 #10
0
        public void sendProcedureDoneMessage(ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the procedure finish
            TimeExpression timestamp = BehaviorScheduler.Instance.getCurrentVirtualTime();
            procMsg.Timestamp = timestamp;

            string content = "((done (action ";
            content += agt.name;
            content += " ";
            content += "(" + clean(procInfo.procedure.name) + ")";
            content += ")))";
            procMsg.Content = content;

            procMsg.Receivers.Add(MascaretApplication.Instance.Agent.Aid);

            agt.send(procMsg);
        }
예제 #11
0
        public void sendActionRealisationMessage(ActionNode action, ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the action start
            TimeExpression timestamp = action.CurrentExecution.Start;

            procMsg.Timestamp = timestamp;

            //set ACLMessage content
            string content = "((action ";
            content += agt.name;
            content += " ";
            content += "(" + clean(action.name) + ")";
            content += "))";
            procMsg.Content = content;

            //send message to other agents
            List<AID> agents = procInfo.getOtherAgents();

            for (int iA = 0; iA < agents.Count; iA++)
            {
                procMsg.Receivers.Add(agents[iA]);
            }
            agt.send(procMsg);
        }
예제 #12
0
        public void sendActionDoneMessage(ActionNode action, ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the action finished
            TimeExpression timestamp = action.CurrentExecution.Finish;

            procMsg.Timestamp = timestamp;

            //set ACLMessage content
            string content = "((done (action ";
            content += agt.name;
            content += " ";
            content += "(" + clean(action.name) + ")";
            content += ")))";
            procMsg.Content = content;
            //MascaretApplication.Instance.VRComponentFactory.Log(content);

            //send message to other agents
            List<AID> agents = procInfo.getOtherAgents();

            for (int iA = 0; iA < agents.Count; iA++)
            {
                procMsg.Receivers.Add(agents[iA]);
            }
            agt.send(procMsg);
        }
예제 #13
0
        public void pushProcedureToDo(Procedure proc, OrganisationalEntity org, Role role, Dictionary<String, ValueSpecification> parameters)
        {
            Agent agt = (Agent)(this.Host);

            ProcedureExecution procInfo = new ProcedureExecution(proc, org, agt);
            procInfo.buildAffectations(parameters, this.Host);

            /* Search if the current agent have something to do in this procedure */
            List<ActivityPartition> parts = proc.Activity.Partitions;
            bool found = false;
            for (int iP = 0; iP < parts.Count; iP++)
            {
                if (parts[iP].name == role.name)
                {
                    //   file.WriteLine("[ProceduralBehavior Info] Found a role " + role.name + " in procedure " + proc.name); file.Flush();
                    found = true;
                }
            }

            runningProcedures.Add(procInfo);
            ispause = false;

            if (!found)
            {
                //inform all agents that this agent's role in this procedure has ended (used to unblock tokens in ProcedureExecution)
                sendProcedureDoneMessage(procInfo);
                runningProcedures.RemoveAt(runningProcedures.Count - 1); //remove it..
                // ispause = true;
            }
        }
예제 #14
0
        public override void action()
        {
            Agent agt = (Agent)(this.Host);

            if (ispause)
            {
                return;
            }
            // StreamWriter file = MascaretApplication.Instance.logfile;
            //file.WriteLine("NB PRocs : " + runningProcedures.Count); file.Flush();

            if (runningProcedures.Count > 0)
            {
                for (int iP = 0; iP < runningProcedures.Count; iP++)
                {
                    // file.WriteLine("ProceduralBehavior in procedure " + runningProcedures[iP].procedure.name); file.Flush();
                    ProcedureExecution procInfo    = runningProcedures[iP];
                    List <ActionNode>  actionNodes = new List <ActionNode>();

                    //remove those which are not agreed upon

                    /*if (agt.ControlledByHuman)
                     * {
                     *   MascaretApplication.Instance.VRComponentFactory.Log("[ProceduralBehavior Info] Agent controlled ... ");
                     *   actionNodes = procInfo.getActionToExecute();
                     *   for (int atd = 0; atd < actionNodes.Count; ++atd)
                     *     MascaretApplication.Instance.VRComponentFactory.Log("ProceduralBehavior Info] -- Human has to do : " + actionNodes[atd].name);
                     *   actionNodes.Clear();
                     *
                     *   for (int atd = 0; atd < actionsToDo.Count; ++atd)
                     *   {
                     *       actionNodes.Add(actionsToDo[atd]);
                     *   }
                     *   actionsToDo.Clear();
                     * }
                     * else*/
                    {
                        actionNodes = procInfo.getActionToExecute();
                    }
                    if (actionNodes.Count > 0)
                    {
                        for (int i = 0; i < actionNodes.Count; i++)
                        {
                            //Dictionary<string, InstanceSpecification> affectations = procInfo.getAffectations();
                            //actionNodes[i].procInfo.procedure.Activity.Context
                            bool isCallBehavior = false;
                            if (actionNodes[i].Action.Kind == "CallBehavior")
                            {
                                isCallBehavior = true;
                            }
                            if (!agt.ControlledByHuman)
                            {
                                actionNodes[i].start(agt, procInfo.getAffectations(), false); //TODO ///////////////////////////////////////// if not flag start, else start
                                sendActionRealisationMessage(actionNodes[i], procInfo);       // TODO
                                procInfo.informActionRunning(agt.Aid, actionNodes[i]);

                                if (actionNodes[i].CurrentExecution != null)
                                {
                                    behaviorToNode.Add(actionNodes[i].CurrentExecution, actionNodes[i]);
                                    actionNodes[i].CurrentExecution.addCallbackOnBehaviorStop(onBehaviorStop);
                                }
                                else
                                {
                                    procInfo.informActionDone(agt.Aid, actionNodes[i]); //TODO
                                    sendActionDoneMessage(actionNodes[i], procInfo);
                                }
                            }
                            else
                            {
                                if (isCallBehavior)
                                {
                                    actionNodes[i].start(agt, procInfo.getAffectations(), false); //TODO ///////////////////////////////////////// if not flag start, else start
                                    sendActionRealisationMessage(actionNodes[i], procInfo);       // TODO
                                    procInfo.informActionRunning(agt.Aid, actionNodes[i]);

                                    if (actionNodes[i].CurrentExecution != null)
                                    {
                                        behaviorToNode.Add(actionNodes[i].CurrentExecution, actionNodes[i]);
                                        actionNodes[i].CurrentExecution.addCallbackOnBehaviorStop(onBehaviorStop);
                                    }
                                    else
                                    {
                                        procInfo.informActionDone(agt.Aid, actionNodes[i]); //TODO
                                        sendActionDoneMessage(actionNodes[i], procInfo);
                                    }
                                }
                                else
                                {
                                    actionsToDo.Add(actionNodes[i]);
                                    MascaretApplication.Instance.VRComponentFactory.Log("ProceduralBehavior Info] -- Human has to do : " + actionNodes[i].name);
                                }
                            }
                        }
                    }
                    else if (agt.getMessageQueue().Count == 0)
                    {
                        //pause();
                        //ispause = true;
                    }

                    if (procInfo.isFinished())
                    {
                        //file.WriteLine("ProceduralBehavior Procedure : " + runningProcedures[iP].procedure.name + " finie "); file.Flush();
                        //inform all agents that this agent's role in this procedure has ended (used to unblock tokens in ProcedureExecution)
                        sendProcedureDoneMessage(procInfo);

                        runningProcedures[iP] = runningProcedures[runningProcedures.Count - 1];
                        runningProcedures.RemoveAt(runningProcedures.Count - 1);
                        //cerr << getHost()->getName()<<" : suppression de la procedure"<< endl;
                    }
                    else
                    {
                        iP++;
                    }
                }
            }
            else
            {
                ispause = true;
            }
        }