Round Robin cpuscheduling in python - is it correct?

59 Views Asked by At

I wrote a python code for the Round Robin algorithm, but the Gantt Chart provided as an answer on the Geeksforgeek site is different from the Gantt Chart provided by the code I created. What's wrong with my code?

def round_robin(processes, burst_time, arrival_time, time_quantum):
    n = len(processes)
    
    # Waiting times
    waiting_time = [0] * n
    # remaining burst time
    rem_burst = list(burst_time)
    # remaining arrival time
    rem_arrival = list(arrival_time)
    # Gantt chart
    gantt_chart = []
    
    t = 0
    while True:
        done = True
        for i in range(n):
            if rem_arrival[i] <= t and rem_burst[i] > 0:
                done = False
                if rem_burst[i] > time_quantum:
                    t += time_quantum
                    rem_burst[i] -= time_quantum
                    rem_arrival[i] = t
                    gantt_chart.append((processes[i], t))
                else:
                    t += rem_burst[i]
                    waiting_time[i] = t - burst_time[i] - arrival_time[i]
                    rem_burst[i] = 0
                    rem_arrival[i] = t
                    gantt_chart.append((processes[i], t))
        if done:
            break
    
    # Calculate Turnaround Time
    turnaround_time = [waiting_time[i] + burst_time[i] for i in range(n)]
    
    return gantt_chart, waiting_time, turnaround_time
0

There are 0 best solutions below