Skip to content

Commit

Permalink
fixed round robin schedular algo
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushSinghGandhi committed Apr 9, 2024
1 parent e8659e7 commit cb6c5d5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/rr_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@ def schedule(self, processes):
return "No processes to schedule" # Return a message if there are no processes

remaining_burst_time = [process.burst_time for process in processes] # Using process object attributes
waiting_times = [0] * len(processes)

scheduling_output = "Process ID\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time\n"

while True:
done = True
for process in processes:
if remaining_burst_time[processes.index(process)] > 0:
for i, process in enumerate(processes):
if remaining_burst_time[i] > 0:
done = False
if remaining_burst_time[processes.index(process)] > self.time_quantum:
if remaining_burst_time[i] > self.time_quantum:
self.current_time += self.time_quantum
remaining_burst_time[processes.index(process)] -= self.time_quantum
remaining_burst_time[i] -= self.time_quantum
waiting_times[i] = max(0, self.current_time - process.arrival_time - process.burst_time)
else:
self.current_time += remaining_burst_time[processes.index(process)]
process_waiting_time = max(0, self.current_time - process.arrival_time - process.burst_time)
self.total_waiting_time += process_waiting_time
remaining_burst_time[processes.index(process)] = 0
self.current_time += remaining_burst_time[i]
waiting_times[i] = max(0, self.current_time - process.arrival_time - process.burst_time)
remaining_burst_time[i] = 0
process_turnaround_time = self.current_time - process.arrival_time
self.total_turnaround_time += process_turnaround_time
scheduling_output += f"{process.name}\t\t{process.arrival_time}\t\t{process.burst_time}\t\t{process_waiting_time}\t\t{process_turnaround_time}\n"
scheduling_output += f"{process.name}\t\t{process.arrival_time}\t\t{process.burst_time}\t\t{waiting_times[i]}\t\t{process_turnaround_time}\n"
if done:
break

self.total_waiting_time = sum(waiting_times)
avg_waiting_time = self.total_waiting_time / len(processes)
avg_turnaround_time = self.total_turnaround_time / len(processes)

Expand Down

0 comments on commit cb6c5d5

Please sign in to comment.