Ejemplo n.º 1
0
        public IEnumerator ProcessQueue()
        {
            Started = true;
            var wait = new WaitUntil(() => (DroneQueue.Count > 0) && JobQueue.Count > 0 && (TimeKeeper.TimeSpeed != TimeSpeed.Pause));

            while (true)
            {
                if (DroneQueue.Count <= 0 || JobQueue.Count <= 0 || TimeKeeper.TimeSpeed == TimeSpeed.Pause)
                {
                    yield return(wait);
                }

                var drone = DroneQueue.Dequeue();
                if (drone.InPool)
                {
                    continue;
                }

                for (var i = _jobs.Length; i < JobQueue.Count; i++)
                {
                    _jobs.Add(new LLVStruct {
                        job = (SchedulingData)JobQueue[i]
                    });
                    _netLossValue.Add(0);
                }
                var num         = _jobs.Length;
                var initializer = new LLVInitializerJob
                {
                    Time    = TimeKeeper.Chronos.Get(),
                    Results = _jobs
                };
                var initJob = initializer.Schedule(num, 4);
                var summer  = new LLVSumJob
                {
                    jobs          = _jobs,
                    totalLosses   = _loss,
                    totalDuration = _duration
                };
                var sumJob     = summer.Schedule(initJob);
                var calculator = new LLVCalculatorJob
                {
                    time          = TimeKeeper.Chronos.Get(),
                    input         = summer.jobs,
                    totalLosses   = _loss,
                    totalDuration = _duration,
                    nlv           = _netLossValue
                };
                Scheduling = calculator.Schedule(num, 4, sumJob);
                yield return(new WaitUntil(() => Scheduling.IsCompleted));

                Scheduling.Complete();

                var n   = FindMin(ref calculator.nlv);
                var end = _jobs.Length - 1;
                var j   = JobQueue[n];
                var b   = j.Status == JobStatus.Failed;
                if (b || drone.AssignJob(j))
                {
                    if (b)
                    {
                        DroneQueue.Enqueue(drone);
                    }
                    _jobs.RemoveAtSwapBack(n);
                    _netLossValue.RemoveAtSwapBack(n);

                    JobQueue.RemoveAtSwapBack(n);
                    _owner.JobDequeued(j.IsDelayed);
                }
                // Clean Queue
                for (var i = JobQueue.Count - 1; i >= 0 && FailedInQueue > 0; i--)
                {
                    if (JobQueue[i].Status != JobStatus.Failed)
                    {
                        continue;
                    }
                    _owner.JobDequeued(JobQueue[i].IsDelayed);
                    JobQueue.RemoveAtSwapBack(i);
                    _jobs.RemoveAtSwapBack(i);
                    _netLossValue.RemoveAtSwapBack(i);
                    FailedInQueue--;
                }

                yield return(null);
            }
        }
Ejemplo n.º 2
0
 public void Complete()
 {
     Scheduling.Complete();
     Dispose();
 }