using System; using System.Collections.Generic; using System.Threading; using System.Text; namespace Lab4 { class Program { static List times = new List(); static List execTime = new List(); static List processes = new List(); static void Main(string[] args) { Console.Write("Enter number of processes/delays: "); Int32 res; while (!int.TryParse(Console.ReadLine(), out res) || res <= 1 || res > 1000) Console.Write("Enter number of processes/delays: "); Random rnd = new Random(); for (int i = 0; i < res; i++) { if (i == 0) times.Add(0); else times.Add(times[i-1] + rnd.Next(6, 12)); execTime.Add(rnd.Next(3, 10)); } //times.AddRange(new int[] { 0, 6, 12, 18, 24 });//(new int[] { 0, 6, 12, 18 }); //execTime.AddRange(new int[] { 8, 9, 8, 13, 4 }); //(new int[] { 10, 10, 10, 10 }); Int32 totalExecTime = 0; for (int i = 0; i < times.Count; i++) { totalExecTime += execTime[i]; // sum exec time Console.Write(times[i] + "\t"); processes.Add(new Process(execTime[i], i)); // add process with exec time and PID } Console.WriteLine(); for (int i = 0; i < times.Count; i++) Console.Write(execTime[i] + "\t"); // some info Console.WriteLine(); Console.WriteLine("Start FCFS emulating, please wait..."); FCFS fcfs = new FCFS(execTime.Count); // new FCFS with specified processes count Console.WriteLine("Adding processes..."); for (int i = 0; i < times.Count; i++) { //Console.WriteLine("adding proc " + processes[i].PID.ToString()+ " with execTime " + processes[i].executionTime.ToString()); fcfs.AddProcess(processes[i]); // add process to fcfs if (i == times.Count - 1) // no more procs { Console.WriteLine("There is no next process.\r\nWaiting for current processes emulation ending."); fcfs.EndEmulation(); } else { //Console.WriteLine("next proc in " + (times[i+1] - times[i]).ToString() +"\r\n"); Thread.Sleep((times[i + 1] - times[i]) * 100); // sleep to next proc } } Console.ReadKey(true); // some info Console.WriteLine("\r\nmax queue " + fcfs.maxQueue.ToString()); Console.WriteLine("avg exec time {0:F2}", 1.0 * totalExecTime / execTime.Count); Console.WriteLine("avg idle time {0:F2}", fcfs.avgIdleTime); Console.WriteLine("\r\nTo start emulating SPN press any key."); Console.ReadKey(true); Console.WriteLine("Start SPN emulating, please wait..."); SPN spn = new SPN(execTime.Count); // new SPN with specified processes count Console.WriteLine("Adding processes..."); for (int i = 0; i < times.Count; i++) { //Console.WriteLine("adding proc " + processes[i].PID.ToString()+ " with execTime " + processes[i].executionTime.ToString()); spn.AddProcess(processes[i]); // add process to spn if (i == times.Count - 1) // no more procs { Console.WriteLine("There is no next process.\r\nWaiting for current processes emulation ending."); spn.EndEmulation(); } else { //Console.WriteLine("next proc in " + (times[i+1] - times[i]).ToString() +"\r\n"); Thread.Sleep((times[i + 1] - times[i]) * 100); // sleep to next proc } } Console.ReadKey(true); Console.WriteLine("\r\nmax queue " + spn.maxQueue.ToString()); Console.WriteLine("avg exec time {0:F2}", 1.0 * totalExecTime / execTime.Count); Console.WriteLine("avg idle time {0:F2}", spn.avgIdleTime); Console.ReadKey(true); } } }