Ejemplo n.º 1
0
 public void addAgentToInform(AID agent, string convId)
 {
     PairStringAID pair = new PairStringAID();
     pair.str = convId;
     pair.aid = agent;
     agentsToInform.Add(pair);
 }
Ejemplo n.º 2
0
        public void addAgentToInform(AID agent, string convId)
        {
            PairStringAID pair = new PairStringAID();

            pair.str = convId;
            pair.aid = agent;
            agentsToInform.Add(pair);
        }
Ejemplo n.º 3
0
        public void informActionRunning(AID agent, string actionName)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("Start : " + actionName);

            ActionNode action = getActionByNameFor(agent, actionName);

            informActionRunning(agent, action);
        }
Ejemplo n.º 4
0
        public void onActionRunning(AID agent, string actionName)
        {
            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];

                procInfo.informActionRunning(agent, actionName);
            }
        }
Ejemplo n.º 5
0
        public void onActionDone(AID agent, ActionNode action)
        {
            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];

                procInfo.informActionDone(agent, action);
            }
            ispause = false;
        }
Ejemplo n.º 6
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();
 }
Ejemplo n.º 7
0
        public AID parseFromString(string aidStr)
        {
            char[] param = { '@', ':' };
            string[] splitedStr = aidStr.Split(param);
            AID newAID = new AID(splitedStr[0], splitedStr[1], int.Parse(splitedStr[2]));

            if (splitedStr.Length != 3)
                System.Console.WriteLine("AID STRING " + aidStr + "IS NOT CORRECTLY FORMATED");

            return newAID;
        }
Ejemplo n.º 8
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();
     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);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        List <string> getAllActionsDoneBy(AID agent)
        {
            // TODO: Maybe retyrb ActionNode and not name ?
            List <string>     actions = new List <string>();
            List <ActionNode> nodes   = allActionsDone[agent.toString()];

            for (int i = 0; i < nodes.Count; i++)
            {
                actions.Add(clean(nodes[i].name));
            }
            return(actions);
        }
Ejemplo n.º 11
0
        public AID parseFromString(string aidStr)
        {
            char[]   param      = { '@', ':' };
            string[] splitedStr = aidStr.Split(param);
            AID      newAID     = new AID(splitedStr[0], splitedStr[1], int.Parse(splitedStr[2]));

            if (splitedStr.Length != 3)
            {
                System.Console.WriteLine("AID STRING " + aidStr + "IS NOT CORRECTLY FORMATED");
            }

            return(newAID);
        }
Ejemplo n.º 12
0
        public List <ActionNode> getAllActionsFor(AID agent)
        {
            List <ActionNode> allActionNodes = getAllActions();
            List <ActionNode> nodesForAgent  = new List <ActionNode>();

            for (int i = 0; i < allActionNodes.Count; ++i)
            {
                if (allActionNodes[i].Partitions[0].name == agentToPartition[agent.toString()].name)
                {
                    nodesForAgent.Add(allActionNodes[i]);
                }
            }

            return(nodesForAgent);
        }
