public List <TaskAllocationOutput> GetAllocations(TaskAllocationInput input) { var GA = new GAAlg(input.Tasks, input.Processors, input.Coefficients, input.RefFrequency, input.MaxDuration); GA.Train(); return(GA.GetCorrectAllocs()); }
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); }
public List <TaskAllocationOutput> GetAllocations(TaskAllocationInput input) { return(HeuristicAlg.GetAllocations(input)); }
public List <TaskAllocationOutput> GetAllocations(TaskAllocationInput input) { return(SortMidAlg.SortMidAlg.GetAllocations(input)); }
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()); }
// Get allocations from services on button-click private async void getAllocationsButton_Click(object sender, EventArgs e) { this.startReading(); string fileUrlInputBox = urlInputBox.Text.Trim(); string fileUrlComboxBox = filePathsComboBox.Text.Trim(); string fileUrl = String.IsNullOrEmpty(fileUrlInputBox) ? fileUrlComboxBox : ""; try { // Read a remote config file string fileContent = FileReader.ReadFromUrl(fileUrl); this.clearOutput(); // Parse the config file ConfigFile configFile = new ConfigFile(fileContent); var allocInput = new TaskAllocationInput(configFile.Tasks, configFile.Processors, configFile.MaxDuration, configFile.RefFrequency, configFile.Coefficients); var allocations = new List <TaskAllocationOutput>(); // Create all service clients var GAServiceClient = new AWSGAServiceReference.GAServiceClient(); var heuristicClient = new AWSHeuristicServiceReference.HeuristicServiceClient(); var sortMidClient = new AWSSortMidServiceReference.SortMidServiceClient(); // Get allocations from SortMid Service var sortMidTask = Task.Factory.StartNew(() => { var sortMidAllocs = sortMidClient.GetAllocations(allocInput); allocations.AddRange(sortMidAllocs); }); // Get allocations from Heuristic Service var heuristicTask = Task.Factory.StartNew(() => { var heuristicAllocs = heuristicClient.GetAllocations(allocInput); allocations.AddRange(heuristicAllocs); }); // Get allocations from GA Service var GATask = Task.Factory.StartNew(() => { var GAAllocs = GAServiceClient.GetAllocations(allocInput); allocations.AddRange(GAAllocs); }); // UI feedback this.printWaitingTime(); // Wait for response from all the services await Task.WhenAll(sortMidTask, GATask, heuristicTask); // Print correct allocations var topAllocations = allocations.OrderBy(a => a.EnergyConsumed).Take(3).ToList(); string formattedAllocations = Visualizer.Allocations(topAllocations); this.printRow(); this.printRow(formattedAllocations); // Close the service clients GAServiceClient.Close(); heuristicClient.Close(); GAServiceClient.Close(); } catch (Exception ex) { this.clearOutput(); this.printRow(ex.Message); } }