Пример #1
0
        /// <summary>
        /// Run the Lottery scheduler on the data
        /// </summary>
        /// <param name="testData"></param>
        /// <returns>Average turnaround time</returns>
        public int Run(string testData)
        {
            ReadTestData(testData);

            Random random = new Random();
            int    randNum;

            // Do lottery
            while (ProcessQueue.Count > 0)
            {
                randNum = random.Next(0, _calcTotalPriority());

                bool winner = false;
                for (int i = 0; !winner; i++)
                {
                    randNum -= ((Process)ProcessQueue[i]).Priority;
                    if (randNum <= 0)
                    {
                        // Check burst
                        Process tempProcess = (Process)ProcessQueue[i];

                        CSVProcess csvProc = new CSVProcess
                        {
                            Pid            = tempProcess.Pid,
                            CPUTime        = CPUTime,
                            StartBurstTime = tempProcess.BurstTime,
                        };

                        tempProcess.BurstTime -= TIMEQ;
                        if (tempProcess.BurstTime <= 0)
                        {
                            csvProc.EndBurstTime = 0;
                            csvProc.Complete     = true;
                            CPUTime             += tempProcess.BurstTime + TIMEQ;
                            TotalTurnAroundTime += CPUTime;
                            ProcessQueue.RemoveAt(i);
                        }
                        else
                        {
                            csvProc.EndBurstTime = tempProcess.BurstTime;
                            csvProc.Complete     = false;
                            CPUTime        += TIMEQ;
                            ProcessQueue[i] = tempProcess;
                        }
                        CsvProcesses.Add(csvProc);
                        winner = true;
                    }
                    CPUTime += SwitchTime;
                }
            }
            return(GetAvgTurnAroundTime());
        }
Пример #2
0
 private static CSVProcess _completeCSVProcess(CSVProcess csvProc, int burstTime)
 {
     if (burstTime <= 0)
     {
         csvProc.EndBurstTime = 0;
         csvProc.Complete     = true;
     }
     else
     {
         csvProc.EndBurstTime = burstTime;
         csvProc.Complete     = false;
     }
     return(csvProc);
 }
Пример #3
0
        /// <summary>
        /// Run the Round Robin scheduler on the data with specified time quantum
        /// </summary>
        /// <param name="testData"></param>
        /// <returns>Average turnaround time</returns>
        public int Run(string testData)
        {
            ReadTestData(testData);

            // Loop till all elements removed from ArrayList
            while (ProcessQueue.Count > 0)
            {
                // Round Robin subtracting
                for (int i = 0; i < ProcessQueue.Count; i++)
                {
                    Process proc  = (Process)ProcessQueue[i];
                    int     burst = proc.BurstTime;
                    proc.BurstTime  = burst - _timeQ;
                    ProcessQueue[i] = proc;

                    CSVProcess csvProc = new CSVProcess
                    {
                        Pid            = proc.Pid,
                        CPUTime        = CPUTime,
                        StartBurstTime = burst,
                    };

                    if (proc.BurstTime <= 0)
                    {
                        ProcessQueue.RemoveAt(i);
                        CPUTime             += _timeQ - burst;
                        TotalTurnAroundTime += CPUTime;
                        i--;
                    }
                    else
                    {
                        CPUTime += _timeQ;
                    }

                    CsvProcesses.Add(_completeCSVProcess(csvProc, proc.BurstTime));
                    CPUTime += SwitchTime;
                }
            }

            // Remove last CPU time for switch since not necessary
            CPUTime -= SwitchTime;

            return(GetAvgTurnAroundTime());
        }
Пример #4
0
        /// <summary>
        /// Add all of the bursttimes with switch times
        /// </summary>
        protected void AddBurstTimes()
        {
            foreach (Process currProc in ProcessQueue)
            {
                CSVProcess csvProc = new CSVProcess
                {
                    Pid            = currProc.Pid,
                    CPUTime        = CPUTime,
                    StartBurstTime = currProc.BurstTime,
                    EndBurstTime   = 0,
                    Complete       = true
                };

                CPUTime             += currProc.BurstTime;
                TotalTurnAroundTime += CPUTime;
                CsvProcesses.Add(csvProc);

                CPUTime += SwitchTime;
            }
            // Remove last CPU time for switch since not necessary
            CPUTime -= SwitchTime;
        }