Пример #1
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;
                    }
                }
            }
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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;
 }
Пример #7
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;
                    }
                }
            }
        }
Пример #8
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;
                    }
                }
            }
        }
Пример #9
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;
        }
Пример #10
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;
        }
Пример #11
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;
        }
Пример #12
0
 List<TimeExpression> getAllActionsDoneTimestampsBy(AID agent)
 {
     return allActionsDoneTimestamps[agent.toString()];
 }
Пример #13
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;
                    }
                }
            }
        }
Пример #14
0
 List <TimeExpression> getAllActionsDoneTimestampsBy(AID agent)
 {
     return(allActionsDoneTimestamps[agent.toString()]);
 }