Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def shortest _ Job _ First ( processes ) : GanttChart = [ ] temp = 0 ready _ queue = [ ] waiting _

def shortest_Job_First(processes):
GanttChart =[]
temp =0
ready_queue =[]
waiting_queue =[]
currentnTime =0
Timer =0
GanttChart.append((processes[0].num, currentnTime, currentnTime + processes[0].Burst_time))
currentnTime += processes[0].Burst_time
processes[0].waiting_time = max(0, currentnTime - processes[0].Arrival_time)
processes[0].turnaround_time = processes[0].waiting_time + processes[0].Burst_time
processes.sort(key=lambda y: (y.Burst_time))
while Timer <200:
for process in processes:
if Timer <200:
if currentnTime + process.Burst_time <=200:
if waiting_queue:
found_waiting = False
for waiting_process in waiting_queue:
if temp >= waiting_process.Comes_back_after:
ready_queue.append(waiting_process)
waiting_queue.remove(waiting_process)
found_waiting = True
break
else:
break
if not found_waiting:
ready_queue.append(process)
running_process = ready_queue.pop(0)
GanttChart.append((process.num, currentnTime, currentnTime + process.Burst_time))
waiting_queue.append(running_process)
temp += process.Burst_time
currentnTime += process.Burst_time
process.waiting_time = max(0, currentnTime - process.Arrival_time)
process.turnaround_time = process.waiting_time + process.Burst_time
Timer = currentnTime
else:
running_process = ready_queue.pop(0)
GanttChart.append((running_process.num, currentnTime, currentnTime + running_process.Burst_time))
waiting_queue.append(running_process)
temp += running_process.Burst_time
currentnTime += running_process.Burst_time
process.waiting_time = max(0, currentnTime - process.Arrival_time)
process.turnaround_time = process.waiting_time + process.Burst_time
Timer = currentnTime
else:
ready_queue.append(process)
running_process = ready_queue.pop(0)
GanttChart.append((process.num, currentnTime, currentnTime + process.Burst_time))
waiting_queue.append(running_process)
currentnTime += process.Burst_time
Timer = currentnTime
else:
currentnTime =200
Timer = currentnTime
# Calculate average waiting time and average turnaround time
avg_waiting_time = calculate_average_waiting_time(processes)
avg_turnaround_time = calculate_average_turnaround_time(processes)
return GanttChart, avg_waiting_time, avg_turnaround_time ........the algorithm true but the avg waiting tima and around time false it should to be Average waiting time =41.5
Average turnaround time =145.5,,please fix the code to get this results

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions