Example #1
0
    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);
        }
    }
Example #2
0
    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!");
        }
    }