diff --git a/FCFS.java b/FCFS.java index 7b9f5fd..c3ce857 100644 --- a/FCFS.java +++ b/FCFS.java @@ -103,7 +103,7 @@ public class FCFS { timeStep++; - input.runForOneTick(); + input.runForOneTick(true); if(input.isDone()) { diff --git a/Process.java b/Process.java index 65c5815..913a051 100644 --- a/Process.java +++ b/Process.java @@ -105,9 +105,23 @@ public class Process { //Functions - public void runForOneTick() + public void runForOneTick(boolean isRunning) { - remainingTime--; + if(isRunning) + { + remainingTime--; + } + else + { + if(waitTime==-1) + { + waitTime=1; + } + else + { + waitTime++; + } + } } public boolean isDone() diff --git a/SRT.java b/SRT.java index 3e2d26a..2953c10 100644 --- a/SRT.java +++ b/SRT.java @@ -55,46 +55,51 @@ public class SRT { { waitingQueue.add(newProcesses.get(i)); } - newProcesses.clear(); } public void runDispatch() - { + { System.out.println("SRT:"); int processesFinished = 0; - boolean startNew = true; - int shortestProcess = -1; - int lastRunProcess = -1; - //timeStep++; + Process currentProcess; + Process lastRunProcess = new Process("temp", 0, 0, 0); //temp process for comparing the first run do { - checkForArrivals(); - shortestProcess = findShortestProcess(); - + checkForArrivals(); //Check for any new processes since timestep + + currentProcess = findShortestProcess(); //get the shortest one out of that + + //As long as there is something in the queue if(waitingQueue.size()>0) { - if(lastRunProcess!=shortestProcess) + if(!lastRunProcess.getId().equals(currentProcess.getId())) { - System.out.println("T"+timeStep+": "+waitingQueue.get(shortestProcess).getId()); timeStep = timeStep+disp; + System.out.println("T"+timeStep+": "+currentProcess.getId()); + for(int i = 0; i winnerValue) - { - winner = i; - break; - } - } - - if(winner == -1) - { - System.out.println("No winner"); - } - else - { - System.out.println("Winner: " + processList.get(winner).getId()); - } - } - - public int returnRandomNum(int totalTickets) - { - - /* - Friendly neighbourhood Latch — 08/08/2021 -I figured it out -Keep looping through the list of unfinished processes, adding that process's number of tickets to the counter, until you get to one that is greater than the winning number. If you get to the end of the list, jump back to the start and keep looping through -At the moment it's a disgusting while loop I'm wondering if there's a way I can do that a bit nicer because while loops give me bad vibes but it does the trick - */ - int randomValue = 0; - - - //Loop back to begining. Probably could remove each consumed random number from the linked list.... but I don't want to right now. - if((randomNumConsumed+1) >= randomNum.size()) - { - randomNumConsumed = 0; - } - else - { - randomNumConsumed += 1; - } - - randomValue = randomNum.get(randomNumConsumed) % totalTickets; - - return randomValue; - } - - + } \ No newline at end of file