mirror of
https://github.com/zach-sb/COMP2240-Assignment1.git
synced 2024-07-02 12:04:00 +10:00
SRT nearly working (Need to fix waiting)
This commit is contained in:
parent
0805a79ceb
commit
b0b108aed6
@ -12,6 +12,9 @@ public class Process {
|
||||
private int endTime= -1;
|
||||
|
||||
private int remainingTime;
|
||||
|
||||
public int hold = -1;
|
||||
public int unhold = -1;
|
||||
|
||||
|
||||
//Constructors
|
||||
|
||||
42
SRT.java
42
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<waitingQueue.size(); i++)
|
||||
{
|
||||
if(waitingQueue.get(i).getRemainingTime()<remaining)
|
||||
{
|
||||
pos = i;
|
||||
listPos = i;
|
||||
remaining = waitingQueue.get(i).getRemainingTime();
|
||||
}
|
||||
}
|
||||
|
||||
runProcessTick(waitingQueue.get(pos));
|
||||
return listPos;
|
||||
}
|
||||
|
||||
private void runProcessTick(Process input)
|
||||
@ -133,7 +131,7 @@ public class SRT {
|
||||
{
|
||||
for (int i = 0; i < processListFromFile.size(); i++)
|
||||
{
|
||||
System.out.println("T"+processListFromFile.get(i).getStartTime()+": "+processListFromFile.get(i).getId());
|
||||
//System.out.println("T"+processListFromFile.get(i).getStartTime()+": "+processListFromFile.get(i).getId());
|
||||
}
|
||||
|
||||
System.out.println("\nProcess \tTurnaround Time \tWaiting Time");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user