Example #1
0
        public void Calculate(int[,] processData)
        {
            ProcessData processdata = new ProcessData();
            string      type        = "duration";
            string      gantt;
            int         tempDuration;

            int[] durationTimeTable = new int[processesCount];
            int[] waitTimeTable     = new int[processesCount];
            int[] serviceTimeTable  = new int[processesCount];
            int[,] sortedProcessData = processdata.SortBy(processData, type);
            int    time              = 0;
            int    status            = 0;
            double avgWaitTime       = 0;
            double avgTurnAroundTime = 0;

            Console.Write("|");
            gantt = "|";
            for (int i = 0; i < processesCount; i++)
            {
                waitTimeTable[i]     = 0;
                durationTimeTable[i] = sortedProcessData[i, 2];
            }
            for (int n = 0; n < processesCount; n++)
            {
                for (int i = 0; i < processesCount; i++)
                {
                    if (durationTimeTable[i] != 0 && sortedProcessData[i, 1] <= time)
                    {
                        tempDuration        = durationTimeTable[i];
                        serviceTimeTable[i] = time;

                        for (int j = 0; j < tempDuration; j++)
                        {
                            time++;
                            durationTimeTable[i] = durationTimeTable[i] - 1;
                            Console.Write(sortedProcessData[i, 0] + "|");
                            gantt += sortedProcessData[i, 0] + "|";
                            status = 1;
                        }
                        break;
                    }
                }
                if (status == 1)
                {
                    status = 0;
                }
                else
                {
                    status = 0;
                    time++;
                    Console.Write(" |");
                    gantt += " |";
                    n--;
                }
            }
            processdata.DisplayData(waitTimeTable, serviceTimeTable, sortedProcessData, avgWaitTime, avgTurnAroundTime, time, processesCount, "Shortest Job First", gantt);
        }
Example #2
0
        public void Calculate(int[,] processData)
        {
            ProcessData processdata = new ProcessData();
            string      type        = "arrival";
            string      gantt;

            int[,] sortedProcessData = processdata.SortBy(processData, type);
            int[] durationTimeTable = new int[processesCount];
            int[] waitTimeTable     = new int[processesCount];
            int[] serviceTimeTable  = new int[processesCount];
            int   time = 0;

            Console.Write("|");
            gantt = "|";

            for (int i = 0; i < processesCount; i++)
            {
                waitTimeTable[i]     = 0;
                durationTimeTable[i] = sortedProcessData[i, 2];
            }
            for (int i = 0; i < processesCount; i++)
            {
                if (sortedProcessData[i, 1] <= time)
                {
                    serviceTimeTable[i] = time;
                    do
                    {
                        Console.Write(sortedProcessData[i, 0] + "|");
                        gantt += sortedProcessData[i, 0] + "|";
                        durationTimeTable[i]--;
                        time++;
                    } while (durationTimeTable[i] > 0);
                }
                else
                {
                    Console.Write(" |");
                    gantt += " |";
                    time++;
                    i--;
                }
            }
            double avgWaitTime       = 0;
            double avgTurnAroundTime = 0;

            processdata.DisplayData(waitTimeTable, serviceTimeTable, sortedProcessData, avgWaitTime, avgTurnAroundTime, time, processesCount, "First Come First Serve", gantt);
        }
