Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
0
        public override void action()
        {
            Agent      agt = (Agent)(this.Host);
            ACLMessage msg = agt.receive();

            if (msg != null)
            {
                MascaretApplication.Instance.VRComponentFactory.Log("Communication Behavior");
                MascaretApplication.Instance.VRComponentFactory.Log("Conversation-ID: " + msg.ConversationID);

                /*if (msg.Performative == ACLPerformative.REQUEST)
                 * {
                 *  manageRequest(msg);
                 * }
                 * else */
                if (msg.Performative == ACLPerformative.INFORM)
                {
                    manageInform(msg);
                }
                else if (msg.Performative == ACLPerformative.QUERY_REF)
                {
                    manageQueryRef(msg);
                }
            }
        }
Exemple #4
0
 public void stopAllProcedures()
 {
     foreach (RoleAssignement currentRA in roleAssignement)
     {
         ACLMessage message = new ACLMessage(ACLPerformative.REQUEST);
         message.Content = "STOP ALL";
         message.Receivers.Add(currentRA.Agent);
         MascaretApplication.Instance.AgentPlateform.sendMessage(message);
     }
 }
 public void stopAllProcedures()
 {
     foreach (RoleAssignement currentRA in roleAssignement)
     {
         ACLMessage message = new ACLMessage(ACLPerformative.REQUEST);
         message.Content = "STOP ALL";
         message.Receivers.Add(currentRA.Agent);
         MascaretApplication.Instance.AgentPlateform.sendMessage(message);
     }
 }
        protected void manageInform(ACLMessage msg)
        {
            Agent              agt     = (Agent)(this.Host);
            string             content = msg.Content;
            FIPASLParserResult result  = parseFipaSLExpression(content);

            if (result.isAction)
            {
                if (result.success)
                {
                    AgentBehaviorExecution be = agt.getBehaviorExecutingByName("ProceduralBehavior");
                    if (be != null)
                    {
                        ProceduralBehavior pbe = (ProceduralBehavior)(be);
                        AID aid = new AID(result.action.performer, agt.Aid.PlateformName, agt.Aid.PlateformPort);
                        if (result.isDone)
                        {
                            aid = new AID(result.action.performer, agt.Aid.PlateformName, agt.Aid.PlateformPort);
                            pbe.onActionDone(aid, result.action.actionName);
                        }
                        else
                        {
                            pbe.onActionRunning(aid, result.action.actionName);
                        }
                    }
                }
            }
            else if (result.isEqual)
            {
                string entityName = result.iota.paramName[2];
                string slotName   = result.iota.paramName[0];
                string value      = result.iota.value;

                MascaretApplication.Instance.VRComponentFactory.Log(entityName + "." + slotName + "=" + value);

                KnowledgeBase        kb       = ((Agent)(this.Host)).KnowledgeBase;
                Mascaret.Environment envKB    = kb.Environment;
                List <Entity>        entities = envKB.getEntities();
                foreach (Entity entity in entities)
                {
                    if (entity.name == entityName)
                    {
                        MascaretApplication.Instance.VRComponentFactory.Log("ENTITY ...");
                        foreach (KeyValuePair <string, Slot> s in entity.Slots)
                        {
                            if (s.Value.name == slotName)
                            {
                                s.Value.addValueFromString(value);
                            }
                        }
                    }
                }
            }
        }
        protected void manageInform(ACLMessage msg)
        {
            Agent agt = (Agent)(this.Host);
            string content = msg.Content;
            FIPASLParserResult result = parseFipaSLExpression(content);
            if (result.isAction)
            {
                if (result.success)
                {
                    AgentBehaviorExecution be = agt.getBehaviorExecutingByName("ProceduralBehavior");
                    if (be != null)
                    {
                        ProceduralBehavior pbe = (ProceduralBehavior)(be);
                        AID aid = new AID(result.action.performer, agt.Aid.PlateformName, agt.Aid.PlateformPort);
                        if (result.isDone)
                        {
                            aid = new AID(result.action.performer, agt.Aid.PlateformName, agt.Aid.PlateformPort);
                            pbe.onActionDone(aid, result.action.actionName);
                        }
                        else
                        {
                            pbe.onActionRunning(aid, result.action.actionName);
                        }
                    }
                }
            }
            else if (result.isEqual)
            {
                string entityName = result.iota.paramName[2];
                string slotName = result.iota.paramName[0];
                string value = result.iota.value;

                MascaretApplication.Instance.VRComponentFactory.Log(entityName + "." + slotName + "=" + value);

                KnowledgeBase kb = ((Agent)(this.Host)).KnowledgeBase;
                Mascaret.Environment envKB = kb.Environment;
                List<Entity> entities = envKB.getEntities();
                foreach (Entity entity in entities)
                {
                    if (entity.name == entityName)
                    {
                        MascaretApplication.Instance.VRComponentFactory.Log("ENTITY ...");
                        foreach (KeyValuePair<string, Slot> s in entity.Slots)
                        {
                            if (s.Value.name == slotName)
                            {
                                s.Value.addValueFromString(value);
                            }
                        }
                    }
                }
            }
        }
Exemple #8
0
        public ACLMessage check()
        {
            ACLMessage msg = null;

            if (messagesQueue.Count != 0)
            {
                msg = messagesQueue[0];
                messagesQueue.RemoveRange(0, 1);
                messagesChecked.Add(msg);
            }

            return(msg);
        }
        protected void manageRequest(ACLMessage msg)
        {
            Agent agt = (Agent)(this.Host);

            string content = msg.Content;

            System.Console.WriteLine(content);

            if (content == "Model")
            {
                sendModel(msg);
            }
            else if (content == "Organisation")
            {
                sendOrganisation(msg);
            }
            else if (content == "Actions")
            {
                sendActions(msg);
            }
            else if (content == "Entities")
            {
                sendEntities(msg);                          // Renvoi les attributs et etats de chaque entités appartenant  a la procedure et abonne aux messages de modifications d'attributs
            }
            else
            {
                string[] words = content.Split(' ');
                if (words[0] == "STOP")
                {
                    //string procName = words[1];
                    //ProceduralBehavior be=(ProceduralBehavior)(agt.getBehaviorExecutingByName("ProceduralBehavior"));

                    /*if (procName =="ALL")
                     *                      if (be) be.stopstopAll();
                     *              else
                     *                      if (be) be.stop(procName);
                     */
                }
                else
                {
                    manageRequestAction(msg);
                }
            }
        }
