Skip to content

Commit a8c3af7

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 45345ae commit a8c3af7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

scheduling/earliest_deadline_first.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010

1111
def calculate_waiting_times(
12-
arrival_times: list[int],
13-
burst_times: list[int],
14-
deadlines: list[int]
12+
arrival_times: list[int], burst_times: list[int], deadlines: list[int]
1513
) -> list[int]:
1614
"""
1715
Calculate the waiting times of processes using EDF algorithm.
@@ -24,16 +22,16 @@ def calculate_waiting_times(
2422
current_time = 0
2523
process_executed = 0
2624
while process_executed < n:
27-
min_deadline = float('inf')
25+
min_deadline = float("inf")
2826
selected_process = -1
2927
for i in range(n):
3028
if (
3129
arrival_times[i] <= current_time
3230
and remaining_times[i] > 0
3331
and deadlines[i] < min_deadline
3432
):
35-
min_deadline = deadlines[i]
36-
selected_process = i
33+
min_deadline = deadlines[i]
34+
selected_process = i
3735

3836
if selected_process == -1:
3937
current_time += 1
@@ -46,30 +44,33 @@ def calculate_waiting_times(
4644

4745
return waiting_times
4846

47+
4948
def calculate_turnaround_times(
50-
burst_times: list[int],
51-
waiting_times: list[int]
49+
burst_times: list[int], waiting_times: list[int]
5250
) -> list[int]:
5351
"""
5452
Calculate the turnaround times of processes.
5553
Return: List of turnaround times for each process.
5654
"""
5755
return [burst_times[i] + waiting_times[i] for i in range(len(burst_times))]
5856

57+
5958
def calculate_average_turnaround_time(turnaround_times: list[int]) -> float:
6059
"""
6160
Calculate the average turnaround time.
6261
Return: The average turnaround time.
6362
"""
6463
return sum(turnaround_times) / len(turnaround_times)
6564

65+
6666
def calculate_average_waiting_time(waiting_times: list[int]) -> float:
6767
"""
6868
Calculate the average waiting time.
6969
Return: The average waiting time.
7070
"""
7171
return sum(waiting_times) / len(waiting_times)
7272

73+
7374
if __name__ == "__main__":
7475
arrival_times = [0, 1, 2]
7576
burst_times = [3, 5, 2]

0 commit comments

Comments
 (0)