Ejemplo n.º 13
0
        public void informActionDone(AID agent, ActionNode action)
        {
            bool foundAndRemoved = false;

            //remove from "running" list
            for (int i = 0; i < actionsRunning.Count; ++i)
            {
                if ((actionsRunning[i].Key == agent.toString()) && (actionsRunning[i].Value.getFullName() == action.getFullName()))
                {
                    actionsRunning.RemoveAt(i);
                    foundAndRemoved = true;
                    break;
                }
            }

            //Debug.Log(" IAD : " + activeTokens.Count);
            if (foundAndRemoved)
            {
                ActionNode doneAction = action;
                if (doneAction != null)
                {
                    bool advancedToken = false;

                    for (int i = 0; i < activeTokens.Count; i++)
                    {
                        ActivityExecutionToken token = activeTokens[i];
                        if (tryToAdvanceToken(token, doneAction, true))
                        {
                            advancedToken = true;
                        }
                    }

                    if (advancedToken)
                    {
                        //add to "done" list
                        actionsDone.Add(doneAction);
                        allActionsDone[agent.toString()].Add(doneAction);
                        allActionsDoneTimestamps[agent.toString()].Add(doneAction.CurrentExecution.Finish);
                    }
                    else
                    {
                        //if (ACTIVATE_GENERAL_DEBUG) cerr << "HUSTON, WE'VE GOT A PROBLEM... no token was advanced for " << doneAction->getName() << endl;
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public List <ActionNode> getActionToExecuteFor(AID agent)
        {
            List <ActionNode> toExec = new List <ActionNode>();

            //	Debug.Log(" GET ACTIONS TO DO");

            List <ActionNode> allActionsToExecute = getActionToExecuteForAll();

            for (int i = 0; i < allActionsToExecute.Count; ++i)
            {
                //check author
                if (allActionsToExecute[i].Partitions[0].name == agentToPartition[agent.toString()].name)
                {
                    toExec.Add(allActionsToExecute[i]);
                }
            }


            return(toExec);
        }
Ejemplo n.º 15
0
        public ActionNode getActionByNameFor(AID agent, string action)
        {
            //assuming only one action exists by that name !

            List <ActionNode> allActionNodes = getAllActions();

            ActionNode found = null;

            for (int i = 0; i < allActionNodes.Count; ++i)
            {
                //agentToPartition.getMap(agent.toString()).name;

                if ((allActionNodes[i].Partitions[0].name == agentToPartition[agent.toString()].name) && (action == clean(allActionNodes[i].name)))
                {
                    found = allActionNodes[i];
                    break;
                }
            }

            return(found);
        }
Ejemplo n.º 16
0
        public ActionNode getActionByNameFor(AID agent, string action)
        {
            //assuming only one action exists by that name !

            List<ActionNode> allActionNodes = getAllActions();

            ActionNode found = null;

            for (int i = 0; i < allActionNodes.Count; ++i)
            {
                //agentToPartition.getMap(agent.toString()).name;

                if ((allActionNodes[i].Partitions[0].name == agentToPartition[agent.toString()].name) && (action == clean(allActionNodes[i].name)))
                {
                    found = allActionNodes[i];
                    break;
                }
            }

            return found;
        }
Ejemplo n.º 17
0
 List <TimeExpression> getAllActionsDoneTimestampsBy(AID agent)
 {
     return(allActionsDoneTimestamps[agent.toString()]);
 }
Ejemplo n.º 18
0
 List<TimeExpression> getAllActionsDoneTimestampsBy(AID agent)
 {
     return allActionsDoneTimestamps[agent.toString()];
 }
Ejemplo n.º 19
0
        public void informActionRunning(AID agent, ActionNode action)
        {
            //check if procedure will advance if this action is made
            bool canAdvance = true;

            ActionNode actionToRun = null;

            MascaretApplication.Instance.VRComponentFactory.Log("Start : " + action.getFullName());

            // Test if action owned by agent
            if (action.Partitions[0].name == agentToPartition[agent.toString()].name)
            {
                actionToRun = action;
            }
            else
            {
                MascaretApplication.Instance.VRComponentFactory.Log("This action " + action.getFullName() + " doesn't belong to agent " + agent.toString());
            }
            if (actionToRun != null)
            {
                //check if procedure can advance (action is reachable from the previous done actions)
                List <ActionNode> possibleNextActions = getActionToExecuteFor(agent);

                for (int i = 0; i < possibleNextActions.Count; ++i)
                {
                    if (actionToRun == possibleNextActions[i])
                    {
                        canAdvance = true;
                        break;
                    }
                }
            }

            if (canAdvance)
            {
                //save the running action in the list
                actionsRunning.Add(new KeyValuePair <string, ActionNode>(agent.toString(), action));

                //TODO: appologise because the hack is not so beautiful. the good part is that it works fine :)
                //update next reachable nodes list, if their current location is not a dead end (this caused problems with loopnodes for example...)
                //-- the problem was that loopnodes must not be restarted/skipped until the effect of its actions is understood. this is not the case with decision nodes for example
                ActionNode doneAction = action;

                if (doneAction != null)
                {
                    bool advancedToken = false;
                    for (int i = 0; i < activeTokens.Count; ++i)
                    {
                        if ((activeTokens[i].outgoingEdge == null) ||
                            (activeTokens[i].outgoingEdge.Target.getOutgoingControlFlowEdges().Count == 0))
                        {
                            continue; //skip deadends
                        }
                        //try to advance
                        //if (ACTIVATE_DEBUG_CONSOLE_OUTPUT_TOKENS) cerr << "> trying to advance token " << (i+1) << "/" << _activeTokens.size() << " from " << _activeTokens[i]->currentLocation->getName() << endl;

                        ActivityExecutionToken token = activeTokens[i];
                        if (tryToAdvanceToken(token, doneAction, true))
                        {
                            //if (ACTIVATE_DEBUG_CONSOLE_OUTPUT_TOKENS) cerr << "   >>  advanced token " << (i+1) << "/" << _activeTokens.size() << " to " << _activeTokens[i]->currentLocation->getName() << endl;

                            activeTokens[i] = token;
                            advancedToken   = true;
                        }
                    }

                    if (advancedToken)
                    {
                        //add to "done" list
                        actionsDone.Add(doneAction);

                        MascaretApplication.Instance.VRComponentFactory.Log("AllActionsDone : " + agent.toString());
                        if (!allActionsDone.ContainsKey(agent.toString()))
                        {
                            allActionsDone.Add(agent.toString(), new List <ActionNode>());
                        }
                        allActionsDone[agent.toString()].Add(doneAction);

                        MascaretApplication.Instance.VRComponentFactory.Log("allActionsDoneTimestamps : " + agent.toString());
                        if (!allActionsDoneTimestamps.ContainsKey(agent.toString()))
                        {
                            allActionsDoneTimestamps.Add(agent.toString(), new List <TimeExpression>());
                        }
                        allActionsDoneTimestamps[agent.toString()].Add(doneAction.CurrentExecution.Finish);
                        MascaretApplication.Instance.VRComponentFactory.Log("Done");
                    }
                    else
                    {
                        //if (ACTIVATE_GENERAL_DEBUG) cerr << "HUSTON, WE'VE GOT A PROBLEM... no token was advanced for " << doneAction->getName() << endl;
                    }
                }
            }
        }
Ejemplo n.º 20
0
 public bool isLocalAgent(AID aid)
 {
     return(((aid.PlateformName == name || aid.PlateformName == "localhost") && aid.PlateformPort == portNumber));
 }
Ejemplo n.º 21
0
 List<string> getAllActionsDoneBy(AID agent)
 {
     // TODO: Maybe retyrb ActionNode and not name ?
     List<string> actions = new List<string>();
     List<ActionNode> nodes = allActionsDone[agent.toString()];
     for(int i = 0; i < nodes.Count; i++)
     {
         actions.Add(clean(nodes[i].name));
     }
     return actions;
 }
Ejemplo n.º 22
0
 public RoleAssignement(OrganisationalEntity organisation)
 {
     role              = new Role("");
     agent             = new AID("", "", 0);
     this.organisation = organisation;
 }
Ejemplo n.º 23
0
        public void informActionRunning(AID agent, string actionName)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("Start : " + actionName);

            ActionNode action = getActionByNameFor(agent, actionName);
            informActionRunning(agent, action);
        }
Ejemplo n.º 24
0
 public void informActionDone(AID agent, string actionName)
 {
     ActionNode action = getActionByNameFor(agent, actionName);
     informActionDone(agent, action);
 }
Ejemplo n.º 25
0
        public List<ActionNode> getActionToExecuteFor(AID agent)
        {
            List<ActionNode> toExec = new List<ActionNode>();

            //	Debug.Log(" GET ACTIONS TO DO");

            List<ActionNode> allActionsToExecute = getActionToExecuteForAll();
            for (int i = 0; i < allActionsToExecute.Count; ++i)
            {
                //check author
                if (allActionsToExecute[i].Partitions[0].name == agentToPartition[agent.toString()].name)
                {
                    toExec.Add(allActionsToExecute[i]);
                }
            }

            return toExec;
        }
 public abstract bool sendDistantMessage(AID aid, ACLMessage msg);
Ejemplo n.º 27
0
        public void informActionDone(AID agent, string actionName)
        {
            ActionNode action = getActionByNameFor(agent, actionName);

            informActionDone(agent, action);
        }
Ejemplo n.º 28
0
        public List<ActionNode> getAllActionsFor(AID agent)
        {
            List<ActionNode> allActionNodes = getAllActions();
            List<ActionNode> nodesForAgent = new List<ActionNode>();

            for (int i=0; i<allActionNodes.Count; ++i)
            {
                if(allActionNodes[i].Partitions[0].name == agentToPartition[agent.toString()].name)
                {
                    nodesForAgent.Add(allActionNodes[i]);
                }
            }

            return nodesForAgent;
        }
Ejemplo n.º 29
0
 public bool isLocalAgent(AID aid)
 {
     return (((aid.PlateformName == name || aid.PlateformName == "localhost") && aid.PlateformPort == portNumber));
 }
Ejemplo n.º 30
0
        public void informActionDone(AID agent, ActionNode action)
        {
            bool foundAndRemoved = false;
            //remove from "running" list
            for (int i = 0; i < actionsRunning.Count; ++i)
            {
                if ((actionsRunning[i].Key == agent.toString()) && (actionsRunning[i].Value.getFullName() == action.getFullName()))
                {
                    actionsRunning.RemoveAt(i);
                    foundAndRemoved = true;
                    break;
                }
            }

            //Debug.Log(" IAD : " + activeTokens.Count);
            if (foundAndRemoved)
            {
                ActionNode doneAction = action;
                if (doneAction != null)
                {
                    bool advancedToken = false;

                    for (int i = 0; i < activeTokens.Count; i++)
                    {
                        ActivityExecutionToken token = activeTokens[i];
                       	if (tryToAdvanceToken(token, doneAction, true))
                        {
                            advancedToken = true;
                        }
                    }

                    if (advancedToken)
                    {

                        //add to "done" list
                        actionsDone.Add(doneAction);
                        allActionsDone[agent.toString()].Add(doneAction);
                        allActionsDoneTimestamps[agent.toString()].Add(doneAction.CurrentExecution.Finish);
                    }
                    else
                    {
                        //if (ACTIVATE_GENERAL_DEBUG) cerr << "HUSTON, WE'VE GOT A PROBLEM... no token was advanced for " << doneAction->getName() << endl;
                    }
                }
            }
        }
 public abstract bool sendDistantMessage(AID aid, ACLMessage msg);
Ejemplo n.º 32
0
        public void informActionRunning(AID agent, ActionNode action)
        {
            //check if procedure will advance if this action is made
            bool canAdvance = true;

            ActionNode actionToRun = null;
            MascaretApplication.Instance.VRComponentFactory.Log("Start : " + action.getFullName());

            // Test if action owned by agent
            if (action.Partitions[0].name == agentToPartition[agent.toString()].name)
                actionToRun = action;
            else
                MascaretApplication.Instance.VRComponentFactory.Log( "This action " + action.getFullName() + " doesn't belong to agent " + agent.toString());
             if (actionToRun != null)
             {
                 //check if procedure can advance (action is reachable from the previous done actions)
                 List<ActionNode> possibleNextActions = getActionToExecuteFor(agent);

                 for (int i=0; i<possibleNextActions.Count; ++i)
                 {
                     if (actionToRun == possibleNextActions[i])
                     {
                        canAdvance = true;
                        break;
                     }
                 }
            }

            if (canAdvance)
            {
                //save the running action in the list
                actionsRunning.Add(new KeyValuePair<string, ActionNode>(agent.toString(), action));

                //TODO: appologise because the hack is not so beautiful. the good part is that it works fine :)
                //update next reachable nodes list, if their current location is not a dead end (this caused problems with loopnodes for example...)
                //-- the problem was that loopnodes must not be restarted/skipped until the effect of its actions is understood. this is not the case with decision nodes for example
                ActionNode doneAction = action;

                if (doneAction != null)
                {
                    bool advancedToken = false;
                    for (int i = 0; i < activeTokens.Count; ++i)
                    {
                        if ((activeTokens[i].outgoingEdge == null) ||
                                (activeTokens[i].outgoingEdge.Target.getOutgoingControlFlowEdges().Count == 0))
                        {
                            continue; //skip deadends
                        }
                        //try to advance
                        //if (ACTIVATE_DEBUG_CONSOLE_OUTPUT_TOKENS) cerr << "> trying to advance token " << (i+1) << "/" << _activeTokens.size() << " from " << _activeTokens[i]->currentLocation->getName() << endl;

                        ActivityExecutionToken token = activeTokens[i];
                        if (tryToAdvanceToken(token, doneAction, true))
                        {
                            //if (ACTIVATE_DEBUG_CONSOLE_OUTPUT_TOKENS) cerr << "   >>  advanced token " << (i+1) << "/" << _activeTokens.size() << " to " << _activeTokens[i]->currentLocation->getName() << endl;

                            activeTokens[i] = token;
                            advancedToken = true;
                        }

                    }

                    if (advancedToken)
                    {

                        //add to "done" list
                        actionsDone.Add(doneAction);

                        MascaretApplication.Instance.VRComponentFactory.Log("AllActionsDone : " + agent.toString());
                        if (!allActionsDone.ContainsKey(agent.toString()))
                            allActionsDone.Add(agent.toString(), new List<ActionNode>());
                        allActionsDone[agent.toString()].Add(doneAction);

                        MascaretApplication.Instance.VRComponentFactory.Log("allActionsDoneTimestamps : " + agent.toString());
                        if (!allActionsDoneTimestamps.ContainsKey(agent.toString()))
                            allActionsDoneTimestamps.Add(agent.toString(),new List<TimeExpression>());
                        allActionsDoneTimestamps[agent.toString()].Add( doneAction.CurrentExecution.Finish);
                        MascaretApplication.Instance.VRComponentFactory.Log("Done");
                    }
                    else
                    {
                        //if (ACTIVATE_GENERAL_DEBUG) cerr << "HUSTON, WE'VE GOT A PROBLEM... no token was advanced for " << doneAction->getName() << endl;
                    }
                }
            }
        }
Ejemplo n.º 33
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>");
        }
Ejemplo n.º 34
0
        public void onActionRunning(AID agent, string actionName)
        {
            for (int iP = 0; iP < runningProcedures.Count;iP++ )
            {
                ProcedureExecution procInfo = runningProcedures[iP];

                procInfo.informActionRunning(agent,actionName);
            }
        }
Ejemplo n.º 35
0
        public void onActionDone(AID agent, ActionNode action)
        {
            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];

                procInfo.informActionDone(agent, action);
            }
            ispause = false;
        }