Exemple #10
0
        protected void manageQueryRef(ACLMessage msg)
        {
            string content = msg.Content;

            FIPASLParserResult result = parseFipaSLExpression(content);

            Dictionary <string, Agent> agents = VRApplication.Instance.AgentPlateform.Agents;

            if (result.isIota)
            {
                FIPAIota iota = result.iota;
                if (iota.predicate == "slot")
                {
                    string fml;
                    string res = getSlot(iota.paramName);
                    MascaretApplication.Instance.VRComponentFactory.Log("IOTA : " + iota.predicate + " " + iota.result + " == " + res);
                    if (res != "")
                    {
                        // give the intention
                        ACLMessage aclMsg = new ACLMessage(ACLPerformative.INFORM);
                        aclMsg.Sender = ((Agent)Host).Aid;
                        aclMsg.Receivers.Add(msg.Sender);
                        aclMsg.Content        = "((= (iota ?" + iota.paramName[0] + " (" + iota.predicate + " ?" + iota.paramName[1] + " ?" + iota.paramName[2] + ")) " + res + "))";
                        aclMsg.ConversationID = msg.ConversationID;
                        ((Agent)Host).send(aclMsg);
                        MascaretApplication.Instance.VRComponentFactory.Log("Inform message: " + aclMsg.Content);
                        //bilal 19-10-15
                        fml = "<FML><Performative>Inform</Performative><Receivers><Receiver>" + msg.Sender + "</Receiver></Receivers><Content>" + /* "the " + iota.paramName[1] + " of " + iota.paramName[2] + "is" +*/ res + "</Content><Emotion>Neutral</Emotion><Ressources><Ressource>" + "" + "</Ressource></Ressources></FML>";
                    }
                    //bilal 19-10-15
                    else
                    {
                        fml = "<FML><Performative>Inform</Performative><Receivers><Receiver>" + msg.Sender + "</Receiver></Receivers><Content>" + "I don't know" + /*" the value of the " + iota.paramName[1] + " of " + iota.paramName[2] +*/ "</Content><Emotion>Neutral</Emotion><Ressources><Ressource>" + "" + "</Ressource></Ressources></FML>";
                    }
                    if (fml != null)
                    {
                        ((EmbodiedAgent)(Host)).addIntention(fml);
                    }
                    //bilal 19-10-15
                }
            }
        }
Exemple #11
0
        //non implémentée pour le moment
        public void sendMessage(ACLMessage message)
        {
            List <AID> receivers = message.Receivers;

            for (int i = 0; i < receivers.Count; i++)
            {
                if (receivers[i].PlateformName == "localhost")
                {
                    receivers[i].PlateformName = this.name;
                }
                if (isLocalAgent(receivers[i]))
                {
                    if (this.Agents.ContainsKey(receivers[i].toString()))
                    {
                        Agent receiver = this.Agents[receivers[i].toString()];
                        receiver.postMessage(message);
                        receiver.wakeup();
                    }
                }
            }
        }
        public override void action()
        {
            Agent      agt = (Agent)(this.Host);
            ACLMessage msg = agt.receive();

            if (msg != null)
            {
                if (msg.Performative == ACLPerformative.REQUEST)
                {
                    manageRequest(msg);
                }
                else if (msg.Performative == ACLPerformative.INFORM)
                {
                    manageInform(msg);
                }
                else if (msg.Performative == ACLPerformative.QUERY_REF)
                {
                    manageQueryRef(msg);
                }
            }
        }
Exemple #13
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);
        }
Exemple #14
0
 public void postMessage(ACLMessage message)
 {
     messagesQueue.Add(message);
 }
