Exemple #1
5
        public Simulator(String fileName)
        {
            Lowest = 99999;
            output = new StreamWriter ("../../output.txt");
            try {
                ProcessList p = new ProcessList (fileName);
                if (debug) {
                    //Echo processes to console
                    output.WriteLine ("===================================");
                    output.WriteLine ("Quantum = " + p.getQuantum ());
                   // Console.Read();
                    for (int loop = 0; loop < p.getNumberOfProcesses (); loop++) {
                        output.WriteLine ("===================================");
                        output.WriteLine ("PID: " + p.getProcess (loop).getPID ());
                        output.WriteLine ("CPU Burst 1: " + p.getProcess (loop).getCPU_burst1 ());
                        output.WriteLine ("CPU Burst 2: " + p.getProcess (loop).getCPU_burst2 ());
                        output.WriteLine ("IO Burst : " + p.getProcess (loop).getIO_burst ());
                        output.WriteLine ("Priority: " + p.getProcess (loop).getPriority ());
                        output.WriteLine ("Period: " + p.getProcess (loop).getCurrentPeriod ());
                    }
                }

                //Populate Schedulers
                Scheduler[] sim = new Scheduler[6];
                {
                    int i = 0;

                    sim [i++] = new FCFS (new ProcessList(fileName),output);
                    sim [i++] = new SJF (new ProcessList(fileName),output);
                    sim [i++] = new SJR (new ProcessList(fileName),output);
                    sim [i++] = new RR (new ProcessList(fileName),output);
                    sim [i++] = new Priority(new ProcessList(fileName),output);
                    sim [i++] = new MFQ (new ProcessList(fileName), output);

                }
                int j;
                output.WriteLine ("ALGORITHM     AVERAGE TURNAROUND TIME");
                for(j =0 ; j < 6; j++){
                    try{
                        output.WriteLine ("{0,9}{1,7}",sim[j].GetType ().Name,sim[j].Average_TurnAround);
                        if(sim[j].Average_TurnAround < Lowest)
                            Lowest = sim[j].Average_TurnAround;
                    }catch(NullReferenceException){
                        //THIS MEANS WE DID NOT PUT ALL THE PROCESSES IN YET WHICH IS FINE
                    }
                }
                foreach(Scheduler item in sim){
                    try{
                        if(item.Average_TurnAround == Lowest)
                            output.WriteLine ("The best algorithm for the data set is "+item.GetType ().Name+" with a average turnaround time of "+item.Average_TurnAround);
                    }catch(NullReferenceException){
                        //THIS MEANS WE DID NOT PUT ALL THE PROCESSES IN YET WHICH IS FINE
                    }
                }
            } catch (Exception e) {
                Console.WriteLine ("Error trying to populate the process list: " + e.Message);
                output.WriteLine ("Program quitting");
            }finally{
                output.Close ();
            }
        }
Exemple #2
2
        static void Main(string[] args)
        {
            List<Process> processList = new List<Process>();

            StreamReader sr = new StreamReader("input.csv");
            StreamWriter sw = new StreamWriter("output.txt");
            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();
                var values = line.Split(';');

                int[] numvalues = new int[5];

                for (int i = 0; i < 5; i++)
                {
                    numvalues[i] = int.Parse(values[i]);
                }
                processList.Add(new Process(numvalues[0], numvalues[1], numvalues[2], numvalues[3], numvalues[4]));
            }

            foreach (Process x in processList)
            {
                Console.WriteLine(x.ToString() + " " + x.getPID() + " " + x.getIO_burst());
            }
            Console.ReadLine();

            //below are the actual simulations
            sw.WriteLine("First Come First Serve");
            SchedulerBase fcfs = new FCFS(processList);
            fcfs.simulate(10, sw);
            fcfs.finalReport(sw);

            sw.Write("\nMFQ");
            SchedulerBase mfq = new MFQ(processList);
            mfq.simulate(10, sw);
            mfq.finalReport(sw);

            sw.WriteLine("\nRound Robin");
            SchedulerBase rr = new RR(processList);
            rr.simulate(10, sw);
            rr.finalReport(sw);

            sw.WriteLine("\nPriority Scheduling");
            SchedulerBase priority = new Priority(processList);
            priority.simulate(10, sw);
            priority.finalReport(sw);

            sw.WriteLine("\nShortest Job First");
            SchedulerBase sjf = new SJF(processList);
            sjf.simulate(10, sw);
            sjf.finalReport(sw);

            sw.WriteLine("\nShortest Job Remaining");
            SchedulerBase sjr = new SJR(processList);
            sjr.simulate(10, sw);
            sjr.finalReport(sw);

            foreach (Process x in processList)
            {
                Console.WriteLine(x.ToString() + " " + x.getPID() + " " + x.getIO_burst());
            }
            Console.ReadLine();

            sw.Close();
        }