public static void executeIsolateOperation(string operation, Agent agt, Dictionary <string, ValueSpecification> spec) { Operation op = MascaretUtils.getOperation(operation, agt); if (op != null) { CallOperationAction act = new CallOperationAction(); act.Operation = op; BehaviorExecution be = act.createBehaviorExecution(agt, spec, false); PrintSingleton.Instance.log("Manually executing " + operation + " for " + agt.name); be.execute(0.0); } else { PrintSingleton.Instance.log("Operation " + operation + " not found for " + agt.name); } }
public override void init(Behavior specif, InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync) { base.init(specif, host, p, sync); agent = (Agent)host; ui = GameObject.Find("Canvas").GetComponent <EE_UI>(); ui.DecisionAgent = agent; if (agent.name == "PlayerAuto") { ui.DecisionAgent = MascaretUtils.getAgent("Player"); } agentC = GameObject.Find(ui.DecisionAgent.name).GetComponent <AgentController>(); ui = GameObject.Find("Canvas").GetComponent <EE_UI>(); }
public static float executeIsolateBehavior(string operation, Agent agt, Dictionary <string, string> spec) { float behaviorExecutionTime = 1.0f; Class cl = (Class)agt.Classifier; if (cl.hasOperation(operation)) { Operation op = cl.Operations[operation]; CallOperationAction act = new CallOperationAction(); act.Operation = op; Dictionary <string, ValueSpecification> param = MascaretUtils.getActionSpecification(spec); BehaviorExecution be = new CallOperationBehaviorExecution(act, agt, param); behaviorExecutionTime = (float)be.execute(0.00); } else { PrintSingleton.Instance.log("Operation " + operation + " not found for " + agt.name); } return(behaviorExecutionTime); }
override public double execute(double dt) { if (state == 0) { /* * ActionNode currentNode = MascaretUtils.getCurrentActionNode(agent); * MascaretHumanActions.changeConstraintValue(ui.DecisionAgent, "decisionValue", -1); * ui.decisionValue = -1; * choices = MascaretUtils.getOutgoingNodes(agent, currentNode); * MascaretHumanActions.setConstrainedEdges(MascaretUtils.getOutgoingEdges(agent, currentNode)); * PrintSingleton.Instance.log("==================================== DECISION ========================================== " + choices.Count); * ui.DisplayChoices(choices, agentC); */ ActionNode currentNode = MascaretUtils.getCurrentActionNode(agent); PrintSingleton.Instance.log("==================================== DECISION ========================================== " + currentNode.name); MascaretHumanActions.setConstrainedEdges(MascaretUtils.getOutgoingEdges(agent, currentNode)); ui.DisplayChoices(MascaretUtils.getOutgoingNodes(agent, currentNode), agentC); state++; MascaretHumanActions.changeConstraintValue(ui.DecisionAgent, "decisionValue", -1); return(Time.deltaTime); } else { if (ui.decisionValue != -1) { PrintSingleton.Instance.log("Decision : " + ui.decisionValue); return(0); } /*else * { * MascaretHumanActions.resetConstraints(); * return Time.deltaTime; * }*/ return(Time.deltaTime); } }
public static void executeOperationInActivity(Agent agent, string operation, Dictionary <string, string> spec, int index, CallProcedureBehaviorExecution pbe) { if (pbe != null) { ActivityPartition agentPartition = new ActivityPartition(agent.name); CallOperationAction act = new CallOperationAction(); act.Operation = MascaretUtils.getOperation(operation, agent); ActionNode an = new ActionNode(operation + "_" + index, "action"); an.Action = act; foreach (KeyValuePair <string, string> kvp in spec) { act.Arguments.Add(kvp.Key, kvp.Value); } an.Partitions = new List <ActivityPartition>(); an.Partitions.Add(agentPartition); AgentBehaviorExecution pbehavior = agent.getBehaviorExecutingByName("ProceduralBehavior"); if (pbehavior != null) { ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior); PrintSingleton.Instance.log(procBehave.RunningProcedures.Count); OrganisationalEntity askedOrg = MascaretApplication.Instance.AgentPlateform.Organisations.Find(x => x.name == pbe.action.OrganisationalEntity); Procedure askedProc = askedOrg.Structure.Procedures.Find(x => x.name == pbe.action.Procedure); Role askedRole = askedOrg.RoleAssignement.Find(x => x.Role.name == agent.name).Role; if (procBehave.RunningProcedures.Count == 0) //No runningProcedure for this agent, need to create one { Dictionary <string, ValueSpecification> procParams = new Dictionary <string, ValueSpecification>(); PrintSingleton.Instance.log("Launch procedure for " + agent.name); askedProc.Activity.Partitions.Add(agentPartition); procBehave.pushProcedureToDo(askedProc, askedOrg, askedRole, procParams); } //The new partition needs to be added to all agents.. Dictionary <string, Agent> allAgents = VRApplication.Instance.AgentPlateform.Agents; foreach (KeyValuePair <string, Agent> kvp in allAgents) { ProceduralBehavior pb = (ProceduralBehavior)kvp.Value.getBehaviorExecutingByName("ProceduralBehavior"); if (pb != null) { for (int iP = 0; iP < pb.runningProcedures.Count; iP++) { if (!pb.runningProcedures[iP].getAgentToPartition().ContainsKey(agent.Aid.toString())) { pb.runningProcedures[iP].getAgentToPartition().Add(agent.Aid.toString(), askedProc.Activity.Partitions.Find(x => x.name == agent.name)); } } } } executeOperation(an, agent); } else { PrintSingleton.Instance.log("Agent " + agent.name + " does not have a proceduralBehavior!"); } } else { PrintSingleton.Instance.log("No procedure launched!"); } }