Skip to content

Instantly share code, notes, and snippets.

@rlingineni
Created April 16, 2017 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlingineni/f05daed51e1751c5ada507b86626ffc0 to your computer and use it in GitHub Desktop.
Save rlingineni/f05daed51e1751c5ada507b86626ffc0 to your computer and use it in GitHub Desktop.
Scheduling Algorithm driver
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Scheduler {
public static void main(String args[]) throws FileNotFoundException
{
RunAll(1);
int i = 1;
//i = Integer.parseInt(args[0]);
switch(i)
{
case 1:
RunFCFS();
break;
case 2:
int quant = Integer.parseInt(args[1]);
RunRR(quant);
break;
case 3:
RunShortestScheduler();
break;
case 4:
RunShortestRemainingScheduler();
break;
case 5:
RunHR();
break;
case 6:
RunMultiLevel();
break;
case 7:
int q = Integer.parseInt(args[1]);
RunAll(q);
break;
}
}
static void RunAll(int quant) throws FileNotFoundException
{
RunFCFS();
RunRR(quant);
RunShortestScheduler();
RunShortestRemainingScheduler();
RunHR();
RunMultiLevel();
}
static void RunFCFS() throws FileNotFoundException
{
//Parse job list
Scanner in = new Scanner(new FileReader("jobs.txt"));
//create a list of Jobs
List<Job> jobList = new ArrayList<Job>();
while(in.hasNext())
{
String[] args = in.nextLine().split("\\s+");
//parse and create a job
Job job = new Job(args[0],Integer.parseInt(args[1]),Integer.parseInt(args[2]));
jobList.add(job);
}
FCFSscheduler a = new FCFSscheduler(jobList);
System.out.println();
}
static void RunShortestScheduler() throws FileNotFoundException
{
//Parse job list
Scanner in = new Scanner(new FileReader("jobs.txt"));
//create a list of Jobs
List<Job> jobList = new ArrayList<Job>();
while(in.hasNext())
{
String[] args = in.nextLine().split("\\s+");
//parse and create a job
Job job = new Job(args[0],Integer.parseInt(args[1]),Integer.parseInt(args[2]));
jobList.add(job);
}
ShortestScheduler g = new ShortestScheduler(jobList);
System.out.println();
}
static void RunShortestRemainingScheduler() throws FileNotFoundException
{
//Parse job list
Scanner in = new Scanner(new FileReader("jobs.txt"));
//create a list of Jobs
List<Job> jobList = new ArrayList<Job>();
while(in.hasNext())
{
String[] args = in.nextLine().split("\\s+");
//parse and create a job
Job job = new Job(args[0],Integer.parseInt(args[1]),Integer.parseInt(args[2]));
jobList.add(job);
}
ShortestRemainingScheduler b = new ShortestRemainingScheduler(jobList);
System.out.println();
}
static void RunRR(int quanta) throws FileNotFoundException
{
//Parse job list
Scanner in = new Scanner(new FileReader("jobs.txt"));
//create a list of Jobs
List<Job> jobList = new ArrayList<Job>();
while(in.hasNext())
{
String[] args = in.nextLine().split("\\s+");
//parse and create a job
Job job = new Job(args[0],Integer.parseInt(args[1]),Integer.parseInt(args[2]));
jobList.add(job);
}
RRScheduler m = new RRScheduler(jobList, quanta);
System.out.println();
}
static void RunHR() throws FileNotFoundException
{
//Parse job list
Scanner in = new Scanner(new FileReader("jobs.txt"));
//create a list of Jobs
List<Job> jobList = new ArrayList<Job>();
while(in.hasNext())
{
String[] args = in.nextLine().split("\\s+");
//parse and create a job
Job job = new Job(args[0],Integer.parseInt(args[1]),Integer.parseInt(args[2]));
jobList.add(job);
}
HRScheduler m = new HRScheduler(jobList);
System.out.println();
}
static void RunMultiLevel() throws FileNotFoundException
{
//Parse job list
Scanner in = new Scanner(new FileReader("jobs.txt"));
//create a list of Jobs
List<Job> jobList = new ArrayList<Job>();
while(in.hasNext())
{
String[] args = in.nextLine().split("\\s+");
//parse and create a job
Job job = new Job(args[0],Integer.parseInt(args[1]),Integer.parseInt(args[2]));
jobList.add(job);
}
MultiLevelScheduler d = new MultiLevelScheduler(jobList);
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment