//20/80 jobs // creates the 20/80 jobs based upon the parameters given from main returns job times public static JobC[] JobType3(int numJobs) { JobC[] jobs = new JobC[numJobs]; //create jobs var large = new Normal(250, 50); //large jobs var small = new Normal(50, 5); //small jobs var gausianarrtime = new Normal(160, 15); //gussian normal double arrival = 0; //arrival initialized for (int i = 0; i < numJobs; i++) //for lopp used to populate jobclass { arrival += gausianarrtime.Sample(); //creates arrival times based on guassian normal and increments for each job, a sum. if (rndm.NextDouble() <= 0.8) //if the random number between 0 and 1 is less than 0.8 creates a large job and otherwise creates a small job { jobs[i] = new JobC(large.Sample(), arrival); // instanianting the process job array with runtime and job arrival time and time taken } else { jobs[i] = new JobC(small.Sample(), arrival);//creation of small jobs } } return(jobs); //return job times }
//////////////////////////// // SHortest-Job First // //////////////////////////// //shortest job first takes in process job class and the job number and returns context switches public static int Sjf(JobC[] Process, int numJobs) { JobC temp = new JobC(); //tempary jobClass used double globalTime = 0; // time taken for (int i = 0; i < Process.Length; i++)// first for loop { temp = null; // if (Process[i].JobLength > 0)// see if job has arrived for (int j = 0; j < Process.Length; j++) // second for loop { if (Process[j].JobArrival <= globalTime && Process[j].Status == false) // checking if arrival time is less than global time { if (temp == null) //if temp node is empty set it to the current process { temp = Process[j]; } else if (Process[j].JobLength < temp.JobLength) //if the job unit time is less than the temporary job length, set it to the current process { temp = Process[j]; } } } if (temp != null)// if shortest jobs { //if temp is not null set the temporray startitme to the global time temp.StarTime = globalTime; globalTime += temp.JobLength; //globalTime is the sum of temp job lengths temp.EndTime = globalTime; //EndTime temp.Status = true; //the tempory job is processed } else //if temp is empty { globalTime = Process[i].JobArrival; //globaltime set to the process job arrival Process[i].StarTime = globalTime; //startme set tothe value of global time globalTime += Process[i].JobLength; //globalTime is the sum of process job lengths Process[i].EndTime = globalTime; //endtime of the process is equal to this golbal time Process[i].Status = true; //return process status as being done } } return(Process.Length); }
// creates the guassian jobs based upon the parameters given from main returns job times public static JobC[] Jobtype1(int numJobs) { var gausianarrtime = new Normal(160, 15); //creation of normal disbution var firstInstance = new Normal(150, 20); //initial job length of a class JobC[] jobs = new JobC[numJobs]; //job class creation, used to fill in each job with its times double arrival = 0; //initializes arrival to be 0 for (int i = 0; i < numJobs; i++) //for loop used to populate each jobclass with the times used { arrival += gausianarrtime.Sample(); //sets the arrival for each incremeted job, jobs[i] = new JobC(firstInstance.Sample(), arrival); // instanianting the process job array with runtime and job arrival time and time taken // Console.WriteLine(" Jruntime :" + Process[i].JobLength + " JArrivalTime: " + Process[i].JobArrival) } return(jobs);//returns the values of the job class }
//80/20 jobs // creates the 80/20 jobs based upon the parameters given from main returns job times public static JobC[] JobType2(int numJobs) { var gausianarrtime = new Normal(160, 15); //guassian normal for arrival times JobC[] jobs = new JobC[numJobs]; //create jobs var large = new Normal(250, 50); //creation of large normal distrubution var small = new Normal(50, 5); //creation of small normal distrubution double arrival = 0; for (int i = 0; i < numJobs; i++) //for loop used to populate jobs { arrival += gausianarrtime.Sample(); //arrival is set and incremented for each incomming job if (rndm.NextDouble() >= 0.8) //if the random number is greater than .8, it creates a large job, else makes a small job { jobs[i] = new JobC(large.Sample(), arrival); // instanianting the process job array with runtime and job arrival time and time taken } else { jobs[i] = new JobC(small.Sample(), arrival);// instanianting the process job array with runtime and job arrival time and time taken } } return(jobs);//return job information }
///////////////////////////// // RoundRobin method // ///////////////////////////// // Roundrobin takes in the initial job process and quanta and returns public static int RoundRobin(JobC[] Process, double pTime) { JobC temp = new JobC(); // temp job object which has nothing in it JobC Cswithc = new JobC(); // making another temp job for context switches int switc = 0; double globalTime = 0; // arrival of jobs do { temp = null; // if (Process[i].JobLength > 0)// see if job has arrived // makes the job arrive and sets temp to be equal the process job for (int j = 0; j < Process.Length; j++) { if (globalTime < Process[j].JobArrival && temp == null) { // clock to jobarrival time plus the job length time which equals the completion time temp = Process[j]; } else if (Process[j].JobArrival <= globalTime && Process[j].Status == false) //else set temp to process instance { temp = Process[j]; } } if (temp != null) // if shortest jobs { ///procesinng jobs //same way of processing jobs of PSJF if (temp.JobArrival > globalTime) { globalTime = temp.JobArrival; } if (temp.StarTime < 0) { temp.StarTime = globalTime; } if (temp.RemaningRuntime <= pTime) { globalTime += temp.RemaningRuntime; temp.RemaningRuntime = 0; temp.EndTime = globalTime; temp.Status = true; } else { globalTime += pTime; temp.RemaningRuntime -= pTime; } if (temp != Cswithc) { switc++; } Cswithc = temp; } } while (temp != null); return(switc);//return context switches }
//////////////////////////////////// // Preemptive Shortest Job First // //////////////////////////////////// //pre-emptive shortest job first takes in the initial job class and quanta time, returns public static int PSjf(JobC[] Process, double pTime) { JobC temp = new JobC(); // temp job object which has nothing in it JobC Cswithc = new JobC(); // making another temp job for context switches, used as comparison for the temp int switc = 0; //context switch double globalTime = 0; //clock that keeps track of the sum of job unit times // time taken do { temp = null; // if (Process[i].JobLength > 0)// see if job has arrived // makes the job arrive and sets temp to be equal the process job for (int j = 0; j < Process.Length; j++) { if (globalTime < Process[j].JobArrival && temp == null) //if globalTime is lest than the instance of the arrival time { //and there is no shortest job set the temp to this instance temp = Process[j]; break; } else if (Process[j].JobArrival <= globalTime && Process[j].Status == false) // checking if arrival time is less than global time { if (temp == null) { temp = Process[j];//if temporary node is empty, set to the instance of process } else if (Process[j].RemaningRuntime < temp.RemaningRuntime) { temp = Process[j]; //if remaining runtime of the instnce is less than the temporary //set temp equal to that process } } } if (temp != null) // if shortest jobs { ///procesinng jobs if (temp.JobArrival > globalTime) //if temp Arrival is less than global time, temp is set { globalTime = temp.JobArrival; } //if temp.startTime is less than zero set temp startime to globall time if (temp.StarTime < 0) { temp.StarTime = globalTime; } if (temp.RemaningRuntime <= pTime) { //if the remaining temp runtime is less than the quanta, finish the job globalTime += temp.RemaningRuntime; temp.RemaningRuntime = 0; temp.EndTime = globalTime; temp.Status = true; } else { globalTime += pTime; //global sum of the quanta temp.RemaningRuntime -= pTime; //if temp is greater than quanta, subtract quanta to time remaining } if (temp != Cswithc) //every time temp is not equal to the normal job process, a contect switch occurs { switc++; } Cswithc = temp; } } while (temp != null); //while the temp node is not empty return(switc); //return context switch }