コード例 #1
0
ファイル: Agent.cs プロジェクト: mbbarange/Mascaret
        //default parameters interval = -1, start = true
        public void addBehavior(string behaviorName, double interval, bool start)
        {
            if (getBehaviorByBame(behaviorName) != null)
            {
                return;
            }

            AgentBehavior behavior = new AgentBehavior(behaviorName);
            Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();


            BehaviorExecution be = behavior.createBehaviorExecution((InstanceSpecification)this, param, false);

            //if(be as OneShotBehaviorExecution !=null && start)
            {
                be = BehaviorScheduler.Instance.executeBehavior((Behavior)behavior, (InstanceSpecification)this, param, false);
                if (interval > 0.00)
                {
                    SimpleBehaviorExecution sbe = (SimpleBehaviorExecution)be;
                    if (sbe != null)
                    {
                        sbe.Interval = interval;
                    }
                }
                behaviorsExecution.Add((AgentBehaviorExecution)be);
            }
            behaviors.Add(behavior);
        }
コード例 #2
0
        public BehaviorExecution executeOperation(string name, List <ValueSpecification> p)
        {
            BehaviorExecution be = null;

            if (Classifier != null)
            {
                Operation op;
                if (Classifier.Operations.ContainsKey(name))
                {
                    op = Classifier.Operations[name];
                    Dictionary <string, ValueSpecification> behaviorParameters = new Dictionary <string, ValueSpecification>();
                    if (!op.createBehaviorParameters(p, behaviorParameters))
                    {
                        System.Console.WriteLine("Parameters are not correct");
                        return(be);
                    }

                    Behavior b = op.Method;
                    if (b != null)
                    {
                        be = BehaviorScheduler.Instance.executeBehavior(b, this, behaviorParameters, false);
                        //be.addCallBackOnBehaviorStop();
                    }
                }
            }
            if (be != null)
            {
                operationsExecution.Add(be);
            }
            return(be);
        }
コード例 #3
0
 protected void onBehaviorStopped(BehaviorExecution be)
 {
     if (operationsExecution.Contains(be))
     {
         operationsExecution.Remove(be);
     }
 }
コード例 #4
0
        public BehaviorExecution InstanciateOpaqueBehavior(Behavior behavior, string typeName, InstanceSpecification host, Dictionary <String, ValueSpecification> p)
        {
            //Assembly assembly = Assembly.GetExecutingAssembly();
            if (plugin != null)
            {
                Type type = plugin.GetType(typeName, true);

                BehaviorExecution be = null;
                if (type != null)
                {
                    be = (BehaviorExecution)(Activator.CreateInstance(type));
                }
                else
                {
                    return(MascaretApplication.Instance.VRComponentFactory.InstanciateOpaqueBehavior(behavior, typeName, host, p));
                }

                if (be != null)
                {
                    be.init(behavior, host, p, false);
                }
                return(be);
            }
            else
            {
                return(MascaretApplication.Instance.VRComponentFactory.InstanciateOpaqueBehavior(behavior, typeName, host, p));
            }
        }
コード例 #5
0
        protected void onBehaviorStop(BehaviorExecution be)
        {
            currentState.running = false;
            currentActionDone    = true;

            //  StreamWriter file = MascaretApplication.Instance.logfile; file.Flush();
            //  file.WriteLine("Behavior stopped");


            foreach (Transition currentTransition in currentState.Outgoing)
            {
                if (currentTransition.Trigger.Count == 0)
                {
                    if (currentTransition.Guard == null) //|| trans[iT]->getGuard()->eval(context))
                    {
                        Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();

                        Action effect = currentTransition.Effect;
                        if (effect != null)
                        {
                            BehaviorScheduler.Instance.executeBehavior(effect, this.Host, param, false);
                        }

                        activateState(currentTransition.Target, param);
                    }
                }
            }
        }
