def
sortByArrival(at, n):
for
i
in
range
(
0
, n
-
1
):
for
j
in
range
(i
+
1
, n):
if
at[i] > at[j]:
at[i], at[j]
=
at[j], at[i]
if
__name__
=
=
'__main__'
:
sum_bt
=
0
avgwt
=
0
avgTT
=
0
n
=
5
completed
=
[
0
]
*
n
waiting_time
=
[
0
]
*
n
turnaround_time
=
[
0
]
*
n
normalised_TT
=
[
0
]
*
n
arrival_time
=
[
0
,
2
,
4
,
6
,
8
]
burst_time
=
[
3
,
6
,
4
,
5
,
2
]
process
=
[]
for
i
in
range
(
0
, n):
process.append(
chr
(
65
+
i))
sum_bt
+
=
burst_time[i]
sortByArrival(arrival_time, n)
print
(
"Name"
,
"Arrival time"
,
"Burst time"
,
"Waiting Time"
,
"Turnaround "
,
"Normalized TT"
)
t
=
arrival_time[
0
]
while
(t < sum_bt):
hrr
=
-
9999
temp, loc
=
0
,
0
for
i
in
range
(
0
, n):
if
arrival_time[i] <
=
t
and
completed[i] !
=
1
:
temp
=
((burst_time[i]
+
(t
-
arrival_time[i]))
/
burst_time[i])
if
hrr < temp:
hrr
=
temp
loc
=
i
t
+
=
burst_time[loc]
waiting_time[loc]
=
(t
-
arrival_time[loc]
-
burst_time[loc])
turnaround_time[loc]
=
t
-
arrival_time[loc]
avgTT
+
=
turnaround_time[loc]
normalised_TT
=
float
(turnaround_time[loc]
/
burst_time[loc])
completed[loc]
=
1
avgwt
+
=
waiting_time[loc]
print
(process[loc],
"\t\t"
, arrival_time[loc],
"\t\t"
, burst_time[loc],
"\t\t"
,
waiting_time[loc],
"\t\t"
,
turnaround_time[loc],
"\t\t"
,
"{0:.6f}"
.
format
(normalised_TT))
print
(
"Average waiting time: {0:.6f}"
.
format
(avgwt
/
n))
print
(
"Average Turn Around time: {0:.6f}"
.
format
(avgTT
/
n))