public static ProcedureExecution getCurrentProcedureExecution(Agent agt) { ProceduralBehavior proceduralBehavior = (ProceduralBehavior)(agt.getBehaviorExecutingByName("ProceduralBehavior")); List <ProcedureExecution> procedureExecutions = new List <ProcedureExecution>(); if (proceduralBehavior != null) { procedureExecutions = proceduralBehavior.runningProcedures; } if (procedureExecutions.Count != 0) { foreach (ProcedureExecution procExe in procedureExecutions) { List <ActionNode> allActions = procExe.getAllActionsFor(agt.Aid); if (allActions != null) { foreach (ActionNode action in allActions) { if (action.isRunning()) { return(procExe); } } } } } //Return null if initialization is not over return(null); }
public static ActionNode getCurrentActionNode(Agent agt) { ProceduralBehavior proceduralBehavior = (ProceduralBehavior)(agt.getBehaviorExecutingByName("ProceduralBehavior")); List <ProcedureExecution> procedureExecutions = new List <ProcedureExecution>(); if (proceduralBehavior != null) { procedureExecutions = proceduralBehavior.runningProcedures; } if (procedureExecutions.Count != 0) { foreach (ProcedureExecution procExe in procedureExecutions) { List <ActionNode> allActions = procExe.getAllActionsFor(agt.Aid); if (allActions != null) { foreach (ActionNode action in allActions) { if (action.isRunning() && action.CurrentExecution.GetType() == typeof(CallOperationBehaviorExecution)) { Debug.Log("::::::::::::::::::::::::: " + procExe.procedure.name); return(action); } } } } } //Return null if initialization is not over return(null); }
public static List <ActivityEdge> getOutgoingEdges(Agent agt, ActionNode node) { ProceduralBehavior proceduralBehavior = (ProceduralBehavior)(agt.getBehaviorExecutingByName("ProceduralBehavior")); if (proceduralBehavior != null) { if (node != null) { List <ActivityEdge> outgoEdges = node.getOutgoingActionNodeEdges(); return(outgoEdges); } } return(null); }
public static void onBehaviorStop(BehaviorExecution be) { ProceduralBehavior proceduralBehavior = (ProceduralBehavior)(((Agent)be.Host).getBehaviorExecutingByName("ProceduralBehavior")); proceduralBehavior.BehaviorToNode[be].CurrentExecution.Finish = BehaviorScheduler.Instance.getCurrentVirtualTime(); for (int iP = 0; iP < proceduralBehavior.RunningProcedures.Count; iP++) { ProcedureExecution procInfo = proceduralBehavior.runningProcedures[iP]; procInfo.informActionDone(((Agent)(proceduralBehavior.Host)).Aid, proceduralBehavior.BehaviorToNode[be]); proceduralBehavior.sendActionDoneMessage(proceduralBehavior.BehaviorToNode[be], procInfo); } //restart(); proceduralBehavior.ispause = false; }
public static List <ActionNode> getOutgoingNodes(Agent agt, ActionNode node) { ProceduralBehavior proceduralBehavior = (ProceduralBehavior)(agt.getBehaviorExecutingByName("ProceduralBehavior")); if (proceduralBehavior != null) { if (node != null) { List <ActionNode> outgoNodes = node.getOutgoingActionNode(); Debug.Log(outgoNodes.Count); return(outgoNodes); } } return(null); }
public static bool agentIsPlaying(Agent agt) { List <ProceduralBehavior> proceduralBehaviors = GameObject.Find("MascaretApplication").GetComponent <UnityMascaretApplication>().ProcedureBehaviorExecution.ProceduralBehaviors; ProceduralBehavior proceduralBehavior = (ProceduralBehavior)agt.getBehaviorExecutingByName("ProceduralBehavior"); if (proceduralBehavior != null) { if (proceduralBehavior.runningProcedures.Count > 0) { ProcedureExecution procExec = proceduralBehavior.runningProcedures[proceduralBehavior.runningProcedures.Count - 1]; List <ActionNode> nodesToExecute = procExec.getActionToExecuteFor(agt.Aid); if (nodesToExecute.Count > 0) { return(true); } } } return(false); }
public static void executeOperation(ActionNode action, Agent agt) { PrintSingleton.Instance.log("Executing " + action.name + " by " + agt.name); ProceduralBehavior proceduralBehavior = (ProceduralBehavior)(agt.getBehaviorExecutingByName("ProceduralBehavior")); for (int iP = 0; iP < proceduralBehavior.runningProcedures.Count; iP++) { ProcedureExecution procInfo = proceduralBehavior.runningProcedures[iP]; action.start(agt, procInfo.getAffectations(), false); proceduralBehavior.sendActionRealisationMessage(action, procInfo); procInfo.informActionRunning(agt.Aid, action); if (action.CurrentExecution != null) { proceduralBehavior.BehaviorToNode.Add(action.CurrentExecution, action); action.CurrentExecution.addCallbackOnBehaviorStop(onBehaviorStop); } else { procInfo.informActionDone(agt.Aid, action); proceduralBehavior.sendActionDoneMessage(action, procInfo); } } }
public static ActionNode getNextNodeToExecute(Agent agt) { List <ProceduralBehavior> proceduralBehaviors = GameObject.Find("MascaretApplication").GetComponent <UnityMascaretApplication>().ProcedureBehaviorExecution.ProceduralBehaviors; PrintSingleton.Instance.log("Agent : " + agt.name); ProceduralBehavior proceduralBehavior = (ProceduralBehavior)agt.getBehaviorExecutingByName("ProceduralBehavior"); if (proceduralBehavior != null) { if (proceduralBehavior.runningProcedures.Count > 0) { PrintSingleton.Instance.log("Procedures : " + proceduralBehavior.runningProcedures.Count); ProcedureExecution procExec = proceduralBehavior.runningProcedures[proceduralBehavior.runningProcedures.Count - 1]; List <ActionNode> nodesToExecute = procExec.getActionToExecuteFor(agt.Aid); List <ActivityNode> activeNodes = new List <ActivityNode>(); foreach (ActivityExecutionToken t in procExec.getActiveToken()) { activeNodes.Add(t.currentLocation); } foreach (ActivityNode t in activeNodes) { List <ActionNode> outgoActions = t.getOutgoingActionNode(); foreach (ActionNode n in outgoActions) { if (!n.isRunning() && nodesToExecute.Contains(n)) { PrintSingleton.Instance.log("Action to execute : " + n.name); return(n); } } } } } return(null); }
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!"); } }