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); }
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); }
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); }
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); } }