/// <summary> /// Generates a list of processes /// </summary> /// <returns></returns> public static List <ProcessDTO> GenerateList() { //Create a list to store processes in List <ProcessDTO> processList = new List <ProcessDTO>(); //seed with total seconds Random rand = new Random(DateTime.Now.Millisecond); //Set the total number of processes int totalProcesses = rand.Next(10, 20); //create the processes for (int i = 0; i < totalProcesses; i++) { ProcessDTO process = new ProcessDTO(); process.ProcessId = i; process.Priority = rand.Next(0, 5); process.ArrivalTime = rand.Next(0, 5); process.BurstTime = rand.Next(5, 25); process.RemainingTime = process.BurstTime; processList.Add(process); } var sortedList = processList.OrderBy(a => a.ArrivalTime); return(sortedList.ToList()); }
/// <summary> /// Calculates the aditional wait to add to the process /// </summary> /// <param name="process"></param> /// <param name="remainingTime"></param> /// <param name="totalWaits"></param> private void CalculateWait(ProcessDTO process, int remainingTime, int totalWaits) { //if this is the first execution, there is no wait to calculate if (totalWaits == 0 && remainingTime == 10) { process.WaitTime = 0; return; } //calculate the number of full cycles before this process has been reached int waitDiff = totalWaits - process.lastProcess; //calculate the exact time since the process has been touched process.WaitTime += (waitDiff * QUANTUM) + (QUANTUM - remainingTime); }