Exemple #15
0
 public void postMessage(ACLMessage message)
 {
     this.mailbox.postMessage(message);
 }
        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);
        }
        protected void manageInform(ACLMessage msg)
        {
            Agent agt = (Agent)(this.Host);
            string content = msg.Content;
            FIPASLParserResult result = parseFipaSLExpression(content);
            if (result.isAction)
            {
            if (result.success)
            {

                AgentBehaviorExecution be = agt.getBehaviorExecutingByName("ProceduralBehavior");
                if (be != null)
                {
                    ProceduralBehavior pbe = (ProceduralBehavior)(be);
                    AID aid = new AID(result.action.performer, agt.Aid.PlateformName, agt.Aid.PlateformPort);
                    if (result.isDone)
                    {

                        aid = new AID(result.action.performer, agt.Aid.PlateformName, agt.Aid.PlateformPort);
                        pbe.onActionDone(aid, result.action.actionName);
                    }
                    else
                    {

                        pbe.onActionRunning(aid, result.action.actionName);
                    }
                }
            }
            }
            else
            {
            /*
            //cerr << result.variable << " of entity : " << result.entity << " == " << result.value << endl;
            Agent agt = (Agent)(Host);
            KnowledgeBase kb = agt.KnowledgeBase;
            Environment env = kb.Environment;
            if (env != null)
            {
                InstanceSpecification entity;
                entity = env.getInstance(result.entity);
                if (entity)
                {
                    shared_ptr<Slot> variable;
                    variable = entity->getProperty(result.variable);
                    if (variable)
                    {
                        variable->addValueFromString(result.value);
                    }
                    else
                    {
                        shared_ptr<ACLMessage> reponse = shared_ptr<ACLMessage>(new ACLMessage(NOT_UNDERSTOOD));
                        reponse->setContent(content);
                        reponse->addReceiver(msg->getSender());
                        agt->send(reponse);
                    }
                }
                else
                {
                    shared_ptr<ACLMessage> reponse = shared_ptr<ACLMessage>(new ACLMessage(NOT_UNDERSTOOD));
                    reponse->setContent(content);
                    reponse->addReceiver(msg->getSender());
                    agt->send(reponse);
                }
            }
            else
            {
                shared_ptr<ACLMessage> reponse = shared_ptr<ACLMessage>(new ACLMessage(NOT_UNDERSTOOD));
                reponse->setContent(content);
                reponse->addReceiver(msg->getSender());
                agt->send(reponse);
            }*/
            }
            /*
            if (msg->getXMLContent())
            {
            shared_ptr<XmlParser> newParser = shared_ptr<XmlParser>(new XmlParser());
            newParser->createFile("parser");
            shared_ptr<XmlNode> newRoot_node = newParser->getRoot();
            newRoot_node->addChild(msg->getXMLContent(), false);
            cerr << newParser->writeString() << endl;
            }*/
        }
 protected void sendModel(ACLMessage msg)
 {
 }
 protected void sendOrganisation(ACLMessage msg)
 {
 }
 protected void sendModel(ACLMessage msg)
 {
 }
        protected void manageQueryRef(ACLMessage msg)
        {
            /*
             * Dictionary<string, Agent> agents = VRApplication.Instance.AgentPlateform.Agents;
             *
             * string agentName = msg.Sender.toString();
             * //MascaretApplication.Instance.VRComponentFactory.Log("Sender : " + agentName + " - Host: "+this.Host.name);
             * if (agents.ContainsKey(agentName))
             * {
             *  Mascaret.Agent agt = agents[agentName];
             *
             *  ProceduralBehavior pbehavior = (ProceduralBehavior)(agt.getBehaviorExecutingByName("ProceduralBehavior"));
             *  List<ProcedureExecution> procedures = pbehavior.runningProcedures;
             *  //MascaretApplication.Instance.VRComponentFactory.Log("M-Procedures : " + procedures.Count);
             *  foreach (ProcedureExecution proc in procedures)
             *      MascaretApplication.Instance.VRComponentFactory.Log(proc.procedure.getFullName());
             *
             *  List<KeyValuePair<ProcedureExecution, ActionNode>> actionNodes = pbehavior.actionsToDo;
             *  //MascaretApplication.Instance.VRComponentFactory.Log("M-Action Nodes Count: " + actionNodes.Count);
             *
             *  for (int atd = 0; atd < actionNodes.Count; ++atd)
             *  {
             *      if (actionNodes[atd].Value.Action.GetType().ToString() == "Mascaret.CallOperationAction")
             *      {
             *          //MascaretApplication.Instance.VRComponentFactory.Log("Action Node Description: "+actionNodes[atd].Value.Description);
             *          string fml=null;
             *          if (msg.Content == "action")
             *          {
             *              fml = "<FML><Performative>Inform</Performative><Receivers><Receiver>" + agentName + "</Receiver></Receivers><Content>" + actionNodes[atd].Value.Description + "</Content><Emotion>Neutral</Emotion><Ressources><Ressource>" + "" + "</Ressource></Ressources></FML>";
             *          }
             *          else if (msg.Content == "object")
             *          {
             *              CallOperationAction coa = (CallOperationAction)(actionNodes[atd].Value.Action);
             *              List<InputPin> pins = coa.InputPins;
             *              if (pins.Count >= 1)
             *              {
             *                  InputPin ip = pins[0];
             *                  List<ObjectNode> nObjNode = ip.getIncomingObjectNode();
             *
             *                  if (nObjNode.Count >= 1)
             *                  {
             *                      ObjectNode on = nObjNode[0];
             *                      foreach (ProcedureExecution pe in procedures)
             *                      {
             *                          Dictionary<string, InstanceSpecification> affect = pe.getAffectations();
             *                          if (affect.ContainsKey(on.name))
             *                          {
             *                              InstanceSpecification instance = affect[on.name];
             *                              fml = "<FML><Performative>Point</Performative><Receivers><Receiver>" + agentName + "</Receiver></Receivers><Content>" + "" + "</Content><Emotion>Neutral</Emotion><Ressources><Ressource>" + instance.name + "</Ressource></Ressources></FML>";
             *                          }
             *                      }
             *                  }
             *              }
             *          }
             *
             *          if(fml != null) ((EmbodiedAgent)(Host)).addIntention(fml);
             *      }
             *  }
             * }*/

            //////////////////////////////////////////////////bilal Sep2015////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            string content = msg.Content;

            FIPASLParserResult result = parseFipaSLExpression(content);

            Dictionary <string, Agent> agents = VRApplication.Instance.AgentPlateform.Agents;

            if (result.isIota)
            {
                FIPAIota iota = result.iota;
                if (iota.predicate == "slot")
                {
                    string res = getSlot(iota.paramName);
                    MascaretApplication.Instance.VRComponentFactory.Log("IOTA : " + iota.predicate + " " + iota.result + " == " + res);
                    if (res != "")
                    {
                        // give the intention
                        ACLMessage aclMsg = new ACLMessage(ACLPerformative.INFORM);
                        aclMsg.Sender = ((Agent)Host).Aid;
                        aclMsg.Receivers.Add(msg.Sender);
                        aclMsg.Content = "((= (iota ?" + iota.paramName[0] + " (" + iota.predicate + " ?" + iota.paramName[1] + " ?" + iota.paramName[2] + ")) " + res + "))";
                        ((Agent)Host).send(aclMsg);
                        MascaretApplication.Instance.VRComponentFactory.Log("Inform message: " + aclMsg.Content);
                    }
                }
            }


            /*string agentName = msg.Sender.toString();
             * MascaretApplication.Instance.VRComponentFactory.Log("Sender : " + agentName + " - Host: "+this.Host.name);
             * if (agents.ContainsKey(agentName))
             * {
             *  Mascaret.Agent agt = agents[agentName];
             *  KnowledgeBase kb = agt.KnowledgeBase;
             *  Mascaret.Environment envKB = kb.Environment;
             *  List<Entity> entitiesKB = envKB.getEntities();
             *  foreach (Entity entity in entitiesKB)
             *  {
             *      MascaretApplication.Instance.VRComponentFactory.Log(entity.getFullName());
             *      if (entity.Slots.Count > 0)
             *      {
             *          foreach (KeyValuePair<string, Slot> s in entity.Slots)
             *          {
             *              if (s.Value.getValue() != null)
             *                  MascaretApplication.Instance.VRComponentFactory.Log(s.Key + " = " + s.Value.getValue().getStringFromValue());
             *          }
             *      }
             *  }
             *
             * }*/
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        }
Exemple #22
0
        public override void manageRequest(HttpRequest req)
        {
            string procName = req.parameters["alias"];
            string orgName  = req.parameters["org"];

            req.response.write("<html>");
            req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            req.response.write("<body>");

            OrganisationalEntity        org  = null;
            List <OrganisationalEntity> orgs = MascaretApplication.Instance.AgentPlateform.Organisations;
            bool found = false;
            int  i     = 0;

            while (!found && i < orgs.Count)
            {
                if (orgs[i].name == orgName)
                {
                    found = true;
                }
                else
                {
                    i++;
                }
            }
            if (found)
            {
                org = orgs[i];
            }

            OrganisationalStructure struc = org.Structure;

            List <Procedure> procs = struc.Procedures;
            Procedure        proc  = null;

            found = false;
            i     = 0;
            while (!found && i < procs.Count)
            {
                if (procs[i].name == procName)
                {
                    found = true;
                }
                else
                {
                    i++;
                }
            }
            if (found)
            {
                proc = procs[i];
            }

            Environment env = MascaretApplication.Instance.getEnvironment();

            List <Parameter>    parameters = new List <Parameter>();
            List <ActivityNode> nodes      = proc.Activity.Nodes;

            for (int iNode = 0; iNode < nodes.Count; iNode++)
            {
                if (nodes[iNode].Kind == "parameter")
                {
                    parameters.Add(((ActivityParameterNode)(nodes[iNode])).Parameter);
                }
            }

            string paramString = "";
            Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();

            for (int iParam = 0; iParam < parameters.Count; iParam++)
            {
                string strVal = req.parameters[parameters[iParam].name];
                strVal.Replace("+", " ");

                //Debug.Log (strVal);
                param.Add(parameters[iParam].name, parameters[iParam].Type.createValueFromString(strVal));
                paramString += " :" + parameters[iParam].name + " " + strVal;
            }

            List <RoleAssignement> assignements = org.RoleAssignement;

            for (int iA = 0; iA < assignements.Count; iA++)
            {
                ACLMessage procMsg = new ACLMessage(ACLPerformative.REQUEST);
                procMsg.Receivers.Add(assignements[iA].Agent);

                AID agentAID = MascaretApplication.Instance.Agent.Aid;
                procMsg.Sender = agentAID;
                string content = "((action ";
                content        += assignements[iA].Agent.name;
                content        += " ";
                content        += "(" + proc.name;
                content        += paramString;
                content        += ")))";
                procMsg.Content = content;
                MascaretApplication.Instance.AgentPlateform.sendMessage(procMsg);

                if (agentAID.name == assignements[iA].Agent.name)
                {
                    req.response.write("<H2>Vous jouez le role ");
                    req.response.write(assignements[iA].Role.name);
                    req.response.write("</H2>");
                    req.response.write("<H3>Vous pouvez faire les actions suivantes : </H3>");

                    req.response.write("<ul>");
                    Activity act = proc.Activity;
                    List <ActivityPartition> partitions = act.Partitions;
                    for (int iPart = 0; iPart < partitions.Count; iPart++)
                    {
                        if (partitions[iPart].name == assignements[iA].Role.name)
                        {
                            nodes = partitions[iPart].Node;
                            for (int iNode = 0; iNode < nodes.Count; iNode++)
                            {
                                if (nodes[iNode].Kind == "action")
                                {
                                    req.response.write("<li>");
                                    req.response.write("<a href=\"Actions?alias=");
                                    req.response.write(nodes[iNode].name);
                                    req.response.write("&org=");
                                    req.response.write(org.name);
                                    req.response.write("&role=");
                                    req.response.write(assignements[iA].Role.name);
                                    req.response.write("&proc=");
                                    req.response.write(proc.name);
                                    req.response.write("\" target = \"Body\">");
                                    req.response.write(nodes[iNode].name);
                                    req.response.write("</a></li>");
                                }
                            }
                        }
                    }
                    req.response.write("</ul>");
                }
            }

            req.response.write("</body>");
            req.response.write("</html>");
        }
