Esempio n. 1
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;
                    }
                }
            }
        }
Esempio n. 2
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;
                    }
                }
            }
        }
Esempio n. 3
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;
                    }
                }
            }
        }
Esempio n. 4
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;
                    }
                }
            }
        }