public bool ValidateTaskRAM(AllocationDisplay allocationDisplay, Configuration configuration) { int errorCount = 0; List <ProcessorAllocation> processorAllocations = allocationDisplay.ProcessorAllocations; for (int processorAllocatioNum = 0; processorAllocatioNum < processorAllocations.Count; processorAllocatioNum++) { ProcessorAllocation processorAllocation = processorAllocations[processorAllocatioNum]; int processorAllocationRAM = processorAllocation.RAM; int processorRAM = configuration.Processors[processorAllocatioNum].RAM; if (processorAllocationRAM > processorRAM) { Error error = new Error(); error.Message = $"The processor (ID={processorAllocatioNum}) of allocation (ID={allocationDisplay.ID}) " + $"has {processorRAM} GB RAM but requires {processorAllocationRAM} GB RAM"; error.ActualValue = $"{processorAllocationRAM} GB RAM"; error.ExpectedValue = $"Must be less than or equal to {processorRAM} GB RAM"; error.Filename = ValidationsManager.Filename; error.LineNumber = ""; error.ErrorCode = ErrorCode.INVALID_ALLOCATION; errorCount++; ValidationsManager.ErrorValidationManager.Errors.Add(error); } } return(errorCount == 0); }
public List <ProcessorAllocation> CalculateProcessorAllocationValues(Allocation allocation, Configuration configuration) { List <ProcessorAllocation> processorAllocations = new List <ProcessorAllocation>(); string[,] mapMatrix = allocation.MapMatrix; int numOfProcessors = mapMatrix.GetLength(0); // Number of rows int numOfTasks = mapMatrix.GetLength(1); // Number of columns string TASK_ON = "1"; for (int row = 0; row < numOfProcessors; row++) { ProcessorAllocation processorAllocation = new ProcessorAllocation(); processorAllocation.Allocation = ""; for (int col = 0; col < numOfTasks; col++) { string task = mapMatrix[row, col]; // Task distribution on each processor if (col == numOfTasks - 1) { processorAllocation.Allocation += $"{task}"; } else { processorAllocation.Allocation += $"{task},"; } // Calculate RAM, Upload, Donwload Task currentTask = configuration.Tasks[col]; if (task == TASK_ON) { processorAllocation.RAM = Math.Max(processorAllocation.RAM, currentTask.RAM); processorAllocation.Upload = Math.Max(processorAllocation.Upload, currentTask.Upload); processorAllocation.Download = Math.Max(processorAllocation.Download, currentTask.Download); } } processorAllocations.Add(processorAllocation); } return(processorAllocations); }