Example #3
0
        public void Calculate(int[,] processData)
        {
            ProcessData processdata = new ProcessData();

            int    quantum = processdata.AskQuantum();
            int    time    = 0;
            string gantt;
            int    counter   = 0;
            int    totalTime = 0;
            int    runs      = 0;

            int[,] sortedProcessData = processdata.SortBy(processData, "pid");
            int[]  durationTimeTable = new int[processesCount];
            int[]  waitTimeTable     = new int[processesCount];
            int[]  serviceTimeTable  = new int[processesCount];
            int[]  finishTimeTable   = new int[processesCount];
            double avgWaitTime       = 0;
            double avgTurnAroundTime = 0;

            Console.Write("|");
            gantt = "|";

            for (int i = 0; i < processesCount; i++)
            {
                totalTime            = totalTime + sortedProcessData[i, 2];
                durationTimeTable[i] = sortedProcessData[i, 2];
                waitTimeTable[i]     = 0;
            }

            int temp;

            int[] firtsDigit = new int[totalTime];
            for (int n = 0; n < processesCount; n++)
            {
                for (int i = 0; i < processesCount; i++)
                {
                    if (sortedProcessData[i, 1] < time + 1 && durationTimeTable[i] > 0)
                    {
                        counter = 0;
                        if (serviceTimeTable[i] == 0 && runs < processesCount)
                        {
                            serviceTimeTable[i] = time;
                        }
                        do
                        {
                            Console.Write(sortedProcessData[i, 0] + "|");
                            gantt += sortedProcessData[i, 0] + "|";

                            for (int j = 0; j < processesCount; j++)
                            {
                                if (sortedProcessData[j, 1] < time + 1 && sortedProcessData[i, 0] != sortedProcessData[j, 0])
                                {
                                    waitTimeTable[j] = waitTimeTable[j] + 1;
                                }
                            }

                            durationTimeTable[i]--;
                            time++;
                            counter++;


                            if (durationTimeTable[i] <= 0)
                            {
                                break;
                            }
                        } while (quantum > counter);

                        finishTimeTable[i] = time;
                    }


                    runs++;
                }
                if (sortedProcessData[n, 1] > time && durationTimeTable[n] >= 0)
                {
                    time++;
                    Console.Write(" |");
                    gantt += " |";
                    n--;
                }
            }
            processdata.DisplayData(waitTimeTable, serviceTimeTable, sortedProcessData, firtsDigit, finishTimeTable, avgWaitTime, avgTurnAroundTime, time, processesCount, "Round Robin", gantt, quantum);
        }
Example #4
0
        public static void Main()
        {
            ProcessData processdata = new ProcessData();

            int[,] processData = new int[, ] {
            };

            Console.WriteLine("Select data input type: ");
            Console.WriteLine("1. Input from file");
            Console.WriteLine("2. Input from keyboard");
            switch (Console.ReadLine())
            {
            case "1":

                string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/process.txt";
                Console.WriteLine(
                    "If you want to select different path, input the file localisation now (actual path: " +
                    filePath + " )");

                string userInput = Console.ReadLine();
                if (!(userInput == ""))
                {
                    filePath = userInput;
                }

                processData = processdata.ReadFromFile(filePath);
                break;

            case "2":
                processData = processdata.OpenPool();
                break;

            default:
                Console.WriteLine("Wrong choose, use only digits 1 or 2 .");
                Environment.Exit(2);
                break;
            }

            int processesCount = processData.GetLength(0) - 1;

            string[] columnNames = { "PID", "Arrival", "Duration", "Priority" };
            Console.WriteLine("Loaded data:");
            Console.WriteLine("");
            for (int i = 0; i < columnNames.Length; i++)
            {
                Console.Write(columnNames[i] + " ");
            }

            Console.WriteLine("");

            for (int i = 0; i < processesCount; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Console.Write(processData[i, j] + "\t");
                }

                Console.WriteLine(" ");
            }


            while (true)
            {
                Console.WriteLine("");
                Console.WriteLine("Please choose algorithm:");
                Console.WriteLine("1. FCFS");
                Console.WriteLine("2. SJF");
                Console.WriteLine("3. Round Robin");
                Console.WriteLine("4. Priority Scheduling with aging");
                Console.WriteLine("0. Exit");
                switch (Console.ReadLine())
                {
                case "0":
                    Environment.Exit(0);
                    break;

                case "1":
                    Console.WriteLine("Choosed FCFS");
                    Console.WriteLine(" ");
                    Fcfs fcfs = new Fcfs(processesCount);
                    fcfs.Calculate(processData);
                    break;

                case "2":
                    Console.WriteLine("Choosed SJF");
                    Console.WriteLine(" ");
                    Sjf sjf = new Sjf(processesCount);
                    sjf.Calculate(processData);
                    break;

                case "3":
                    Console.WriteLine("Choosed RR");
                    Console.WriteLine(" ");
                    Rr rr = new Rr(processesCount);
                    rr.Calculate(processData);
                    break;

                case "4":
                    Console.WriteLine("Choosed Priority Scheduling with aging");
                    Console.WriteLine(" ");
                    Ps ps = new Ps(processesCount);
                    ps.Calculate(processData);
                    break;

                default:
                    Console.WriteLine("Wrong choice");
                    break;
                }
            }
        }