-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrtf.py
98 lines (76 loc) · 1.5 KB
/
srtf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import sys
def disp(x, s):
sys.stdout.write("\033[;1m") #BOLD headings
print s
sys.stdout.write("\033[0;0m") #RESET to normal(default)
for i in range(count):
print 'P' + str(i+1) + '\t' + str(x[i])
def fileRead(arriv, burst, count):
file = open("srtf.txt", "r")
count = int(file.readline())
for i in range(count):
arriv.insert(i, int(file.readline()))
for i in range(count):
burst.insert(i, int(file.readline()))
return count
def minIndex(l):
m = count - 1
while True:
if (l < arriv[m]):
m -= 1
else:
break
return m
def minValue(cop, n):
new = []
for i in range(n+1):
new.insert(i, cop[i])
return min(new)
def cal():
n = 0
last = 0
copy = []
for i in range(count):
copy.insert(i, burst[i])
line = arriv[0]
while True:
print line
n = minIndex(line)
n = minValue(copy, n)
index = copy.index(n)
#print copy[index]
copy[index] -= 1
print copy
line += 1
if copy[index] == 0:
last += 1
copy[index] = 999999;
print copy
if last == count:
break
def waiting(sum):
sum = 0
for i in range(count):
wait.insert(i, (turn[i] - burst[i]))
sum += wait[i]
disp(wait, '\nWaiting Time')
return sum
def turnaround(sum):
sum = 0
for i in range(count):
turn.insert(i, (end[i] - arriv[i]))
sum += turn[i]
disp(turn, '\nTurnaround Time')
return sum
sum = 0
line = 0
count = 0
end = []
wait = []
turn = []
arriv = []
burst = []
count = fileRead(arriv, burst, count)
disp(arriv, '\nArrival Time')
disp(burst, '\nBurst Time')
cal()