protected string getSlot(List <string> p)
        {
            string entityName = p[2];
            string slotName   = p[1];

            MascaretApplication.Instance.VRComponentFactory.Log(entityName + "." + slotName);
            string 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)
                        {
                            value = s.Value.getValue().getStringFromValue();
                        }
                    }
                }
            }

            return(value);
        }
예제 #2
0
 //default parameters KBName = "default"
 public Agent(AgentPlateform ap, string name, AgentClass agentclass, string KBName)
     : base(name, agentclass)
 {
     this.aid = new AID(name, ap.name, ap.PortNumber);
     this.plateform = ap;
     mailbox = new Mailbox();
     knowledgeBase = new KnowledgeBase(KBName);
     behaviorPlanner = new BehaviorPlanner(this);
     //behaviorRealizer = new BehaviorRealizer();
 }
예제 #3
0
파일: Agent.cs 프로젝트: mbbarange/Mascaret
 //default parameters KBName = "default"
 public Agent(AgentPlateform ap, string name, AgentClass agentclass, string KBName)
     : base(name, agentclass)
 {
     this.aid       = new AID(name, ap.name, ap.PortNumber);
     this.plateform = ap;
     mailbox        = new Mailbox();
     knowledgeBase  = new KnowledgeBase(KBName);
     //behaviorPlanner = new BehaviorPlanner(this);
     //behaviorRealizer = new BehaviorRealizer();
     emotion = "joyStrong";
 }
        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);
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        public override void manageRequest(HttpRequest req)
        {
            string id = "";

            if (req.parameters.ContainsKey("agent"))
            {
                id = req.parameters["agent"];
            }

            Environment           env    = MascaretApplication.Instance.getEnvironment();
            InstanceSpecification entity = null;

            if (env.InstanceSpecifications.ContainsKey(id))
            {
                entity = env.InstanceSpecifications[id];
            }

            VirtualHuman human = null;

            if (entity != null)
            {
                human = (VirtualHuman)(entity);
            }


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

            req.response.write("<div class=\"tabs\">");
            req.response.write("<ul>");
            if (human == null)
            {
                req.response.write("<li class=\"current\"><a href=\"Model\"><span>Model</span></a></li>");
            }
            else
            {
                req.response.write("<li><a href=\"Model?agent=");
                req.response.write(human.name);
                req.response.write("\"><span>Model</span></a></li>");
            }
            if (human == null)
            {
                req.response.write("<li><a href=\"Instances\"><span>Entites</span></a></li>");
            }
            else
            {
                req.response.write("<li><a href=\"Instances?agent=");
                req.response.write(human.name);
                req.response.write("\"><span>Entites</span></a></li>");
            }
            req.response.write("<li><a href=\"Agents\"><span>Humains Virtuels</span></a></li>");
            req.response.write("<li><a href=\"Organisations\"><span>Organisations</span></a></li>");
            req.response.write("<li><a href=\"Scenario\"><span>Scenario</span></a></li>");
            req.response.write("<li><a href=\"Application\"><span>Application</span></a></li>");
            req.response.write("<li><a href=\"FIPASL\"><span>FIPA SL</span></a></li>");
            req.response.write("<li><a href=\"XOCL\"><span>XOCL</span></a></li>");
            req.response.write("<li><a href=\"messages\"><span>Mes messages</span></a></li>");

            req.response.write("</ul>");
            req.response.write("</div>");

            req.response.write("<HR>");

            req.response.write("<ul>");

            Model model;

            if (human != null)
            {
                KnowledgeBase kb    = human.KnowledgeBase;
                Environment   envKB = kb.Environment;
                if (envKB != null)
                {
                    _printPackage(0, req, env.Model.Package, human);
                }
            }
            else
            {
                _printPackage(0, req, MascaretApplication.Instance.Model.Package, null);
            }

            req.response.write("</ul>");

            req.response.write("</body>");
            req.response.write("</html>");
        }
예제 #6
0
        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>");
            }
        }