From b0b108aed6abc3270740fbff074e26cabe27989b Mon Sep 17 00:00:00 2001 From: Zach S-B Date: Fri, 27 Aug 2021 20:19:05 +1000 Subject: [PATCH] SRT nearly working (Need to fix waiting) --- Process.java | 3 +++ SRT.java | 42 ++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Process.java b/Process.java index 8191ab6..65c5815 100644 --- a/Process.java +++ b/Process.java @@ -12,6 +12,9 @@ public class Process { private int endTime= -1; private int remainingTime; + + public int hold = -1; + public int unhold = -1; //Constructors diff --git a/SRT.java b/SRT.java index 70d4fb2..3e2d26a 100644 --- a/SRT.java +++ b/SRT.java @@ -64,53 +64,51 @@ public class SRT { System.out.println("SRT:"); int processesFinished = 0; boolean startNew = true; + int shortestProcess = -1; + int lastRunProcess = -1; //timeStep++; do { - if(startNew) - { - timeStep = timeStep+disp; - startNew = false; - } - checkForArrivals(); + shortestProcess = findShortestProcess(); if(waitingQueue.size()>0) { - if(waitingQueue.getFirst().isDone()) + if(lastRunProcess!=shortestProcess) { - waitingQueue.removeFirst(); + System.out.println("T"+timeStep+": "+waitingQueue.get(shortestProcess).getId()); + timeStep = timeStep+disp; + } + + runProcessTick(waitingQueue.get(shortestProcess)); + + if(waitingQueue.get(shortestProcess).isDone()) + { + waitingQueue.remove(shortestProcess); processesFinished++; - startNew = true; - } - else - { - runShortestProcess(); } + lastRunProcess = shortestProcess; } - }while(processesFinished!=processListFromFile.size()); - - //... - printResults(); + }while(processesFinished!=processListFromFile.size()); } - private void runShortestProcess() + private int findShortestProcess() { - int pos = 0; + int listPos = 0; int remaining = waitingQueue.get(0).getRemainingTime(); for(int i = 1; i