コード例 #6
0
        //sync =false
        public BehaviorExecution executeBehavior(Behavior behavior, InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
        {
            _updateCurrentVirtualTime();
            BehaviorExecution newBe = behavior.createBehaviorExecution(host, p, sync);

            if (newBe != null)
            {
                newBe.Start          = currentVirtualTime;
                newBe.LastCalledTime = currentVirtualTime;
                if (sync)
                {
                    newBe.execute(0.00);//remplacer le double par un timespan?
                }
                else
                {
                    //Debug.Log("Adding behavior : " + newBe.name);
                    allBehaviors.Add(newBe);
                    _insert(newBe, 0.00);
                }
            }
            else
            {
                System.Console.WriteLine("Error on adding behavior : " + behavior.name + " for " + host.name);
            }
            return(newBe);
        }
コード例 #7
0
ファイル: Agent.cs プロジェクト: mbbarange/Mascaret
        public virtual void start()
        {
            Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();

            foreach (Behavior behavior in this.Behaviors)
            {
                BehaviorExecution be = BehaviorScheduler.Instance.executeBehavior((Behavior)behavior, (InstanceSpecification)this, param, false);
                behaviorsExecution.Add((AgentBehaviorExecution)be);
            }
        }
コード例 #8
0
        public void reActivate(BehaviorExecution be)
        {
            if (be != null)
            {
                return;
            }

            deleteExecutionBehavior(be);
            allBehaviors.Add(be);
        }
コード例 #9
0
        public void onBehaviorStop(BehaviorExecution be)
        {
            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];
                procInfo.informActionDone(((Agent)(this.Host)).Aid, behaviorToNode[be]);
                sendActionDoneMessage(behaviorToNode[be], procInfo);
            }

            //restart();
            ispause = false;
        }
コード例 #10
0
ファイル: Agent.cs プロジェクト: mbbarange/Mascaret
        public AgentBehaviorExecution executeOneShotBehavior(string behaviorName)
        {
            AgentBehavior behavior = getBehaviorByBame(behaviorName);
            Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();

            BehaviorExecution be = behavior.createBehaviorExecution((InstanceSpecification)this, param, false);

            if (be as OneShotBehaviorExecution != null)
            {
                be = BehaviorScheduler.Instance.executeBehavior((Behavior)behavior, (InstanceSpecification)this, param, false);
                return((AgentBehaviorExecution)be);
            }
            return(null);
        }
コード例 #11
0
 protected void _onBehaviorRestarted(BehaviorExecution be)
 {
     if (be == null)
     {
         return;
     }
     foreach (BehaviorExecution currentBe in _suspendedBehaviors)
     {
         _insert(currentBe, 0);
         //currentBe = _suspendedBehaviors.Last;
         //COMMENT ON TRADUIT CE QUI SUIT?
         //_suspendedBehaviors[i]=_suspendedBehaviors.back();
         //_suspendedBehaviors.pop_back();
     }
 }
コード例 #12
0
 public void deleteExecutionBehavior(BehaviorExecution be)
 {
     if (be == null)
     {
         return;
     }
     allBehaviors.Remove(be);
     foreach (SchedInfo info in behaviors)
     {
         if (info.be == be)
         {
             behaviors.Remove(info);
             return;
         }
     }
 }
コード例 #13
0
 public void suspendExecutionBehavior(BehaviorExecution be)
 {
     if (be != null)
     {
         return;
     }
     _suspendedBehaviors.Add(be);
     //addCallbackOnBehaviorRestarted
     foreach (SchedInfo info in behaviors)
     {
         if (info.be == be)
         {
             behaviors.Remove(info);
             return;
         }
     }
 }
コード例 #14
0
        public new void simulate(InstanceSpecification entity)
        {
            BehaviorExecution be = null;

            if (isSubMachineState)
            {
                be = BehaviorScheduler.Instance.executeBehavior(submachine, entity, new Dictionary <string, ValueSpecification>(), false);
            }
            else if (!isSimple)
            {
                System.Console.WriteLine("!!!!!!!!!!! SUBREGION !!!!!!!");
            }

            if (doBehavior != null)
            {
                be = BehaviorScheduler.Instance.executeBehavior(doBehavior.Method, entity, new Dictionary <string, ValueSpecification>(), true);
            }
        }