Exemple #23
0
 public void postMessage(ACLMessage message)
 {
     messagesQueue.Add(message);
 }
 protected void sendActions(ACLMessage msg)
 {
 }
 protected void sendEntities(ACLMessage msg)
 {
 }
 protected void sendOrganisation(ACLMessage msg)
 {
 }
        protected void manageRequestAction(ACLMessage msg)
        {
            Agent agt = (Agent)(this.Host);

            string content = msg.Content;

            FIPASLParserResult result = parseFipaSLExpression(content);

            if (result.success)
            {
                if (result.isAction)
                {
                    bool done = false;

                    AgentBehavior behavior = agt.getBehaviorByBame(result.action.actionName);

                    if (behavior != null)
                    {
                        Dictionary <string, ValueSpecification> parameters = new Dictionary <string, ValueSpecification>();

                        if (result.action.paramName.Count > 0)
                        {
                            for (int i = 0; i < result.action.paramName.Count; i++)
                            {
                                LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                parameters.Add(result.action.paramName[i], (ValueSpecification)(stringValue));
                            }
                        }
                        else
                        {
                            for (int i = 0; i < result.action.paramName.Count; i++)
                            {
                                LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                parameters.Add("param" + i + '0', (ValueSpecification)(stringValue));
                            }
                        }

                        BehaviorScheduler.Instance.executeBehavior(behavior, agt, parameters, false);
                        ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                        reponse.Content = msg.Content;
                        reponse.Receivers.Add(msg.Sender);
                        agt.send(reponse);
                        done = true;
                    }

                    Class     classifier = agt.Classifier;
                    Operation operation  = null;
                    if (classifier != null && classifier.Operations.ContainsKey(result.action.actionName))
                    {
                        operation = classifier.Operations[result.action.actionName];
                        //System.Console.WriteLine("Operation:" + operation.getFullName());
                    }
                    if (operation != null)
                    {
                        Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();
                        List <Parameter> parameters = operation.Parameters;
                        List <string>    paramValue = result.action.paramValue;
                        List <string>    paramName  = result.action.paramName;

                        if (parameters.Count == paramValue.Count)
                        {
                            for (int i = 0; i < parameters.Count; i++)
                            {
                                // Pour tous les parametres issus de l'operation
                                string parameterName = parameters[i].name;

                                // Cherche l'indice de ce parameter dans paramsName
                                int indice = 0; bool found = false;
                                while (!found && indice < paramName.Count)
                                {
                                    if (paramName[indice] == parameterName)
                                    {
                                        found = true;
                                    }
                                    else
                                    {
                                        indice++;
                                    }
                                }

                                if (found)
                                {
                                    string strVal = paramValue[indice];

                                    System.Console.Write("Type : " + parameters[i].Type.getFullName());
                                    System.Console.Write(" - Name: " + parameters[i].name);
                                    System.Console.WriteLine(" - Value: " + strVal);

                                    string typeName = parameters[i].Type.getFullName();
                                    if (typeName == "boolean" || typeName == "integer" || typeName == "real" || typeName == "string")
                                    {
                                        param.Add(parameters[i].name, parameters[i].Type.createValueFromString(strVal.ToLower()));
                                    }
                                    else
                                    {
                                        try
                                        {
                                            InstanceSpecification inst = MascaretApplication.Instance.getEnvironment().getInstance(strVal.ToLower());
                                            param.Add(parameters[i].name, new InstanceValue(inst));
                                        }
                                        catch (NullReferenceException e)
                                        {
                                        }
                                    }
                                }
                            }

                            //BehaviorScheduler.Instance.executeBehavior(operation.Method, agt, param, false);

                            /*
                             *  List<ActionNode> possibleTranslation = _translateOperationToActions(operation);
                             *
                             *  shared_ptr<AgentBehaviorExecution> abe = agt->getBehaviorExecutionByName("ProceduralBehavior"); //hasslich... ja...
                             *  shared_ptr<ProceduralBehavior> pbe  = shared_dynamic_cast<ProceduralBehavior> (abe);
                             *
                             *  if (possibleTranslation.size() && pbe)
                             *  {
                             *      //add actionNode in ProceduralBehavior
                             *
                             *      pbe->pushActionToDo(possibleTranslation[0]);
                             *  }
                             *  else
                             *  {
                             *      //call method
                             */
                            BehaviorExecution be = BehaviorScheduler.Instance.executeBehavior(operation.Method, agt, param, false);

                            /*
                             * if (be != null)
                             * {
                             *  be.addCallbackOnBehaviorStop(bind(&SimpleCommunicationBehavior::_onBehaviorStop,this,_1));
                             *
                             *  _requestedAction[be->getSpecification()->getName()].push_back(msg->getSender());
                             * }*/
                            // }



                            ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                            reponse.Content = msg.Content;

                            System.Console.WriteLine("Content-Sent: " + reponse.Content);
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);
                        }
                        else
                        {
                            ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                            string     contentRep = "";
                            contentRep     += content;
                            reponse.Content = contentRep;
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);
                        }
                    }
                    else
                    {
                        string procName = result.action.actionName;
                        bool   found    = false;
                        OrganisationalEntity askedOrg  = null;
                        Procedure            askedProc = null;
                        Role askedRole = null;
                        List <OrganisationalEntity> orgs = agt.Plateform.Organisations;

                        for (int iOrg = 0; iOrg < orgs.Count; iOrg++)
                        {
                            List <RoleAssignement> assigns = orgs[iOrg].RoleAssignement;

                            for (int iAss = 0; iAss < assigns.Count; iAss++)
                            {
                                if (assigns[iAss].Agent.toString() == agt.Aid.toString())
                                {
                                    OrganisationalStructure os    = orgs[iOrg].Structure;
                                    List <Procedure>        procs = os.Procedures;

                                    for (int iP = 0; iP < procs.Count; iP++)
                                    {
                                        System.Console.WriteLine(procName + " / " + procs[iP].name);
                                        if (procs[iP].name == procName)
                                        {
                                            askedProc = procs[iP];
                                            askedOrg  = orgs[iOrg];
                                            askedRole = assigns[iAss].Role;
                                            found     = true;
                                        }
                                    }
                                }
                            }
                        }

                        if (found)
                        {
                            ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                            reponse.Content = msg.Content;
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);

                            // Recherche du comportement procedural
                            // UGGLY
                            //System.Console.WriteLine("1");
                            AgentBehaviorExecution pbehavior = agt.getBehaviorExecutingByName("ProceduralBehavior");

                            //AgentBehaviorExecution> behavior2 = agt->getBehaviorExecutionByName("ActionListenerBehavior");
                            //System.Console.WriteLine("2");
                            if (pbehavior != null)
                            {
                                ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior);

                                Dictionary <string, ValueSpecification> procParams = new Dictionary <string, ValueSpecification>();
                                for (int i = 0; i < result.action.paramName.Count; i++)
                                {
                                    LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                    procParams.Add(result.action.paramName[i], stringValue);
                                }

                                //System.Console.WriteLine("3");
                                Activity act = askedProc.Activity;
                                //List<ActivityNode>  nodes  = act.Nodes;

                                procBehave.pushProcedureToDo(askedProc, askedOrg, askedRole, procParams);
                                //procBehave.restart();

                                ACLMessage reponse2 = new ACLMessage(ACLPerformative.AGREE);
                                reponse2.Content = msg.Content;
                                reponse2.Receivers.Add(msg.Sender);
                                agt.send(reponse2);
                            }

                            /*
                             * else if (behavior2)
                             * {
                             *  shared_ptr<ActionListenerBehavior> procBehave  = shared_dynamic_cast<ActionListenerBehavior> (behavior2);
                             *
                             *  procBehave->pushProcedureToDo(askedProc, askedOrg, askedRole, Parameters());
                             *  procBehave->restart();
                             *
                             *  shared_ptr<ACLMessage> reponse = make_shared<ACLMessage>(AGREE);
                             *  reponse->setContent(msg->getContent());
                             *  reponse->addReceiver(msg->getSender());
                             *  agt->send(reponse);
                             * }*/
                            else
                            {
                                if (!done)
                                {
                                    ACLMessage reponse3   = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                                    string     contentRep = "";
                                    contentRep      += result.action.actionName;
                                    reponse3.Content = contentRep;
                                    reponse3.Receivers.Add(msg.Sender);
                                    agt.send(reponse3);
                                }
                            }
                        }
                        else
                        {
                            if (!done)
                            {
                                ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                                string     contentRep = "";
                                contentRep     += result.action.actionName;
                                reponse.Content = contentRep;
                                reponse.Receivers.Add(msg.Sender);
                                agt.send(reponse);
                            }
                        }
                    }
                }
                else
                {
                    // Proposition Non encore traite....
                }
            }
            else
            {
                System.Console.WriteLine("[SimpleCommunicationBehavior Warning] Parsing error. Message content parsing error: " + content);

                ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                string     contentRep = "";
                contentRep += content;

                reponse.Content = contentRep;
                reponse.Receivers.Add(msg.Sender);
                agt.send(reponse);
            }
        }
        protected void manageQueryRef(ACLMessage msg)
        {
            string content = msg.Content;

            FIPASLParserResult result = parseFipaSLExpression(content);

            Dictionary<string, Agent> agents = VRApplication.Instance.AgentPlateform.Agents;

            if (result.isIota)
            {
                FIPAIota iota = result.iota;
                if (iota.predicate == "slot")
                {
                    string fml;
                    string res = getSlot(iota.paramName);
                    MascaretApplication.Instance.VRComponentFactory.Log("IOTA : " + iota.predicate + " " + iota.result + " == " + res);
                    if (res != "")
                    {
                        // give the intention
                        ACLMessage aclMsg = new ACLMessage(ACLPerformative.INFORM);
                        aclMsg.Sender = ((Agent)Host).Aid;
                        aclMsg.Receivers.Add(msg.Sender);
                        aclMsg.Content = "((= (iota ?" + iota.paramName[0] + " (" + iota.predicate + " ?" + iota.paramName[1] + " ?" + iota.paramName[2] + ")) " + res + "))";
                        aclMsg.ConversationID = msg.ConversationID;
                        ((Agent)Host).send(aclMsg);
                        MascaretApplication.Instance.VRComponentFactory.Log("Inform message: " + aclMsg.Content);
                        //bilal 19-10-15
                        fml = "<FML><Performative>Inform</Performative><Receivers><Receiver>" + msg.Sender + "</Receiver></Receivers><Content>" +/* "the " + iota.paramName[1] + " of " + iota.paramName[2] + "is" +*/ res + "</Content><Emotion>Neutral</Emotion><Ressources><Ressource>" + "" + "</Ressource></Ressources></FML>";
                    }
                    //bilal 19-10-15
                    else
                        fml = "<FML><Performative>Inform</Performative><Receivers><Receiver>" + msg.Sender + "</Receiver></Receivers><Content>" + "I don't know" + /*" the value of the " + iota.paramName[1] + " of " + iota.paramName[2] +*/ "</Content><Emotion>Neutral</Emotion><Ressources><Ressource>" + "" + "</Ressource></Ressources></FML>";
                    if (fml != null) ((EmbodiedAgent)(Host)).addIntention(fml);
                    //bilal 19-10-15
                }
            }
        }
 public override bool sendDistantMessage(AID aid, ACLMessage msg)
 {
     return(true);
 }
        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);
        }
