示例#1
0
        /// <summary>
        /// Generates a single list and runs the list against selected algorithms
        /// </summary>
        private static void RunSingle()
        {
            List <ProcessDTO> processList = GenerateList();

            bool continueRun = true;

            while (continueRun)
            {
                Console.WriteLine("Select an algorithm to run:");
                Console.WriteLine("1: First Come First Serve");
                Console.WriteLine("2: Round Robin");
                string input = Console.ReadLine();

                bool validInput = int.TryParse(input, out int result);

                switch (result)
                {
                case (int)SchedulingAlgorithms.FCFS:
                    FCFS firstCome = new FCFS(processList);
                    firstCome.Run();
                    firstCome.PrintResults();
                    break;

                case (int)SchedulingAlgorithms.RR:
                    RoundRobin robin = new RoundRobin(processList);
                    robin.Run();
                    robin.PrintResults();
                    break;

                default:
                    Console.WriteLine("Please Enter a valid option.");
                    continue;
                }

                continueRun = GetRunAgain(true);
            }
        }
示例#2
0
        /// <summary>
        /// Runs all algortihms x times and writes results to a file
        /// </summary>
        private static void Compare()
        {
            bool validInput = false;
            int  runCount   = 0;

            while (!validInput)
            {
                Console.WriteLine("Please enter amount of times to run:");
                string input = Console.ReadLine();
                validInput = int.TryParse(input, out runCount);
            }

            //build a data structure to hold the objects and results
            Dictionary <SchedulingAlgorithms, List <double> > processDict = new Dictionary <SchedulingAlgorithms, List <double> >();

            processDict.Add(SchedulingAlgorithms.FCFS, new List <double>());
            processDict.Add(SchedulingAlgorithms.RR, new List <double>());

            Console.WriteLine("Starting Algorithm Execution");
            for (int i = 0; i < runCount; i++)
            {
                List <ProcessDTO> processList = GenerateList();

                foreach (KeyValuePair <SchedulingAlgorithms, List <double> > kvPair in processDict)
                {
                    switch (kvPair.Key)
                    {
                    case SchedulingAlgorithms.FCFS:
                        FCFS firstCome = new FCFS(processList);
                        firstCome.Run();
                        kvPair.Value.Add(firstCome.GetAvgWait());

                        // this sleep needs to be here to ensure the add completes properly
                        Thread.Sleep(1);
                        break;

                    case SchedulingAlgorithms.RR:
                        RoundRobin robin = new RoundRobin(processList);
                        robin.Run();
                        kvPair.Value.Add(robin.GetAvgWait());

                        // this sleep needs to be here to ensure the add completes properly
                        Thread.Sleep(1);
                        break;

                    default:
                        break;
                    }
                }
                processList.Clear();
            }
            Console.WriteLine("Completed Running Algorithms");

            if (File.Exists(COMP_FILE))
            {
                File.Delete(COMP_FILE);
            }

            using (StreamWriter stream = new StreamWriter(COMP_FILE))
            {
                stream.WriteLine("Results of Scheduling Algorithm Comparisons");
                stream.WriteLine($"Total interations: {runCount}\n");

                Console.WriteLine("Results of Scheduling Algorithm Comparisons");
                Console.WriteLine($"Total interations: {runCount}\n");

                foreach (KeyValuePair <SchedulingAlgorithms, List <double> > kvPair in processDict)
                {
                    switch (kvPair.Key)
                    {
                    case SchedulingAlgorithms.FCFS:
                        stream.WriteLine("Results for First Come First Serve");
                        stream.WriteLine($"Lowest Average Wait: {kvPair.Value.Min()}");
                        stream.WriteLine($"Total Average Wait: {(kvPair.Value.Sum() / kvPair.Value.Count)}");
                        stream.WriteLine($"Highest Average Wait: {kvPair.Value.Max()}");
                        stream.WriteLine();

                        Console.WriteLine("Results for First Come First Serve");
                        Console.WriteLine($"Lowest Average Wait: {kvPair.Value.Min()}");
                        Console.WriteLine($"Total Average Wait: {(kvPair.Value.Sum() / kvPair.Value.Count)}");
                        Console.WriteLine($"Highest Average Wait: {kvPair.Value.Max()}");
                        Console.WriteLine();
                        break;

                    case SchedulingAlgorithms.RR:
                        stream.WriteLine("Results for Round Robin");
                        stream.WriteLine($"Lowest Average Wait: {kvPair.Value.Min()}");
                        stream.WriteLine($"Total Average Wait: {(kvPair.Value.Sum() / kvPair.Value.Count)}");
                        stream.WriteLine($"Highest Average Wait: {kvPair.Value.Max()}");
                        stream.WriteLine();

                        Console.WriteLine("Results for Round Robin");
                        Console.WriteLine($"Lowest Average Wait: {kvPair.Value.Min()}");
                        Console.WriteLine($"Total Average Wait: {(kvPair.Value.Sum() / kvPair.Value.Count)}");
                        Console.WriteLine($"Highest Average Wait: {kvPair.Value.Max()}");
                        Console.WriteLine();
                        break;
                    }
                }
            }
            Console.WriteLine("Completed Writing to file");
        }