コード例 #15
0
        public CallOperationBehaviorExecution(CallOperationAction paction, InstanceSpecification host, Dictionary <string, ValueSpecification> p)
            : base(paction, host, p, false)
        {
            this.action = paction;
            MascaretApplication.Instance.VRComponentFactory.Log("CallOperationAction : " + action.Operation.Method);

            foreach (ValuePin pin in action.ValuePins)
            {
                p.Add(pin.name, pin.ValueSpec);
            }
            MascaretApplication.Instance.VRComponentFactory.Log("READY TO Start");

            behaviorExecution = action.Operation.Method.createBehaviorExecution(this.Host, p, false);
            if (behaviorExecution == null)
            {
                MascaretApplication.Instance.VRComponentFactory.Log("Chérie ca va trancher");
            }
        }
コード例 #16
0
ファイル: OpaqueBehavior.cs プロジェクト: mbbarange/Mascaret
        public override BehaviorExecution createBehaviorExecution(InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("OPAQUEBEHAVIOR::CREATEBEHAVIOREXECUTION");

            Class cl = (Class)(host.Classifier);

            MascaretApplication.Instance.VRComponentFactory.Log(cl.getFullName());

            Class ocl = _lookForOperation(cl);

            if (ocl == null)
            {
                return(null);
            }

            string            typeName = ocl.name + "_" + body;
            BehaviorExecution be       = BehaviorScheduler.Instance.InstanciateOpaqueBehavior(this, typeName, host, p);

            return(be);
        }
コード例 #17
0
        protected bool activateState(Vertex state, Dictionary <string, ValueSpecification> p)
        {
            // StreamWriter file = MascaretApplication.Instance.logfile;

            //  file.WriteLine("Activating State : " + state.name); file.Flush();
            currentState = state;

            if (state as FinalState == null)
            {
                toStop = true;
            }

            be = currentState.activate(Host, p);

            if (be != null)
            {
                currentState.running = true;
                //callBack function
                be.addCallbackOnBehaviorStop(onBehaviorStop);
                currentActionDone = false;
            }


            foreach (Transition currentTransition in currentState.Outgoing)
            {
                foreach (Trigger currentTrigger in currentTransition.Trigger)
                {
                    if (currentTrigger.MEvent.Type == "ChangeEvent")
                    {
                        ChangeEvent ce  = currentTrigger.MEvent as ChangeEvent;
                        Expression  exp = (Expression)ce.ChangeExpression.clone();
                        //callBack function
                        //evalutateExpression function
                    }
                }
            }


            return(true);
        }
コード例 #18
0
        public override BehaviorExecution activate(InstanceSpecification entity, Dictionary <string, ValueSpecification> param)
        {
            BehaviorExecution be = null;

            if (isSubMachineState)
            {
                be = BehaviorScheduler.Instance.executeBehavior(submachine, entity, param, false);
            }
            else if (!isSimple)
            {
                System.Console.WriteLine("!!!!!!!!!!! SUBREGION !!!!!!!");
            }

            System.Console.WriteLine(" Running State : " + name + " : " + DoBehavior);

            if (doBehavior != null)
            {
                be = BehaviorScheduler.Instance.executeBehavior(doBehavior.Method, entity, param, false);
            }

            return(be);
        }
コード例 #19
0
        public void _insert(BehaviorExecution be, double dt)
        {
            if (be == null)
            {
                return;
            }

            _updateCurrentVirtualTime();

            TimeExpression nextTime = new TimeExpression(2000, 1, 1, 0, 0, 0);

            nextTime.TimeExp = currentVirtualTime.TimeExp + (long)(dt * 1000);
            foreach (SchedInfo info in behaviors)
            {
                if (nextTime.TimeExp < info.nextTime.TimeExp)
                {
                    //behaviors.AddBefore(new LinkedListNode<SchedInfo>(info), new SchedInfo(be,nextTime));
                    behaviors.AddBefore(behaviors.Find(info), new SchedInfo(be, nextTime));
                    return;
                }
            }

            behaviors.AddLast(new SchedInfo(be, nextTime));
        }
