public IEnumerator ProcessQueue() { Started = true; var wait = new WaitUntil(() => (DroneQueue.Count > 0) && JobQueue.Count > 0 && (TimeKeeper.TimeSpeed != TimeSpeed.Pause)); while (true) { yield return(wait); while (DroneQueue.Count > 0 && JobQueue.Count > 0 && TimeKeeper.TimeSpeed != TimeSpeed.Pause) { var drone = DroneQueue.Dequeue(); if (drone.InPool) { continue; } var j = JobQueue[0]; if (j.Status == JobStatus.Failed || drone.AssignJob(j)) { _owner.JobDequeued(j.IsDelayed); JobQueue.RemoveAt(0); } for (var i = JobQueue.Count - 1; i >= 0 && FailedInQueue > 0; i--) { if (JobQueue[i].Status != JobStatus.Failed) { continue; } _owner.JobDequeued(JobQueue[i].IsDelayed); JobQueue.RemoveAt(i); FailedInQueue--; } yield return(null); } } }
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; } Scheduling.Complete(); for (var i = _jobs.Length; i < JobQueue.Count; i++) { _jobs.Add(new EPStruct { job = (SchedulingData)JobQueue[i] }); } for (var i = _precedence.Length; i < JobQueue.Count * JobQueue.Count; i++) { _precedence.Add(0); } var num = _jobs.Length; var initializer = new EpInitializerJob { Time = TimeKeeper.Chronos.Get(), Results = _jobs }; var initJob = initializer.Schedule(num, 4); var calculator = new EpCalculatorJob { Time = TimeKeeper.Chronos.Get(), Input = _jobs, Ep = _precedence }; Scheduling = calculator.Schedule(num, 1, initJob); yield return(new WaitUntil(() => Scheduling.IsCompleted)); Scheduling.Complete(); var n = FindMax(ref calculator.Ep); 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); JobQueue.RemoveAtSwapBack(n); var sq = end * end; while (_precedence.Length != sq) { _precedence.RemoveAtSwapBack(0); } _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); var x = _jobs.Length * _jobs.Length; while (_precedence.Length != x) { _precedence.RemoveAtSwapBack(0); } FailedInQueue--; } yield return(null); } }
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); } }