Question: import matplotlib.pyplot as plt class Process: def _ _ init _ _ ( self , num, Arrival _ time, Burst _ time, Comes _ back

import matplotlib.pyplot as plt
class Process:
def __init__(self, num, Arrival_time, Burst_time, Comes_back_after, Priority):
self.num = num
self.Arrival_time = Arrival_time
self.Burst_time = Burst_time
self.remaining_time = Burst_time
self.Comes_back_after = Comes_back_after
self.Priority = Priority
#===========================================================================================================================
def FirstComeFirstServed(processes):
TurnAroundTimeTotalwithSupposed_p =0
TurnAroundTime =0
WaitingTime =0
GanttChart =[]
TurnAroundTimeTotal =0
WaitingTimeTotal =0
processes.sort(key=lambda y: y.Arrival_time)
Size =0
currentnTime =0
Timer =0
while Timer <200:
for process in processes:
if process.Arrival_time <= currentnTime and Timer <200:
if currentnTime + process.Burst_time <=200:
Size +=1
GanttChart.append((process.num, currentnTime, currentnTime + process.Burst_time))
print(process.num, currentnTime, currentnTime + process.Burst_time)
currentnTime += process.Burst_time
TurnAroundTime = currentnTime - process.Arrival_time
TurnAroundTimeTotal += TurnAroundTime
WaitingTime = TurnAroundTime - process.Burst_time
WaitingTimeTotal += WaitingTime
Timer = currentnTime
else:
currentnTime =200
Timer = currentnTime
TurnAroundTime = currentnTime - process.Arrival_time
TurnAroundTimeTotalwithSupposed_p += TurnAroundTime + TurnAroundTimeTotal
TurnAroundTimeTotalwithSupposed_p = TurnAroundTimeTotalwithSupposed_p / Size
break
average_waiting_time = WaitingTimeTotal / Size
average_turnaround_time = TurnAroundTimeTotal / Size
return GanttChart, average_waiting_time, average_turnaround_time, TurnAroundTimeTotalwithSupposed_p
#===========================================================================================================
def shortest_Job_First(processes):
GanttChart =[]
temp =0
ready_queue =[]
waiting_queue =[]
currentnTime =0
Timer =0
Size =0
TurnAroundTimeTotalwithSupposed_p =0
TurnAroundTime =0
WaitingTime =0
TurnAroundTimeTotal =0
WaitingTimeTotal =0
GanttChart.append((processes[0].num, currentnTime, currentnTime + processes[0].Burst_time))
currentnTime += processes[0].Burst_time
processes.sort(key=lambda y: (y.Burst_time))
Size +=1
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 # Exit the waiting queue loop after adding processes to the ready queue
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))
print(process.num, currentnTime, currentnTime + process.Burst_time)
waiting_queue.append(running_process)
Size +=1
temp += process.Burst_time
currentnTime += process.Burst_time
TurnAroundTime = currentnTime - process.Arrival_time
TurnAroundTimeTotal += TurnAroundTime
WaitingTime = TurnAroundTime - process.Burst_time
WaitingTimeTotal += WaitingTime
Timer = currentnTime
else:
running_process = ready_queue.pop(0)
GanttChart.append(
(running_process.num, currentnTime, currentnTime + running_process.Burst_time))
print(process.num, currentnTime, currentnTime + process.Burst_time)
waiting_queue.append(running_process)
temp += running_process.Burst_time
currentnTithis is my code for this project Faculty of Engineering & Technology
Department of Electrical & Comp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!