コード例 #20
0
        //default parameters sync = false
        public void start(InstanceSpecification host, Dictionary <string, InstanceSpecification> affectations, bool sync)
        {
            // StreamWriter file = MascaretApplication.Instance.logfile;
            if (action == null)
            {
                // file.WriteLine("Le noeud " + name + " n'a pas d'action associée!!!"); file.Flush();
                return;
            }

            Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();

            if (action.Kind == "SendSignal")
            {
                if (((SendSignalAction)action).Target == null)
                {
                    foreach (ActivityEdge currentEdge in Outgoing)
                    {
                        if (currentEdge.Target.Kind == "object")
                        {
                            if (affectations.ContainsKey(currentEdge.Target.name))
                            {
                                System.Console.WriteLine("Sending signal to : " + currentEdge.Target.name);
                                SendSignalAction ssAct = (SendSignalAction)action;
                                ssAct.Target        = new SendSignalTarget();
                                ssAct.Target.target = affectations[currentEdge.Target.name];
                            }

                            else
                            {
                                System.Console.WriteLine("affectation of " + currentEdge.Target.name + " not found");
                            }
                        }
                    }
                }
            }
            if (action.Kind == "CallOperation")
            {
                // file.WriteLine("Executing Call operation" + action.name + " " + ((CallOperationAction)action).Operation.getFullName()); file.Flush();

                if (((CallOperationAction)action).isDynamic())
                {
                    param = ((CallOperationAction)action).getParameters();
                }
                else
                {
                    foreach (InputPin currentPin in action.InputPins)
                    {
                        string paramName = currentPin.getIncomingObjectNode()[0].name;
                        //  file.WriteLine(" Looking for : " + paramName); file.Flush();
                        if (!affectations.ContainsKey(currentPin.getIncomingObjectNode()[0].name))
                        {
                            //        file.WriteLine(((CallOperationAction)action).Operation.getFullName() + " from " + action.Owner.name + " MISS " + currentPin.getIncomingObjectNode()[0].name); file.Flush();
                        }
                        InstanceValue val = new InstanceValue(affectations[currentPin.getIncomingObjectNode()[0].name]);
                        //    file.WriteLine("..... Trouve " + val.ToString()); file.Flush();
                        param.Add(currentPin.name, val);
                    }
                }

                if (Activity != null)
                {
                    //	action.Context(Activity.Context);
                }
            }
            currentExecution = BehaviorScheduler.Instance.executeBehavior(action, host, param, sync);
        }
