// Finds unique correct allocations public List <TaskAllocationOutput> GetCorrectAllocs() { List <TaskAllocationOutput> allocations = new List <TaskAllocationOutput>(); var uniqueCorrectAllocs = this.correctAllocs.GroupBy(elem => elem.GetUniqueId()).Select(group => group.First()); foreach (var alloc in uniqueCorrectAllocs) { Dictionary <string, List <string> > processors = new Dictionary <string, List <string> >(); foreach (var proc in alloc.Processors) { processors.Add(proc.Value.Id, proc.Value.Tasks); } TaskAllocationOutput allocOutput = new TaskAllocationOutput((allocations.Count + 1).ToString(), alloc.ProgramRuntime, alloc.EnergyConsumed, processors); allocations.Add(allocOutput); } return(allocations); }
public static List <TaskAllocationOutput> GetAllocations(TaskAllocationInput allocInput) { List <TaskAllocationOutput> allocations = new List <TaskAllocationOutput>(); Allocation newAllocation = new Allocation(allocInput.Tasks.Count, allocInput.Processors, allocInput.Coefficients); var grid = new Grid(allocInput.Tasks, allocInput.Processors, allocInput.RefFrequency); while (!newAllocation.IsDone) { TaskAssignment newTaskAssignment = new TaskAssignment(grid); var taskRuntime = grid.Content[newTaskAssignment.TaskId][newTaskAssignment.ProcessorId]; newAllocation.AssignTaskToProcessor(newTaskAssignment.TaskId, newTaskAssignment.ProcessorId, taskRuntime); grid.UpdateProcessorRuntime(newTaskAssignment.ProcessorId, grid.GetRuntime(newTaskAssignment.TaskId, newTaskAssignment.ProcessorId)); grid.RemoveRow(newTaskAssignment.TaskId); } var allocOutput = new TaskAllocationOutput((allocations.Count + 1).ToString(), 0, newAllocation.EnergyConsumed, newAllocation.Processors); allocations.Add(allocOutput); return(allocations); }
private static string Allocation(TaskAllocationOutput allocOutput) { string output = $"Allocation ID = {allocOutput.AllocationId}, Time = {allocOutput.TimeConsumed}, Energy = {allocOutput.EnergyConsumed}"; output += Environment.NewLine; foreach (var processor in allocOutput.Processors) { output += "P" + processor.Key + ": "; for (int taskIndex = 0; taskIndex < processor.Value.Count; taskIndex++) { output += processor.Value.ElementAt(taskIndex); output += taskIndex == (processor.Value.Count - 1) ? "" : ", "; } output += Environment.NewLine; } output += Environment.NewLine; output += "--------------------------------------"; output += Environment.NewLine; output += Environment.NewLine; return(output); }
public static List <TaskAllocationOutput> GetAllocations(TaskAllocationInput allocInput) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <TaskAllocationOutput> allocations = new List <TaskAllocationOutput>(); uint trialCount = 0; while (stopWatch.ElapsedMilliseconds < Constants.MAX_PROGRAM_DURATION_MS && allocations.Count < MAX_ALLOCATIONS) { var newAllocation = new HeuristicAllocation(allocInput.Tasks.Count, allocInput.Processors, allocInput.Coefficients); var unassignedTasks = new Dictionary <string, float>(allocInput.Tasks); var processorRuntimes = new Dictionary <string, float>(); var shouldStopAllocating = false; while (!newAllocation.IsDone && !shouldStopAllocating) { var availableProcessors = new Dictionary <string, float>(allocInput.Processors); string longestRuntimeTaskId; string hiqhestFreqProcessorId; float taskRuntime; do { longestRuntimeTaskId = unassignedTasks.Aggregate((x, y) => x.Value > y.Value ? x : y).Key; hiqhestFreqProcessorId = availableProcessors.Aggregate((x, y) => x.Value > y.Value ? x : y).Key; taskRuntime = unassignedTasks[longestRuntimeTaskId] * (allocInput.RefFrequency / availableProcessors[hiqhestFreqProcessorId]); availableProcessors.Remove(hiqhestFreqProcessorId); if (!processorRuntimes.ContainsKey(hiqhestFreqProcessorId)) { processorRuntimes.Add(hiqhestFreqProcessorId, 0); } } while ((processorRuntimes[hiqhestFreqProcessorId] + taskRuntime) > (allocInput.MaxDuration - (trialCount * TIME_STEP)) && availableProcessors.Count != 0); if (!String.IsNullOrEmpty(hiqhestFreqProcessorId)) { newAllocation.AssignTaskToProcessor(longestRuntimeTaskId, hiqhestFreqProcessorId, taskRuntime); processorRuntimes[hiqhestFreqProcessorId] += taskRuntime; unassignedTasks.Remove(longestRuntimeTaskId); } else { shouldStopAllocating = true; } } float programRuntime = processorRuntimes.Max((x) => x.Value); if (newAllocation.IsDone && programRuntime <= allocInput.MaxDuration) { TaskAllocationOutput allocOutput = new TaskAllocationOutput((allocations.Count + 1).ToString(), programRuntime, newAllocation.EnergyConsumed, newAllocation.Processors); bool isAllocationUnique = true; // Check if the same allocation already exists foreach (var allocation in allocations) { if (allocation.GetUniqueId() == allocOutput.GetUniqueId()) { isAllocationUnique = false; } } if (isAllocationUnique) { allocations.Add(allocOutput); } } trialCount += 1; } return(allocations.ToList()); }