Exemple #31
0
 public void send(ACLMessage message)
 {
     messagesSent.Add(message);
 }
        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);
        }
Exemple #33
0
        //non implémentée pour le moment
        public void sendMessage(ACLMessage message)
        {
            List<AID> receivers = message.Receivers;
            for (int i = 0; i < receivers.Count; i++)
            {
                if (receivers[i].PlateformName == "localhost") receivers[i].PlateformName = this.name;
                if (isLocalAgent(receivers[i]))
                {
                    if (this.Agents.ContainsKey(receivers[i].toString()))
                    {
                        Agent receiver = this.Agents[receivers[i].toString()];
                        receiver.postMessage(message);
                        receiver.wakeup();
                    }
                }

            }
        }
        public override void manageRequest(HttpRequest req)
        {
            string procName = req.parameters["alias"];
            string orgName = req.parameters["org"];

            req.response.write("<html>");
            req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            req.response.write("<body>");

            OrganisationalEntity org = null;
            List<OrganisationalEntity> orgs = MascaretApplication.Instance.AgentPlateform.Organisations;
            bool found = false;
            int i = 0;
            while (!found && i < orgs.Count)
            {
                if (orgs[i].name == orgName)
                    found = true;
                else i++;
            }
            if (found) org = orgs[i];

            OrganisationalStructure struc = org.Structure;

            List<Procedure> procs = struc.Procedures;
            Procedure proc = null;
            found = false;
            i = 0;
            while (!found && i < procs.Count)
            {
                if (procs[i].name == procName)
                    found = true;
                else i++;
            }
            if (found) proc = procs[i];

            Environment env = MascaretApplication.Instance.getEnvironment();

            List<Parameter> parameters = new List<Parameter>();
            List<ActivityNode> nodes = proc.Activity.Nodes;
            for (int iNode = 0; iNode < nodes.Count; iNode++)
            {
                if (nodes[iNode].Kind == "parameter")
                    parameters.Add(((ActivityParameterNode)(nodes[iNode])).Parameter);
            }

            string paramString = "";
            Dictionary<string, ValueSpecification> param = new Dictionary<string, ValueSpecification>();
            for (int iParam = 0; iParam < parameters.Count; iParam++)
            {
                string strVal = req.parameters[parameters[iParam].name];
                strVal.Replace("+", " ");

                //Debug.Log (strVal);
                param.Add(parameters[iParam].name, parameters[iParam].Type.createValueFromString(strVal));
                paramString += " :" + parameters[iParam].name + " " + strVal;
            }

            List<RoleAssignement> assignements = org.RoleAssignement;
            for (int iA = 0; iA < assignements.Count; iA++)
            {
                ACLMessage procMsg = new ACLMessage(ACLPerformative.REQUEST);
                procMsg.Receivers.Add(assignements[iA].Agent);

                AID agentAID = MascaretApplication.Instance.Agent.Aid;
                procMsg.Sender = agentAID;
                string content = "((action ";
                content += assignements[iA].Agent.name;
                content += " ";
                content += "(" + proc.name;
                content += paramString;
                content += ")))";
                procMsg.Content = content;
                MascaretApplication.Instance.AgentPlateform.sendMessage(procMsg);

                if (agentAID.name == assignements[iA].Agent.name)
                {
                    req.response.write("<H2>Vous jouez le role ");
                    req.response.write(assignements[iA].Role.name);
                    req.response.write("</H2>");
                    req.response.write("<H3>Vous pouvez faire les actions suivantes : </H3>");

                    req.response.write("<ul>");
                    Activity act = proc.Activity;
                    List<ActivityPartition> partitions = act.Partitions;
                    for (int iPart = 0; iPart < partitions.Count; iPart++)
                    {
                        if (partitions[iPart].name == assignements[iA].Role.name)
                        {
                            nodes = partitions[iPart].Node;
                            for (int iNode = 0; iNode < nodes.Count; iNode++)
                            {
                                if (nodes[iNode].Kind == "action")
                                {
                                    req.response.write("<li>");
                                    req.response.write("<a href=\"Actions?alias=");
                                    req.response.write(nodes[iNode].name);
                                    req.response.write("&org=");
                                    req.response.write(org.name);
                                    req.response.write("&role=");
                                    req.response.write(assignements[iA].Role.name);
                                    req.response.write("&proc=");
                                    req.response.write(proc.name);
                                    req.response.write("\" target = \"Body\">");
                                    req.response.write(nodes[iNode].name);
                                    req.response.write("</a></li>");
                                }
                            }
                        }
                    }
                    req.response.write("</ul>");
                }
            }

            req.response.write("</body>");
            req.response.write("</html>");
        }