コード例 #21
0
        protected void manageRequestAction(ACLMessage msg)
        {
            Agent agt = (Agent)(this.Host);

            string content = msg.Content;

            FIPASLParserResult result = parseFipaSLExpression(content);

            if (result.success)
            {
                if (result.isAction)
                {
                    bool done = false;

                    AgentBehavior behavior = agt.getBehaviorByBame(result.action.actionName);

                    if (behavior != null)
                    {
                        Dictionary <string, ValueSpecification> parameters = new Dictionary <string, ValueSpecification>();

                        if (result.action.paramName.Count > 0)
                        {
                            for (int i = 0; i < result.action.paramName.Count; i++)
                            {
                                LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                parameters.Add(result.action.paramName[i], (ValueSpecification)(stringValue));
                            }
                        }
                        else
                        {
                            for (int i = 0; i < result.action.paramName.Count; i++)
                            {
                                LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                parameters.Add("param" + i + '0', (ValueSpecification)(stringValue));
                            }
                        }

                        BehaviorScheduler.Instance.executeBehavior(behavior, agt, parameters, false);
                        ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                        reponse.Content = msg.Content;
                        reponse.Receivers.Add(msg.Sender);
                        agt.send(reponse);
                        done = true;
                    }

                    Class     classifier = agt.Classifier;
                    Operation operation  = null;
                    if (classifier != null && classifier.Operations.ContainsKey(result.action.actionName))
                    {
                        operation = classifier.Operations[result.action.actionName];
                        //System.Console.WriteLine("Operation:" + operation.getFullName());
                    }
                    if (operation != null)
                    {
                        Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();
                        List <Parameter> parameters = operation.Parameters;
                        List <string>    paramValue = result.action.paramValue;
                        List <string>    paramName  = result.action.paramName;

                        if (parameters.Count == paramValue.Count)
                        {
                            for (int i = 0; i < parameters.Count; i++)
                            {
                                // Pour tous les parametres issus de l'operation
                                string parameterName = parameters[i].name;

                                // Cherche l'indice de ce parameter dans paramsName
                                int indice = 0; bool found = false;
                                while (!found && indice < paramName.Count)
                                {
                                    if (paramName[indice] == parameterName)
                                    {
                                        found = true;
                                    }
                                    else
                                    {
                                        indice++;
                                    }
                                }

                                if (found)
                                {
                                    string strVal = paramValue[indice];

                                    System.Console.Write("Type : " + parameters[i].Type.getFullName());
                                    System.Console.Write(" - Name: " + parameters[i].name);
                                    System.Console.WriteLine(" - Value: " + strVal);

                                    string typeName = parameters[i].Type.getFullName();
                                    if (typeName == "boolean" || typeName == "integer" || typeName == "real" || typeName == "string")
                                    {
                                        param.Add(parameters[i].name, parameters[i].Type.createValueFromString(strVal.ToLower()));
                                    }
                                    else
                                    {
                                        try
                                        {
                                            InstanceSpecification inst = MascaretApplication.Instance.getEnvironment().getInstance(strVal.ToLower());
                                            param.Add(parameters[i].name, new InstanceValue(inst));
                                        }
                                        catch (NullReferenceException e)
                                        {
                                        }
                                    }
                                }
                            }

                            //BehaviorScheduler.Instance.executeBehavior(operation.Method, agt, param, false);

                            /*
                             *  List<ActionNode> possibleTranslation = _translateOperationToActions(operation);
                             *
                             *  shared_ptr<AgentBehaviorExecution> abe = agt->getBehaviorExecutionByName("ProceduralBehavior"); //hasslich... ja...
                             *  shared_ptr<ProceduralBehavior> pbe  = shared_dynamic_cast<ProceduralBehavior> (abe);
                             *
                             *  if (possibleTranslation.size() && pbe)
                             *  {
                             *      //add actionNode in ProceduralBehavior
                             *
                             *      pbe->pushActionToDo(possibleTranslation[0]);
                             *  }
                             *  else
                             *  {
                             *      //call method
                             */
                            BehaviorExecution be = BehaviorScheduler.Instance.executeBehavior(operation.Method, agt, param, false);

                            /*
                             * if (be != null)
                             * {
                             *  be.addCallbackOnBehaviorStop(bind(&SimpleCommunicationBehavior::_onBehaviorStop,this,_1));
                             *
                             *  _requestedAction[be->getSpecification()->getName()].push_back(msg->getSender());
                             * }*/
                            // }



                            ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                            reponse.Content = msg.Content;

                            System.Console.WriteLine("Content-Sent: " + reponse.Content);
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);
                        }
                        else
                        {
                            ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                            string     contentRep = "";
                            contentRep     += content;
                            reponse.Content = contentRep;
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);
                        }
                    }
                    else
                    {
                        string procName = result.action.actionName;
                        bool   found    = false;
                        OrganisationalEntity askedOrg  = null;
                        Procedure            askedProc = null;
                        Role askedRole = null;
                        List <OrganisationalEntity> orgs = agt.Plateform.Organisations;

                        for (int iOrg = 0; iOrg < orgs.Count; iOrg++)
                        {
                            List <RoleAssignement> assigns = orgs[iOrg].RoleAssignement;

                            for (int iAss = 0; iAss < assigns.Count; iAss++)
                            {
                                if (assigns[iAss].Agent.toString() == agt.Aid.toString())
                                {
                                    OrganisationalStructure os    = orgs[iOrg].Structure;
                                    List <Procedure>        procs = os.Procedures;

                                    for (int iP = 0; iP < procs.Count; iP++)
                                    {
                                        System.Console.WriteLine(procName + " / " + procs[iP].name);
                                        if (procs[iP].name == procName)
                                        {
                                            askedProc = procs[iP];
                                            askedOrg  = orgs[iOrg];
                                            askedRole = assigns[iAss].Role;
                                            found     = true;
                                        }
                                    }
                                }
                            }
                        }

                        if (found)
                        {
                            ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                            reponse.Content = msg.Content;
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);

                            // Recherche du comportement procedural
                            // UGGLY
                            //System.Console.WriteLine("1");
                            AgentBehaviorExecution pbehavior = agt.getBehaviorExecutingByName("ProceduralBehavior");

                            //AgentBehaviorExecution> behavior2 = agt->getBehaviorExecutionByName("ActionListenerBehavior");
                            //System.Console.WriteLine("2");
                            if (pbehavior != null)
                            {
                                ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior);

                                Dictionary <string, ValueSpecification> procParams = new Dictionary <string, ValueSpecification>();
                                for (int i = 0; i < result.action.paramName.Count; i++)
                                {
                                    LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                    procParams.Add(result.action.paramName[i], stringValue);
                                }

                                //System.Console.WriteLine("3");
                                Activity act = askedProc.Activity;
                                //List<ActivityNode>  nodes  = act.Nodes;

                                procBehave.pushProcedureToDo(askedProc, askedOrg, askedRole, procParams);
                                //procBehave.restart();

                                ACLMessage reponse2 = new ACLMessage(ACLPerformative.AGREE);
                                reponse2.Content = msg.Content;
                                reponse2.Receivers.Add(msg.Sender);
                                agt.send(reponse2);
                            }

                            /*
                             * else if (behavior2)
                             * {
                             *  shared_ptr<ActionListenerBehavior> procBehave  = shared_dynamic_cast<ActionListenerBehavior> (behavior2);
                             *
                             *  procBehave->pushProcedureToDo(askedProc, askedOrg, askedRole, Parameters());
                             *  procBehave->restart();
                             *
                             *  shared_ptr<ACLMessage> reponse = make_shared<ACLMessage>(AGREE);
                             *  reponse->setContent(msg->getContent());
                             *  reponse->addReceiver(msg->getSender());
                             *  agt->send(reponse);
                             * }*/
                            else
                            {
                                if (!done)
                                {
                                    ACLMessage reponse3   = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                                    string     contentRep = "";
                                    contentRep      += result.action.actionName;
                                    reponse3.Content = contentRep;
                                    reponse3.Receivers.Add(msg.Sender);
                                    agt.send(reponse3);
                                }
                            }
                        }
                        else
                        {
                            if (!done)
                            {
                                ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                                string     contentRep = "";
                                contentRep     += result.action.actionName;
                                reponse.Content = contentRep;
                                reponse.Receivers.Add(msg.Sender);
                                agt.send(reponse);
                            }
                        }
                    }
                }
                else
                {
                    // Proposition Non encore traite....
                }
            }
            else
            {
                System.Console.WriteLine("[SimpleCommunicationBehavior Warning] Parsing error. Message content parsing error: " + content);

                ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                string     contentRep = "";
                contentRep += content;

                reponse.Content = contentRep;
                reponse.Receivers.Add(msg.Sender);
                agt.send(reponse);
            }
        }
