diff --git a/FCFS.java b/FCFS.java index c3ce857..0e6dcbc 100644 --- a/FCFS.java +++ b/FCFS.java @@ -1,7 +1,7 @@ import java.util.LinkedList; /** - * First Come First Serve Algorithm + * Shortest Remaining Time */ public class FCFS { @@ -55,61 +55,92 @@ public class FCFS { { waitingQueue.add(newProcesses.get(i)); } - newProcesses.clear(); } public void runDispatch() - { + { System.out.println("FCFS:"); int processesFinished = 0; - boolean startNew = true; - //timeStep++; + Process currentProcess; + Process lastRunProcess = new Process("temp", 0, 0, 0); //temp process for comparing the first run do { - if(startNew) - { - timeStep = timeStep+disp; - startNew = false; - } - else - { - ; - } - - checkForArrivals(); - + checkForArrivals(); //Check for any new processes since timestep + + //As long as there is something in the queue if(waitingQueue.size()>0) { - if(waitingQueue.getFirst().isDone()) + currentProcess = findShortestProcess(); + + if(!lastRunProcess.getId().equals(currentProcess.getId())) { - waitingQueue.removeFirst(); + timeStep = timeStep+disp; + System.out.println("T"+timeStep+": "+currentProcess.getId()); + for(int i = 0; i0) { + currentProcess = findShortestProcess(); + if(!lastRunProcess.getId().equals(currentProcess.getId())) { timeStep = timeStep+disp; @@ -85,8 +85,7 @@ public class SRT { } runProcessTick(currentProcess); - - //convert to all be process driven instead of index driven + if(currentProcess.isDone()) { waitingQueue.remove(currentProcess); @@ -101,10 +100,10 @@ public class SRT { private Process findShortestProcess() { - int listPos = 0; - int remaining = waitingQueue.get(0).getRemainingTime(); + int listPos = -1; + int remaining = waitingQueue.getFirst().getRemainingTime(); - for(int i = 1; i