Exemple #35
0
 public void postMessage(ACLMessage message)
 {
     this.mailbox.postMessage(message);
 }
Exemple #36
0
 public void send(ACLMessage message)
 {
     message.Sender = this.aid;
     this.plateform.sendMessage(message);
     this.mailbox.send(message);
 }
        public override void manageRequest(HttpRequest req)
        {
            string id = req.parameters["alias"];

            Environment env = MascaretApplication.Instance.getEnvironment();

            if (!env.InstanceSpecifications.ContainsKey(id))
            {
                req.response.write("<html>");
                req.response.write("<body>");
                req.response.write("Can't find entity: " + id);
                req.response.write("</body>");
                req.response.write("</html>");
                return;
            }
            InstanceSpecification entity = env.InstanceSpecifications[id];

            VirtualHuman human = null;

            try
            {
                human = (VirtualHuman)(entity);
            }
            catch (InvalidCastException e)
            {
                req.response.write("<html>");
                req.response.write("<body>");
                req.response.write("Entity: " + id + " is not an agent");
                req.response.write("</body>");
                req.response.write("</html>");
                return;
            }

            req.response.write("<html>");
            req.response.write("<body>");
            req.response.write("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"30\">");
            req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            req.response.write("<link href=\"doxygen.css\" rel=\"stylesheet\" type=\"text/css\">");
            req.response.write("<link href=\"tabs.css\" rel=\"stylesheet\" type=\"text/css\">");

            req.response.write("<H2>Description</H2>");
            req.response.write("<ul>");
            req.response.write("<li>");
            req.response.write(human.name);
            req.response.write("</li>");
            req.response.write("<li>");
            req.response.write(human.getFullName());
            req.response.write("</li>");
            req.response.write("<li>");
            req.response.write(human.Description);
            req.response.write("</li>");
            req.response.write("<li>");
            req.response.write(" <a href=\"Class?alias=");
            req.response.write(human.Classifier.name);
            req.response.write("\" target = \"Body\">");
            req.response.write("</a>");
            req.response.write("</li>");
            req.response.write("</ul>");

            string setControlled = req.parameters["setControlled"];

            if (setControlled == "true")
            {
                human.ControlledByHuman = true;
            }
            else if (setControlled == "false")
            {
                human.ControlledByHuman = false;
            }


            req.response.write("<HR>");
            req.response.write("<H2>Toggle controlled by human</H2>");

            req.response.write("<FORM METHOD=POST action=\"Agent?alias=" + id + "\">");
            req.response.write("<input type=\"hidden\" name=\"alias\" value=\"" + id + "\" />");
            if (human.ControlledByHuman)
            {
                req.response.write("<font color=\"darkred\">This agent is currently controlled. (will not follow procedure automatically)</font><br />");
                req.response.write("<input type=\"hidden\" name=\"setControlled\" value=\"false\" />");
                req.response.write("<input type=\"submit\" name=\"control\" value=\"Release control of this agent\" />");
            }
            else
            {
                req.response.write("<font color=\"darkgreen\">This agent is currently automatic. (will automatically follow procedures)</font><br />");
                req.response.write("<input type=\"hidden\" name=\"setControlled\" value=\"true\" />");
                req.response.write("<input type=\"submit\" name=\"control\" value=\"Take control of this agent\" />");
            }
            req.response.write("</FORM>");

            req.response.write("<HR>");
            req.response.write("<H2>Knowledge base</H2>");
            KnowledgeBase kb = human.KnowledgeBase;

            if (kb != null)
            {
                req.response.write(" <a href=\"KnowledgeBase?alias=");
                req.response.write(human.name);
                req.response.write("\" target = \"_blank\">");
                req.response.write(kb.name);
                req.response.write("</a>");
            }

            req.response.write("<HR>");
            req.response.write("<H2>Parler</H2>");
            req.response.write("<FORM METHOD=GET action=\"speak\">");
            req.response.write("<input type=\"hidden\" name=\"alias\" value=\"");
            req.response.write(id);
            req.response.write("\" />");
            req.response.write("Texte : \t <INPUT name=\"text\">");
            req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Dire\">");
            req.response.write("</FORM>");

            req.response.write("<HR>");
            req.response.write("<H2>Attributs</H2>");
            req.response.write("<FORM METHOD=GET action=\"changeAttributes\">");
            req.response.write("<input type=\"hidden\" name=\"alias\" value=\"");
            req.response.write(id);
            req.response.write("\" />");
            req.response.write("<ul>");

            Dictionary <string, Slot> attributes = human.Slots;

            foreach (KeyValuePair <string, Slot> attr in attributes)
            {
                req.response.write("<li>");
                req.response.write(attr.Key);
                req.response.write(" = ");
                //string value = it->second->getValue().getStringFromValue();
                string value = "";
                foreach (KeyValuePair <string, ValueSpecification> val in attr.Value.Values)
                {
                    value += "'" + val.Value.getStringFromValue() + "' ";
                }
                req.response.write(value);
                req.response.write("</li>");
            }
            req.response.write("</ul>");
            req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Modifier\">");
            req.response.write("</FORM>");
            //req.response.flushBuffer();

            req.response.write("<HR>");
            req.response.write("<H2>Operations</H2>");
            req.response.write("<ul>");
            Class classifier = human.Classifier;
            Dictionary <string, Operation> operations = classifier.Operations;

            foreach (KeyValuePair <string, Operation> operation in operations)
            {
                req.response.write("<li>");
                req.response.write(" <a href=\"Operation?alias=");
                req.response.write(human.name);
                req.response.write("&oper=");
                req.response.write(operation.Key);
                req.response.write("\" target = \"Body\">");
                req.response.write(operation.Key);
                req.response.write("</a>");
                req.response.write("</li>");
            }
            req.response.write("</ul>");
            //req.response.flushBuffer();



            req.response.write("<HR>");
            req.response.write("<H2>Signaux</H2>");
            req.response.write("<ul>");
            Dictionary <string, Behavior> behaviors = classifier.OwnedBehavior;

            foreach (KeyValuePair <string, Behavior> behavior in behaviors)
            {
                StateMachine stateMachine = (StateMachine)(behavior.Value);
                Region       region       = stateMachine.Region[0];
                if (region != null)
                {
                    List <Transition> transitions = region.Transitions;
                    for (int iTrans = 0; iTrans < transitions.Count; iTrans++)
                    {
                        List <Trigger> triggers = transitions[iTrans].Trigger;
                        for (int iTrig = 0; iTrig < triggers.Count; iTrig++)
                        {
                            MascaretEvent evt = triggers[iTrig].MEvent;
                            if (evt != null)
                            {
                                if (evt.Type == "SignalEvent")
                                {
                                    SignalEvent signalEvent = (SignalEvent)(evt);

                                    req.response.write("<li>");
                                    req.response.write(" <a href=\"Signal?alias=");
                                    req.response.write(human.name);
                                    req.response.write("&signal=");
                                    req.response.write(((SignalEvent)(evt)).SignalClass.name);
                                    req.response.write("\" target = \"Body\">");
                                    req.response.write(((SignalEvent)(evt)).SignalClass.name);
                                    req.response.write("</a>");
                                    req.response.write("</li>");
                                }
                            }
                        }
                    }
                }
            }
            req.response.write("</ul>");

            req.response.write("</ul>");
            req.response.write("<HR>");
            req.response.write("<H2>Messages</H2>");
            req.response.write(" AID : ");
            req.response.write(human.Aid.toString());
            req.response.write("<H3>");
            req.response.write(" <a href=\"createMessage?alias=");
            req.response.write(human.name);
            req.response.write("\" target = \"Body\">");
            req.response.write("Envoyer un message");
            req.response.write("</a>");
            req.response.write("</H3>");
            req.response.write("<H3>Non lus</H3>");
            List <ACLMessage> nl = human.Mailbox.MessagesQueue;

            req.response.write("<TABLE BORDER=1>");
            req.response.write("<TR>");
            req.response.write("<TD>De </TD>");
            req.response.write("<TD>Performative </TD>");
            req.response.write("<TD>Contenu </TD>");
            req.response.write("</TR>");
            for (int inl = 0; inl < nl.Count; inl++)
            {
                ACLMessage msg = nl[inl];
                //nl.erase(nl.begin());
                req.response.write("<TR>");
                req.response.write("<TD>");
                req.response.write(msg.Sender.toString());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.getPerformativeText());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.Content);
                req.response.write("</TD>");
                req.response.write("</TR>");
            }
            req.response.write("</TABLE>");

            req.response.write("<H3>Lus</H3>");
            List <ACLMessage> l = human.Mailbox.MessagesChecked;

            req.response.write("<TABLE BORDER=1>");
            req.response.write("<TR>");
            req.response.write("<TD>De </TD>");
            req.response.write("<TD>Performative </TD>");
            req.response.write("<TD>Contenu </TD>");
            req.response.write("</TR>");
            for (int il = 0; il < l.Count; il++)
            {
                ACLMessage msg = l[il];
                req.response.write("<TR>");
                req.response.write("<TD>");
                req.response.write(msg.Sender.toString());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.getPerformativeText());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.Content);
                req.response.write("</TD>");
                req.response.write("</TR>");
            }
            req.response.write("</TABLE>");

            req.response.write("<H3>Envoyes</H3>");
            List <ACLMessage> me = human.Mailbox.MessagesSent;

            req.response.write("<TABLE BORDER=1>");
            req.response.write("<TR>");
            req.response.write("<TD>A </TD>");
            req.response.write("<TD>Performative </TD>");
            req.response.write("<TD>Contenu </TD>");
            req.response.write("</TR>");
            for (int ie = 0; ie < me.Count; ie++)
            {
                ACLMessage msg = me[ie];
                req.response.write("<TR>");
                req.response.write("<TD>");
                List <AID> receivers = msg.Receivers;
                for (int ir = 0; ir < receivers.Count; ir++)
                {
                    req.response.write(receivers[ir].toString());
                }
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.getPerformativeText());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.Content);
                req.response.write("</TD>");
                req.response.write("</TR>");
            }
        }