コード例 #22
0
        public override double execute(double dt)
        {
            //  StreamWriter file = MascaretApplication.Instance.logfile; file.Flush();
            //   file.WriteLine("StateMachine"); file.Flush();
            if (first)
            {
                // TODO: Attention a gerer plus tard : possibilite de fixe l'etat en cours a l'initialisation de l'instance
                // Recherche de l'etat Initial
                List <PseudoState> ps      = getStateMachine().ConnectionPoint;
                StateMachine       machine = getStateMachine();
                List <Region>      res     = machine.Region;

                bool foundInitialState = false;
                // file.WriteLine("Pseudo state : " + ps.Count); file.Flush();
                foreach (PseudoState pseudo in ps)
                {
                    if (pseudo.kind == PseudoStateKind.INITIAL)
                    {
                        Dictionary <string, ValueSpecification> p = new Dictionary <string, ValueSpecification>();
                        List <Transition> trans = pseudo.Outgoing;
                        foreach (Transition transition in trans)
                        {
                            //if (_currentState) _currentState->desactivate();
                            activateState(transition.Target, p);
                        }
                        //file.WriteLine("Found Initial"); file.Flush();
                        foundInitialState = true;
                        break;
                    }
                }
                if (!foundInitialState)
                {
                    toStop = true;
                }
                //toStop = foundInitialState ? false : true;
                first = false;
            }
            else
            {
                while (eventQueue.Count != 0)
                {
                    Vertex currentState = this.currentState;
                    if (currentState == null)//|| (currentState.Noninterpt && currentState.running))
                    {
                        break;
                    }

                    // if (this.Host.name == "tiroirProduits")
                    // file.WriteLine(" --->  " + this.Host.name + " stateMachine Behavior " + this.Specification.getFullName()+ " in " + currentState.getFullName()); file.Flush();

                    Trigger trigger = eventQueue[0];
                    eventQueue.RemoveAt(0);
                    List <Transition> trans = currentState.Outgoing;
                    MascaretApplication.Instance.VRComponentFactory.Log(" Trigger : " + trigger.name);
                    // file.WriteLine("Nb Trans : " + trans.Count); file.Flush();
                    for (int iT = 0; iT < trans.Count; iT++)
                    {
                        List <Trigger> transTriggers = trans[iT].Trigger;
                        //  file.WriteLine("Nb Triger : " + transTriggers.Count); file.Flush();
                        for (int i = 0; i < transTriggers.Count; i++)
                        {
                            Trigger transTrigger = transTriggers[i];
                            // if (this.Host.name == "tiroirProduits")
                            // file.WriteLine(" --->  " + this.Host.name + " " +  transTrigger.getFullName()); file.Flush();

                            if (transTrigger.equals(trigger))
                            {
                                Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();
                                //OclParser::Context context;
                                MascaretApplication.Instance.VRComponentFactory.Log(" Trigger OK");

                                MascaretEvent evt = trigger.MEvent;
                                if (evt != null && evt.Type == "SignalEvent")
                                {
                                    SignalEvent           sevt   = (SignalEvent)evt;
                                    InstanceSpecification signal = sevt.Signal;
                                    if (signal != null)
                                    {
                                        /*  // Gestion des parametres
                                         * map<string, shared_ptr<Slot> > props = signal->getSlots();
                                         * map<string, shared_ptr<Slot> >::iterator it;
                                         * for (it = props.begin(); it != props.end(); it++)
                                         * {
                                         *  vector<AnyValue> values;
                                         *  values.push_back((AnyValue)it->second->getValue()->getStringFromValue());
                                         *  context[it->first] = CollectionAnyValue(values);
                                         *  param[it->first] = it->second->getValue();
                                         *  cerr << it->first << " == " << it->second->getValue()->getStringFromValue() << endl;
                                         * }
                                         */
                                    }
                                }
                                //context["self"]=getHost();

                                if (trans[iT].Guard == null) //|| trans[iT]->getGuard()->eval(context))
                                {
                                    if (currentState != null)
                                    {
                                        if (be != null)
                                        {
                                            be.stop();
                                            BehaviorScheduler.Instance.deleteExecutionBehavior(be);
                                            be = null;
                                        }
                                        currentState.desactivate();
                                    }

                                    Action effect = trans[iT].Effect;
                                    if (effect != null)
                                    {
                                        MascaretApplication.Instance.VRComponentFactory.Log("Has effect");

                                        BehaviorScheduler.Instance.executeBehavior(effect, this.Host, param, false);
                                    }

                                    MascaretApplication.Instance.VRComponentFactory.Log("Activate new state : " + trans[iT].Target.name);
                                    activateState(trans[iT].Target, param);
                                }
                            }
                        }
                    }
                }

                //	if(eventQueue.Count == 0)
                //		pause();
                //toStop = true;
            }

            return(0.01);
            //if (toStop) return 0;
            //else return 0.001;
        }
コード例 #23
0
 public SchedInfo(BehaviorExecution b, TimeExpression time)
 {
     be       = b;
     nextTime = time;
 }