Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def Shortest _ remaining _ Time ( processes ) : GanttChart = [ ] ready _ queue = deque ( ) waiting _ queue =
def ShortestremainingTimeprocesses:
GanttChart
readyqueue deque
waitingqueue deque
currenttime
temp
GanttChart.appendprocessesnum, currenttime, temp
if processesArrivaltime temp:
currenttime processesBursttime temp
GanttChart.appendprocessesnum, temp, currenttime
processes.sortkeylambda y: yBursttime
while currenttime :
for process in processes:
if currenttime process.Arrivaltime: # Check attribute consistency
currenttime process.Arrivaltime
if currenttime :
if process.remainingtime and process not in readyqueue and process not in waitingqueue:
if process.Bursttime process.remainingtime:
GanttChart.appendprocessnum, currenttime, currenttime process.Bursttime
process.waitingtime max currenttime process.Arrivaltime
process.turnaroundtime process.waitingtime process.Bursttime
readyqueue.appendprocess
if readyqueue:
readyqueue dequesortedreadyqueue, keylambda x: xremainingtime
process readyqueue.popleft
GanttChart.appendprocessnum, currenttime, currenttime
process.remainingtime
temp
currenttime
if process.remainingtime :
waitingqueue.appendprocess
temp
else:
currenttime
if waitingqueue:
for process in waitingqueue:
if temp process.Comesbackafter:
readyqueue.appendprocess
waitingqueue.removeprocess
break
avgwaitingtime calculateaveragewaitingtimeprocesses
avgturnaroundtime calculateaverageturnaroundtimeprocesses
TurnAroundTimeTotalwithSupposedpsrtf sumprocessturnaroundtime for process in processes if process.remainingtime
return GanttChart, avgwaitingtime, avgturnaroundtime, TurnAroundTimeTotalwithSupposedpsrtf fix it to get theese results:Shortest Remaining Time First:
GANTT CHART:
P P P P P P P P P P P P P D P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P
Average waiting time
Average turnaround time
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started