Skip to content

Commit f35650b

Browse files
authored
Update shortest_job_first_algorithm.py
1 parent cb8eb74 commit f35650b

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

scheduling/shortest_job_first_algorithm.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#time are inputted as space separated
66

77
import pandas as pd
8-
8+
from typing import List
99

1010

11-
def calculate_waitingtime(arrival_time,burst_time,no_of_processes):
11+
def calculate_waitingtime(
12+
arrival_time: List[int],burst_time: List[int],no_of_processes: int
13+
) -> List[int]:
1214

1315
"""
1416
This function calculates the Waiting Times of each Processes
@@ -34,25 +36,25 @@ def calculate_waitingtime(arrival_time,burst_time,no_of_processes):
3436

3537
# Process until all processes gets
3638
# completed
37-
while (complete != no_of_processes):
39+
while complete != no_of_processes:
3840
for j in range(no_of_processes):
39-
if(arrival_time[j]<=increment_time):
40-
if(remaining_time[j]>0):
41-
if(remaining_time[j]<minm):
41+
if arrival_time[j]<=increment_time:
42+
if remaining_time[j]>0:
43+
if remaining_time[j]<minm:
4244
minm=remaining_time[j]
4345
short=j
4446
check=True
4547

46-
if (check == False):
48+
if check == False:
4749
increment_time += 1
4850
continue
4951
remaining_time[short]-=1
5052

5153
minm = remaining_time[short]
52-
if (minm == 0):
54+
if minm == 0:
5355
minm = 999999999
5456

55-
if (remaining_time[short] == 0):
57+
if remaining_time[short] == 0:
5658
complete += 1
5759
check = False
5860

@@ -64,13 +66,15 @@ def calculate_waitingtime(arrival_time,burst_time,no_of_processes):
6466
finar=finish_time - arrival_time[short]
6567
waiting_time[short] = (finar - burst_time[short])
6668

67-
if (waiting_time[short] < 0):
69+
if waiting_time[short] < 0:
6870
waiting_time[short] = 0
6971

7072
# Increment time
7173
increment_time += 1
7274
return waiting_time
73-
def calculate_turnaroundtime(burst_time, no_of_processes, waiting_time):
75+
def calculate_turnaroundtime(
76+
burst_time: List[int], no_of_processes: int, waiting_time: List[int]
77+
) -> List[int]:
7478
"""
7579
This function calculates the Turn Around Times of each Processes
7680
Return: list of Turn Around Time.
@@ -85,7 +89,9 @@ def calculate_turnaroundtime(burst_time, no_of_processes, waiting_time):
8589
for i in range(no_of_processes):
8690
turn_around_time[i] = burst_time[i] + waiting_time[i]
8791
return turn_around_time
88-
def calculate_average_times(waiting_time,turn_around_time, no_of_processes):
92+
def calculate_average_times(
93+
waiting_time: List[int],turn_around_time: List[int], no_of_processes: int
94+
):
8995
"""
9096
This function calculates the average of the waiting & turnaround times
9197
Prints: Average Waiting time & Average Turn Around Time
@@ -104,7 +110,7 @@ def calculate_average_times(waiting_time,turn_around_time, no_of_processes):
104110
for i in range(no_of_processes):
105111
total_waiting_time = total_waiting_time + waiting_time[i]
106112
total_turn_around_time = total_turn_around_time + turn_around_time[i]
107-
print("\nAverage waiting time = %.5f "%(
113+
print("Average waiting time = %.5f "%(
108114
total_waiting_time /no_of_processes) )
109115
print("Average turn around time = ",
110116
total_turn_around_time / no_of_processes)
@@ -134,4 +140,3 @@ def calculate_average_times(waiting_time,turn_around_time, no_of_processes):
134140
# Printing the dataFrame
135141
pd.set_option('display.max_rows', fcfs.shape[0]+1)
136142
print(fcfs)
137-

0 commit comments

Comments
 (0)