/// <summary> /// Returns the next machine to schedule. /// </summary> /// <param name="next">Next</param> /// <param name="choices">Choices</param> /// <param name="current">Curent</param> /// <returns>Boolean</returns> public bool TryGetNext(out MachineInfo next, IEnumerable <MachineInfo> choices, MachineInfo current) { var availableMachines = choices.Where( m => m.IsEnabled && !m.IsBlocked && !m.IsWaitingToReceive).ToList(); if (availableMachines.Count == 0) { availableMachines = choices.Where(m => m.IsWaitingToReceive).ToList(); if (availableMachines.Count == 0) { next = null; return(false); } } SChoice nextChoice = null; List <SChoice> scs = null; if (this.SchIndex < this.ScheduleStack.Count) { scs = this.ScheduleStack[this.SchIndex]; } else { scs = new List <SChoice>(); foreach (var task in availableMachines) { scs.Add(new SChoice(task.Machine.Id.Value)); } this.ScheduleStack.Add(scs); } nextChoice = scs.FirstOrDefault(val => !val.IsDone); if (nextChoice == null) { next = null; return(false); } if (this.SchIndex > 0) { var previousChoice = this.ScheduleStack[this.SchIndex - 1].Last(val => val.IsDone); previousChoice.IsDone = false; } next = availableMachines.Find(task => task.Machine.Id.Value == nextChoice.Id); nextChoice.IsDone = true; this.SchIndex++; if (next == null) { return(false); } this.ExploredSteps++; return(true); }
/// <inheritdoc/> public bool GetNextOperation(IEnumerable <AsyncOperation> ops, AsyncOperation current, bool isYielding, out AsyncOperation next) { var enabledOps = ops.Where(op => op.Status is AsyncOperationStatus.Enabled).ToList(); if (enabledOps.Count == 0) { next = null; return(false); } SChoice nextChoice = null; List <SChoice> scs = null; if (this.SchIndex < this.ScheduleStack.Count) { scs = this.ScheduleStack[this.SchIndex]; } else { scs = new List <SChoice>(); foreach (var task in enabledOps) { scs.Add(new SChoice(task.Id)); } this.ScheduleStack.Add(scs); } nextChoice = scs.FirstOrDefault(val => !val.IsDone); if (nextChoice is null) { next = null; return(false); } if (this.SchIndex > 0) { var previousChoice = this.ScheduleStack[this.SchIndex - 1].Last(val => val.IsDone); previousChoice.IsDone = false; } next = enabledOps.Find(task => task.Id == nextChoice.Id); nextChoice.IsDone = true; this.SchIndex++; if (next is null) { return(false); } this.ScheduledSteps++; return(true); }
/// <summary> /// Returns the next choice to schedule. /// </summary> /// <param name="next">Next</param> /// <param name="choices">Choices</param> /// <param name="current">Curent</param> /// <returns>Boolean</returns> public bool GetNext(out ISchedulable next, List <ISchedulable> choices, ISchedulable current) { var enabledChoices = choices.Where(choice => choice.IsEnabled).ToList(); if (enabledChoices.Count == 0) { next = null; return(false); } SChoice nextChoice = null; List <SChoice> scs = null; if (SchIndex < ScheduleStack.Count) { scs = ScheduleStack[SchIndex]; } else { scs = new List <SChoice>(); foreach (var task in enabledChoices) { scs.Add(new SChoice(task.Id)); } ScheduleStack.Add(scs); } nextChoice = scs.FirstOrDefault(val => !val.IsDone); if (nextChoice == null) { next = null; return(false); } if (SchIndex > 0) { var previousChoice = ScheduleStack[SchIndex - 1].Last(val => val.IsDone); previousChoice.IsDone = false; } next = enabledChoices.Find(task => task.Id == nextChoice.Id); nextChoice.IsDone = true; SchIndex++; if (next == null) { return(false); } ScheduledSteps++; return(true); }
/// <summary> /// Returns the next machine to schedule. /// </summary> /// <param name="next">Next</param> /// <param name="machines">Machines</param> /// <returns>Boolean value</returns> bool ISchedulingStrategy.TryGetNext(out TaskInfo next, List <TaskInfo> tasks) { var enabledTasks = tasks.Where(task => task.IsEnabled).ToList(); if (enabledTasks.Count == 0) { next = null; return(false); } SChoice nextChoice = null; List <SChoice> scs = null; if (this.SchIndex < this.ScheduleStack.Count) { scs = this.ScheduleStack[this.SchIndex]; } else { scs = new List <SChoice>(); foreach (var task in enabledTasks) { scs.Add(new SChoice(task.Machine.Id.Value)); } this.ScheduleStack.Add(scs); } nextChoice = scs.FirstOrDefault(val => !val.IsDone); if (nextChoice == null) { next = null; return(false); } if (this.SchIndex > 0) { var previousChoice = this.ScheduleStack[this.SchIndex - 1].Last(val => val.IsDone); previousChoice.IsDone = false; } next = enabledTasks.Find(task => task.Machine.Id.Value == nextChoice.Id); nextChoice.IsDone = true; this.SchIndex++; if (next == null) { return(false); } return(true); }
/// <summary> /// Returns the next task to schedule. /// </summary> /// <param name="next">Next</param> /// <param name="tasks">Tasks</param> /// <param name="currentTask">Curent task</param> /// <returns>Boolean value</returns> public bool TryGetNext(out TaskInfo next, List <TaskInfo> tasks, TaskInfo currentTask) { var enabledTasks = tasks.Where(task => task.IsEnabled).ToList(); if (enabledTasks.Count == 0) { next = null; return(false); } var availableTasks = enabledTasks.Where( task => !task.IsBlocked && !task.IsWaiting).ToList(); if (availableTasks.Count == 0) { next = null; return(false); } SChoice nextChoice = null; List <SChoice> scs = null; if (this.SchIndex < this.ScheduleStack.Count) { scs = this.ScheduleStack[this.SchIndex]; } else { scs = new List <SChoice>(); foreach (var task in availableTasks) { scs.Add(new SChoice(task.Machine.Id.Value)); } this.ScheduleStack.Add(scs); } nextChoice = scs.FirstOrDefault(val => !val.IsDone); if (nextChoice == null) { next = null; return(false); } if (this.SchIndex > 0) { var previousChoice = this.ScheduleStack[this.SchIndex - 1].Last(val => val.IsDone); previousChoice.IsDone = false; } next = availableTasks.Find(task => task.Machine.Id.Value == nextChoice.Id); nextChoice.IsDone = true; this.SchIndex++; if (next == null) { return(false); } if (!currentTask.IsCompleted) { this.SchedulingSteps++; } return(true); }