Exemple #38
0
 public void send(ACLMessage message)
 {
     messagesSent.Add(message);
 }
 protected void sendEntities(ACLMessage msg)
 {
 }
 protected void manageQueryRef(ACLMessage msg)
 {
 }
 public abstract bool sendDistantMessage(AID aid, ACLMessage msg);
        protected void manageRequest(ACLMessage msg)
        {
            Agent agt = (Agent)(this.Host);

            string content = msg.Content;

            System.Console.WriteLine(content);

            if (content == "Model") sendModel(msg);
            else if (content == "Organisation") sendOrganisation(msg);
            else if (content == "Actions") sendActions(msg);
            else if (content == "Entities") sendEntities(msg);  // Renvoi les attributs et etats de chaque entités appartenant  a la procedure et abonne aux messages de modifications d'attributs
            else
            {
            string[] words = content.Split(' ');
               	if (words[0] == "STOP")
               		{
                //string procName = words[1];
                //ProceduralBehavior be=(ProceduralBehavior)(agt.getBehaviorExecutingByName("ProceduralBehavior"));
                /*if (procName =="ALL")
               			if (be) be.stopstopAll();
                else
              	   			if (be) be.stop(procName);
              	   		*/
               		}
               		else manageRequestAction(msg);
            }
        }
        protected void manageRequestAction(ACLMessage msg)
        {
            Agent agt = (Agent)(this.Host);

            string content = msg.Content;

            FIPASLParserResult result = parseFipaSLExpression(content);

            if (result.success)
            {
            if (result.isAction)
            {
                bool done = false;

                AgentBehavior behavior = agt.getBehaviorByBame(result.action.actionName);

                if (behavior != null)
                {
                    Dictionary<string, ValueSpecification> parameters = new Dictionary<string, ValueSpecification>();

                    if (result.action.paramName.Count > 0)
                    {
                        for (int i = 0; i < result.action.paramName.Count; i++)
                        {
                            LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                            parameters.Add(result.action.paramName[i], (ValueSpecification)(stringValue));
                        }
                    }
                    else
                    {
                        for (int i = 0; i < result.action.paramName.Count; i++)
                        {
                            LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                            parameters.Add("param" + i + '0', (ValueSpecification)(stringValue));
                        }
                    }

                    BehaviorScheduler.Instance.executeBehavior(behavior, agt, parameters, false);
                    ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                    reponse.Content = msg.Content;
                    reponse.Receivers.Add(msg.Sender);
                    agt.send(reponse);
                    done = true;
                }

                Class classifier = agt.Classifier;
                Operation operation = null;
                if (classifier != null && classifier.Operations.ContainsKey(result.action.actionName))
                {
                    operation = classifier.Operations[result.action.actionName];
                    //System.Console.WriteLine("Operation:" + operation.getFullName());
                }
                if (operation != null)
                {
                    Dictionary<string, ValueSpecification> param = new Dictionary<string, ValueSpecification>();
                    List<Parameter> parameters = operation.Parameters;
                    List<string> paramValue = result.action.paramValue;
                    List<string> paramName = result.action.paramName;

                    if (parameters.Count == paramValue.Count)
                    {

                        for (int i = 0; i < parameters.Count; i++)
                        {
                            // Pour tous les parametres issus de l'operation
                            string parameterName = parameters[i].name;

                            // Cherche l'indice de ce parameter dans paramsName
                            int indice = 0; bool found = false;
                            while (!found && indice < paramName.Count)
                            {
                                if (paramName[indice] == parameterName)
                                {
                                    found = true;
                                }
                                else
                                {
                                    indice++;
                                }
                            }

                            if (found)
                            {
                                string strVal = paramValue[indice];

                                System.Console.Write("Type : " + parameters[i].Type.getFullName());
                                System.Console.Write(" - Name: " + parameters[i].name);
                                System.Console.WriteLine(" - Value: " + strVal);

                                string typeName = parameters[i].Type.getFullName();
                                if (typeName == "boolean" || typeName == "integer" || typeName == "real" || typeName == "string")
                                    param.Add(parameters[i].name, parameters[i].Type.createValueFromString(strVal.ToLower()));
                                else
                                {
                                    try
                                    {
                                        InstanceSpecification inst = MascaretApplication.Instance.getEnvironment().getInstance(strVal.ToLower());
                                        param.Add(parameters[i].name, new InstanceValue(inst));
                                    }
                                    catch (NullReferenceException)
                                    {

                                    }

                                }

                            }
                        }

                        //BehaviorScheduler.Instance.executeBehavior(operation.Method, agt, param, false);
                        /*
                            List<ActionNode> possibleTranslation = _translateOperationToActions(operation);

                            shared_ptr<AgentBehaviorExecution> abe = agt->getBehaviorExecutionByName("ProceduralBehavior"); //hasslich... ja...
                            shared_ptr<ProceduralBehavior> pbe  = shared_dynamic_cast<ProceduralBehavior> (abe);

                            if (possibleTranslation.size() && pbe)
                            {
                                //add actionNode in ProceduralBehavior

                                pbe->pushActionToDo(possibleTranslation[0]);
                            }
                            else
                            {
                                //call method
                        */
                                BehaviorExecution be = BehaviorScheduler.Instance.executeBehavior(operation.Method, agt, param, false);
                /*
                                if (be != null)
                                {
                                    be.addCallbackOnBehaviorStop(bind(&SimpleCommunicationBehavior::_onBehaviorStop,this,_1));

                                    _requestedAction[be->getSpecification()->getName()].push_back(msg->getSender());
                                }*/
                           // }

                        ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                        reponse.Content = msg.Content;

                        System.Console.WriteLine("Content-Sent: " + reponse.Content);
                        reponse.Receivers.Add(msg.Sender);
                        agt.send(reponse);
                    }
                    else
                    {
                        ACLMessage reponse = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                        string contentRep = "";
                        contentRep += content;
                        reponse.Content = contentRep;
                        reponse.Receivers.Add(msg.Sender);
                        agt.send(reponse);
                    }
                }
                else
                {
                    string procName = result.action.actionName;
                    bool found = false;
                    OrganisationalEntity askedOrg = null;
                    Procedure askedProc = null;
                    Role askedRole = null;
                    List<OrganisationalEntity> orgs = agt.Plateform.Organisations;

                    for (int iOrg = 0; iOrg < orgs.Count; iOrg++)
                    {
                        List<RoleAssignement> assigns = orgs[iOrg].RoleAssignement;

                        for (int iAss = 0; iAss < assigns.Count; iAss++)
                        {
                            if (assigns[iAss].Agent.toString() == agt.Aid.toString())
                            {
                                OrganisationalStructure os = orgs[iOrg].Structure;
                                List<Procedure> procs = os.Procedures;

                                for (int iP = 0; iP < procs.Count; iP++)
                                {
                                    System.Console.WriteLine(procName + " / " + procs[iP].name);
                                    if (procs[iP].name == procName)
                                    {
                                        askedProc = procs[iP];
                                        askedOrg = orgs[iOrg];
                                        askedRole = assigns[iAss].Role;
                                        found = true;
                                    }
                                }
                            }
                        }
                    }

                    if (found)
                    {
                        ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                        reponse.Content = msg.Content;
                        reponse.Receivers.Add(msg.Sender);
                        agt.send(reponse);

                        // Recherche du comportement procedural
                        // UGGLY
                        //System.Console.WriteLine("1");
                        AgentBehaviorExecution pbehavior = agt.getBehaviorExecutingByName("ProceduralBehavior");

                        //AgentBehaviorExecution> behavior2 = agt->getBehaviorExecutionByName("ActionListenerBehavior");
                        //System.Console.WriteLine("2");
                        if (pbehavior != null)
                        {
                            ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior);

                            Dictionary<string, ValueSpecification> procParams = new Dictionary<string, ValueSpecification>();
                            for (int i = 0; i < result.action.paramName.Count; i++)
                            {
                                LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                procParams.Add(result.action.paramName[i], stringValue);
                            }

                            //System.Console.WriteLine("3");
                            Activity act = askedProc.Activity;
                            //List<ActivityNode>  nodes  = act.Nodes;

                            procBehave.pushProcedureToDo(askedProc, askedOrg, askedRole, procParams);
                            //procBehave.restart();

                            ACLMessage reponse2 = new ACLMessage(ACLPerformative.AGREE);
                            reponse2.Content = msg.Content;
                            reponse2.Receivers.Add(msg.Sender);
                            agt.send(reponse2);
                        }
                        /*
                        else if (behavior2)
                        {
                            shared_ptr<ActionListenerBehavior> procBehave  = shared_dynamic_cast<ActionListenerBehavior> (behavior2);

                            procBehave->pushProcedureToDo(askedProc, askedOrg, askedRole, Parameters());
                            procBehave->restart();

                            shared_ptr<ACLMessage> reponse = make_shared<ACLMessage>(AGREE);
                            reponse->setContent(msg->getContent());
                            reponse->addReceiver(msg->getSender());
                            agt->send(reponse);
                        }*/
                        else
                        {
                            if (!done)
                            {
                                ACLMessage reponse3 = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                                string contentRep = "";
                                contentRep += result.action.actionName;
                                reponse3.Content = contentRep;
                                reponse3.Receivers.Add(msg.Sender);
                                agt.send(reponse3);
                            }
                        }
                    }
                    else
                    {
                        if (!done)
                        {
                            ACLMessage reponse = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                            string contentRep = "";
                            contentRep += result.action.actionName;
                            reponse.Content = contentRep;
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);
                        }
                    }
                }
            }
            else
            {
                // Proposition Non encore traite....
            }
            }
            else
            {
            System.Console.WriteLine("[SimpleCommunicationBehavior Warning] Parsing error. Message content parsing error: " + content);

            ACLMessage reponse = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
            string contentRep = "";
            contentRep += content;

            reponse.Content = contentRep;
            reponse.Receivers.Add(msg.Sender);
            agt.send(reponse);
            }
        }
 public abstract bool sendDistantMessage(AID aid, ACLMessage msg);
 protected void sendActions(ACLMessage msg)
 {
 }
Exemple #46
0
 public void send(ACLMessage message)
 {
     message.Sender = this.aid;
     this.plateform.sendMessage(message);
     this.mailbox.send(message);
 }
 public override bool sendDistantMessage(AID aid, ACLMessage msg)
 {
     return true;
 }