Ejemplo n.º 36
0
 public override bool sendDistantMessage(AID aid, ACLMessage msg)
 {
     return(true);
 }
Ejemplo n.º 37
0
 public RoleAssignement(OrganisationalEntity organisation)
 {
     role = new Role("");
     agent = new AID("", "", 0);
     this.organisation = organisation;
 }
Ejemplo n.º 38
0
        protected OrganisationalEntity _createOrganisation(XElement node)
        {
            //StreamWriter file = new StreamWriter("Organisation.txt");

            string name = "";
            OrganisationalEntity organisation = null;
            XAttribute attr = (XAttribute)node.Attribute("name");
            if (attr != null) name = attr.Value;

            foreach (XElement struc in node.Elements())
            {
                if (struc.Name.LocalName == "Structure")
                {
                    string structName = struc.Value;

                    OrganisationalStructure structOrg = null;

                    foreach (OrganisationalStructure currentOrg in agentPlateform.Structures)
                    {
                        if (currentOrg.name == structName)
                        {
                            structOrg = currentOrg;
                            break;
                        }
                    }
                    if (structOrg == null)
                    {  }
                    else
                    {
                      //  MascaretApplication.Instance.logfile.WriteLine("Structure found"); MascaretApplication.Instance.logfile.Flush();
                        organisation = new OrganisationalEntity(name);
                        organisation.Structure = structOrg;

                        structOrg.Entities.Add(organisation);

                        foreach (XElement affects in node.Elements())
                        {
                            if (affects.Name.LocalName == "Affect")
                            {
                                attr = (XAttribute)affects.Attribute("type");

                                if (attr != null && attr.Value == "Role")
                                {

                                //    file.WriteLine("Affect Role"); file.Flush();
                                    XElement roleNode = null, agentNode = null, aidNode = null;

                                    foreach (XElement currentNode in affects.Elements())
                                    {
                                        if (currentNode.Name.LocalName == "Role")
                                            roleNode = currentNode;
                                        else if (currentNode.Name.LocalName == "Agent")
                                            agentNode = currentNode;
                                        else if (currentNode.Name.LocalName == "AID")
                                            aidNode = currentNode;
                                    }

                                    string agentName = "";
                                    string plateformeName = "localhost";
                                    int plateformePort = agentPlateform.PortNumber;
                                    if (aidNode != null)
                                    {
                                        foreach (XElement currentNode in aidNode.Elements())
                                        {
                                            if (currentNode.Name.LocalName == "Name")
                                            {
                                                agentName = currentNode.Value;
                                            }
                                            else if (currentNode.Name.LocalName == "Plateform")
                                            {
                                                plateformeName = currentNode.Value;
                                            }
                                            else if (currentNode.Name.LocalName == "Port")
                                            {
                                                string ports = currentNode.Value;
                                                plateformePort = int.Parse(ports);
                                            }
                                        }

                                    }
                                    else
                                    {
                                        agentName = agentNode.Value;
                                    }

                                    string roleName = roleNode.Value;

                                    if (plateformeName == "localhost") plateformeName = agentPlateform.name;

                                    AID aid = new AID(agentName, plateformeName, plateformePort);

                                    Role role = null;

                                //    file.WriteLine("Nb Roles : " + structOrg.Roles.Count); file.Flush();

                                    foreach (Role currentRole in structOrg.Roles)
                                    {
                                     //   file.WriteLine(currentRole.name + " == " + roleName); file.Flush();
                                        if (currentRole.name == roleName)
                                        {
                                            role = currentRole;
                                            break;
                                        }
                                    }
                                    if (role == null)
                                    {  }
                                    else
                                    {
                                     //   file.WriteLine("Assign"); file.Flush();
                                        RoleAssignement assignement = new RoleAssignement(organisation);
                                        assignement.Agent = aid;
                                        assignement.Role = role;
                                        organisation.RoleAssignement.Add(assignement);
                                    }

                                }
                                else if (attr != null && attr.Value == "Ressource")
                                {
                                    XElement ressourceNode = null, entityNode = null;
                                    string ressourceName = "";
                                    string entityName = "";

                                    foreach (XElement currentNode in affects.Elements())
                                    {
                                        if (currentNode.Name.LocalName == "Ressource")
                                            ressourceNode = currentNode;

                                        else if (currentNode.Name.LocalName == "Entity")
                                            entityNode = currentNode;
                                    }

                                    ressourceName = ressourceNode.Value;
                                    entityName = entityNode.Value;

                                    //Debug.Log( " Affectation Ressource : " + ressourceName + " = " + entityName );
                                    // Recherche de l'entite .....
                                  //  MascaretApplication.Instance.logfile.WriteLine("Ressource affect looking entity : " + entityName);
                                  //  MascaretApplication.Instance.logfile.Flush();
                                    InstanceSpecification entite = environment.getInstance(entityName);
                                    if (entite == null) {
                                     //   MascaretApplication.Instance.logfile.WriteLine("Not found");
                                     //   MascaretApplication.Instance.logfile.Flush();
                                    }

                                    // Recherche de la ressource
                                    Ressource res = null;
                                    //Debug.Log( " *** " + structOrg.Ressources.Count );
                                    foreach (Ressource currentRes in structOrg.Ressources)
                                    {
                                     //   MascaretApplication.Instance.logfile.WriteLine( "Resource search: comparing " + currentRes.name + " to " + ressourceName );
                                     //   MascaretApplication.Instance.logfile.Flush();
                                        if (currentRes.name == ressourceName)
                                        {
                                          //  MascaretApplication.Instance.logfile.WriteLine("found");
                                          //  MascaretApplication.Instance.logfile.Flush();
                                            res = currentRes;
                                            break;
                                        }
                                    }

                                    // Creation de l'assignement
                                    RessourceAssignement ra = new RessourceAssignement();
                                    ra.Entity = ((Entity)entite);
                                    ra.Ressource = res;

                                    organisation.RessourcesAssignement.Add(ra);

                                }
                            }
                        }
                    }
                }
            }

            return organisation;
        }
        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;
            }*/
        }
Ejemplo n.º 40
0
        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);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 41
0
 public override bool sendDistantMessage(AID aid, ACLMessage msg)
 {
     return true;
 }