9
9
10
10
11
11
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 ]
15
13
) -> list [int ]:
16
14
"""
17
15
Calculate the waiting times of processes using EDF algorithm.
@@ -24,16 +22,16 @@ def calculate_waiting_times(
24
22
current_time = 0
25
23
process_executed = 0
26
24
while process_executed < n :
27
- min_deadline = float (' inf' )
25
+ min_deadline = float (" inf" )
28
26
selected_process = - 1
29
27
for i in range (n ):
30
28
if (
31
29
arrival_times [i ] <= current_time
32
30
and remaining_times [i ] > 0
33
31
and deadlines [i ] < min_deadline
34
32
):
35
- min_deadline = deadlines [i ]
36
- selected_process = i
33
+ min_deadline = deadlines [i ]
34
+ selected_process = i
37
35
38
36
if selected_process == - 1 :
39
37
current_time += 1
@@ -46,30 +44,33 @@ def calculate_waiting_times(
46
44
47
45
return waiting_times
48
46
47
+
49
48
def calculate_turnaround_times (
50
- burst_times : list [int ],
51
- waiting_times : list [int ]
49
+ burst_times : list [int ], waiting_times : list [int ]
52
50
) -> list [int ]:
53
51
"""
54
52
Calculate the turnaround times of processes.
55
53
Return: List of turnaround times for each process.
56
54
"""
57
55
return [burst_times [i ] + waiting_times [i ] for i in range (len (burst_times ))]
58
56
57
+
59
58
def calculate_average_turnaround_time (turnaround_times : list [int ]) -> float :
60
59
"""
61
60
Calculate the average turnaround time.
62
61
Return: The average turnaround time.
63
62
"""
64
63
return sum (turnaround_times ) / len (turnaround_times )
65
64
65
+
66
66
def calculate_average_waiting_time (waiting_times : list [int ]) -> float :
67
67
"""
68
68
Calculate the average waiting time.
69
69
Return: The average waiting time.
70
70
"""
71
71
return sum (waiting_times ) / len (waiting_times )
72
72
73
+
73
74
if __name__ == "__main__" :
74
75
arrival_times = [0 , 1 , 2 ]
75
76
burst_times = [3 , 5 , 2 ]
0 commit comments