Пример #1
0
        /*public void instantiate(double dt)
        {

        }

        public void setValue(double time)
        {

        }

        public string getAsString()
        {
            return timeExp.ToString();
        }*/
        public static TimeExpression createTimeOfDay()
        {
            TimeExpression time = new TimeExpression(2014, 5, 1, 0, 0, 0);
            //time.TimeExp = DateTime.Now.ToOADate();
            time.TimeExp = DateTime.Now.Ticks / 10000;
            return time;
        }
Пример #2
0
        public void sendActionRealisationMessage(ActionNode action, ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the action start
            TimeExpression timestamp = action.CurrentExecution.Start;

            procMsg.Timestamp = timestamp;

            //set ACLMessage content
            string content = "((action ";

            content        += agt.name;
            content        += " ";
            content        += "(" + clean(action.name) + ")";
            content        += "))";
            procMsg.Content = content;

            //send message to other agents
            List <AID> agents = procInfo.getOtherAgents();

            for (int iA = 0; iA < agents.Count; iA++)
            {
                procMsg.Receivers.Add(agents[iA]);
            }
            agt.send(procMsg);
        }
Пример #3
0
        public void sendActionDoneMessage(ActionNode action, ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the action finished
            TimeExpression timestamp = action.CurrentExecution.Finish;

            procMsg.Timestamp = timestamp;

            //set ACLMessage content
            string content = "((done (action ";

            content        += agt.name;
            content        += " ";
            content        += "(" + clean(action.name) + ")";
            content        += ")))";
            procMsg.Content = content;
            //MascaretApplication.Instance.VRComponentFactory.Log(content);

            //send message to other agents
            List <AID> agents = procInfo.getOtherAgents();

            for (int iA = 0; iA < agents.Count; iA++)
            {
                procMsg.Receivers.Add(agents[iA]);
            }
            agt.send(procMsg);
        }
Пример #4
0
        /*public void instantiate(double dt)
         * {
         *
         * }
         *
         * public void setValue(double time)
         * {
         *
         * }
         *
         * public string getAsString()
         * {
         *  return timeExp.ToString();
         * }*/

        public static TimeExpression createTimeOfDay()
        {
            TimeExpression time = new TimeExpression(2014, 5, 1, 0, 0, 0);

            //time.TimeExp = DateTime.Now.ToOADate();
            time.TimeExp = DateTime.Now.Ticks / 10000;
            return(time);
        }
Пример #5
0
        protected void _updateCurrentVirtualTime()
        {
            TimeExpression currentRealTime = TimeExpression.createTimeOfDay();

            //Debug.Log(currentRealTime.TimeExp);
            if (!suspended)
            {
                //currentVirtualTime.TimeExp +=(currentRealTime.TimeExp-lastRealTimeCheck.TimeExp)*virtualTimeSpeedFactor;
                currentVirtualTime = currentRealTime;
            }

            lastRealTimeCheck = currentRealTime;
        }
Пример #6
0
        public void Awake()
        {
            suspended = false;
            cycle     = 0;
            virtualTimeSpeedFactor = 1.0;
            totalSuspendedRealTime = 0.00;

            TimeExpression currentRealTime = TimeExpression.createTimeOfDay();

            startRealTime      = currentRealTime;
            lastRealTimeCheck  = currentRealTime;
            startVirtualTime   = currentRealTime;
            currentVirtualTime = currentRealTime;
        }
Пример #7
0
        public void setSuspended(bool val)
        {
            TimeExpression currentRealTime = TimeExpression.createTimeOfDay();

            if (suspended && !val)
            {
                _updateCurrentVirtualTime();
                totalSuspendedRealTime += currentRealTime.TimeExp - startSuspendTime.TimeExp;
                suspended = false;
            }
            else if (suspended && val)
            {
                _updateCurrentVirtualTime();
                startSuspendTime = TimeExpression.createTimeOfDay();
                suspended        = true;
            }
        }
Пример #8
0
        public void forceCurrentVirtualTime(TimeExpression exp)
        {
            long dt = currentVirtualTime.TimeExp - startVirtualTime.TimeExp;
            LinkedList <SchedInfo> new_behaviors = new LinkedList <SchedInfo>();

            foreach (SchedInfo info in behaviors)
            {
                dt = info.nextTime.TimeExp - currentVirtualTime.TimeExp;
                TimeExpression nextTime = exp;
                nextTime.TimeExp += dt;
                new_behaviors.AddLast(new SchedInfo(info.be, nextTime));
            }

            behaviors          = new_behaviors;
            currentVirtualTime = exp;
            exp.TimeExp       -= dt;
            startVirtualTime   = exp;
        }
Пример #9
0
        public void sendProcedureDoneMessage(ProcedureExecution procInfo)
        {
            Agent agt = (Agent)(this.Host);

            ACLMessage procMsg = new ACLMessage(ACLPerformative.INFORM);

            //we inform at wich time the procedure finish
            TimeExpression timestamp = BehaviorScheduler.Instance.getCurrentVirtualTime();

            procMsg.Timestamp = timestamp;

            string content = "((done (action ";

            content        += agt.name;
            content        += " ";
            content        += "(" + clean(procInfo.procedure.name) + ")";
            content        += ")))";
            procMsg.Content = content;

            procMsg.Receivers.Add(MascaretApplication.Instance.Agent.Aid);

            agt.send(procMsg);
        }
