示例#1
0
        public static List <AllocOutput> GetAllocations(AllocInput allocInput)
        {
            List <AllocOutput> allocations   = new List <AllocOutput>();
            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 AllocOutput((allocations.Count + 1).ToString(), 0, newAllocation.EnergyConsumed, newAllocation.Processors);

            allocations.Add(allocOutput);

            return(allocations);
        }
示例#2
0
        public static List <AllocOutput> GetAllocations(AllocInput allocInput)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            List <AllocOutput> allocations = new List <AllocOutput>();
            uint trialCount = 0;

            while (stopWatch.ElapsedMilliseconds < MAX_DURATION_MS && allocations.Count < MAX_ALLOCATIONS)
            {
                Allocation newAllocation        = new Allocation(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)
                {
                    AllocOutput allocOutput        = new AllocOutput((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());
        }