Пример #10
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));
        }
Пример #11
0
 public SchedInfo(BehaviorExecution b, TimeExpression time)
 {
     be       = b;
     nextTime = time;
 }
Пример #12
0
 private BehaviorScheduler()
 {
     behaviors          = new LinkedList <SchedInfo>();
     allBehaviors       = new List <BehaviorExecution>();
     currentVirtualTime = new TimeExpression(2000, 1, 1, 0, 0, 0);
 }
Пример #13
0
 public void setSuspended(bool val)
 {
     TimeExpression currentRealTime = TimeExpression.createTimeOfDay();
     if (suspended && !val)
     {
         _updateCurrentVirtualTime();
         totalSuspendedRealTime += currentRealTime.TimeExp - startSuspendTime.TimeExp;
         suspended = false;
     }
     else if (suspended && val)
     {
         _updateCurrentVirtualTime();
         startSuspendTime = TimeExpression.createTimeOfDay();
         suspended = true;
     }
 }
Пример #14
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));
        }
Пример #15
0
 private BehaviorScheduler()
 {
     behaviors = new LinkedList<SchedInfo>();
     allBehaviors = new List<BehaviorExecution>();
     currentVirtualTime = new TimeExpression(2000, 1, 1, 0, 0, 0);
 }
Пример #16
0
 public double getElapsedRealTime()
 {
     return(TimeExpression.createTimeOfDay().TimeExp - startRealTime.TimeExp - totalSuspendedRealTime);
 }
Пример #17
0
        //anciennement _activate de la classe c++
        public void Update()
        {
            //si on est suspendu on update rien

            //Debug.Log(behaviors.Count);
            //Debug.Log(allBehaviors.Count);

            LinkedList <SchedInfo> behaviorsToAdd = new LinkedList <SchedInfo>();

            if (!suspended)
            {
                _jumpToNext();
                _updateCurrentVirtualTime();
                //Debug.Log(" ############################################################################ ");
                while (behaviors.Count > 0)
                {
                    TimeExpression virtualTime = currentVirtualTime;
                    SchedInfo      si          = behaviors.First.Value;
                    //Debug.Log("Comparing : " + si.nextTime.TimeExp + " : " + virtualTime.TimeExp);
                    if (si.nextTime.TimeExp > virtualTime.TimeExp)
                    {
                        break;
                    }
                    else
                    {
                        if (si.be.IsSuspended)
                        {
                            suspendExecutionBehavior(si.be);
                            continue;
                        }
                        if (si.be.IsFinished)
                        {
                            si.be.Finish = virtualTime;
                            deleteExecutionBehavior(si.be);
                            continue;
                        }

                        double dt = (virtualTime.TimeExp - si.be.LastCalledTime.TimeExp) / 10000;
                        //Debug.Log(" DT reel d'execution : " + dt);
                        double next_dt = si.be.execute(dt);

                        si.be.LastCalledTime = virtualTime;


                        if (next_dt > 0.00)
                        {
                            si.nextTime.TimeExp = (long)(next_dt * 1000);
                            behaviorsToAdd.AddLast(si);
                        }
                        else
                        {
                            si.be.stop();
                            si.be.Finish = virtualTime;
                            allBehaviors.Remove(si.be);
                        }

                        behaviors.RemoveFirst();
                    }
                }
                foreach (SchedInfo info in behaviorsToAdd)
                {
                    _insert(info.be, (info.nextTime.TimeExp / 1000));
                }

                cycle++;
            }
        }
Пример #18
0
        protected void _updateCurrentVirtualTime()
        {
            TimeExpression currentRealTime = TimeExpression.createTimeOfDay();
            //Debug.Log(currentRealTime.TimeExp);
            if (!suspended)
            {
                //currentVirtualTime.TimeExp +=(currentRealTime.TimeExp-lastRealTimeCheck.TimeExp)*virtualTimeSpeedFactor;
                currentVirtualTime = currentRealTime;
            }

            lastRealTimeCheck = currentRealTime;
        }
Пример #19
0
        public void forceCurrentVirtualTime(TimeExpression exp)
        {
            long dt = currentVirtualTime.TimeExp - startVirtualTime.TimeExp;
            LinkedList<SchedInfo> new_behaviors = new LinkedList<SchedInfo>();
            foreach (SchedInfo info in behaviors)
            {
                dt = info.nextTime.TimeExp - currentVirtualTime.TimeExp;
                TimeExpression nextTime = exp;
                nextTime.TimeExp += dt;
                new_behaviors.AddLast(new SchedInfo(info.be, nextTime));
            }

            behaviors = new_behaviors;
            currentVirtualTime = exp;
            exp.TimeExp -= dt;
            startVirtualTime = exp;
        }
Пример #20
0
 public SchedInfo(BehaviorExecution b, TimeExpression time)
 {
     be = b;
     nextTime = time;
 }
Пример #21
0
        public void Awake()
        {
            suspended = false;
            cycle = 0;
            virtualTimeSpeedFactor = 1.0;
            totalSuspendedRealTime = 0.00;

            TimeExpression currentRealTime = TimeExpression.createTimeOfDay();

            startRealTime = currentRealTime;
            lastRealTimeCheck = currentRealTime;
            startVirtualTime = currentRealTime;
            currentVirtualTime = currentRealTime;
        }