-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
206 lines (192 loc) · 5.68 KB
/
main.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import copy
import sys
import numpy as np
import statistics
# Lendo arquivo e retornando em lista as requisicoes
def read_file(file):
f = open(file, 'r')
req = [int(x) for x in f.readline().split('-') if x !='']
# req.remove('')
# req.remove('\n')
f.close()
return req
def fifo(pos, time, req):
r = copy.copy(req)
f = open("fifo.txt", "w")
dslc = 0
n = len(r)
l_dsl = []
for request in r:
dslc += abs(request-pos)
l_dsl.append(abs(request-pos))
pos = request
f.write(str(request))
f.write("-")
lt = [time * d for d in l_dsl]
m_dslc = dslc / n
m_seek = time * dslc / n
name = f.name
vd = statistics.variance(l_dsl)
dpd = statistics.stdev(l_dsl)
vt = statistics.variance(lt)
dpt = statistics.stdev(lt)
f.close()
print('\nFIFO/FCFS')
print('Quantidade de deslocamento:', dslc)
print('Quantidade media de deslocamento:', m_dslc)
print('Variancia:', vd)
print('Desvio padrao:', dpd)
print('Tempo medio de deslocamento:', m_seek)
print('Variancia tempo:', vt)
print('Desvio padrao tempo:', dpt)
print('Arquivo:', name)
# Shortest Seek First
def ssf(pos, time, req):
r = copy.copy(req)
f = open("ssf.txt", "w")
n = len(r)
high = max(r)
x = high
min_seek = abs(pos-high)
r.sort()
dslc = 0
l_dsl = []
while len(r) > 0:
# find the shortest distance from the current position
for request in r:
seek = abs(pos-request)
if (seek < min_seek):
min_seek = seek
x = request
f.write(str(request))
f.write("-")
dslc += abs(pos-x)
l_dsl.append(abs(pos-x))
pos = x
r.remove(x)
min_seek = abs(pos-high)
x = high
lt = [time * d for d in l_dsl]
m_dslc = dslc / n
m_seek = time * dslc / n
name = f.name
vd = statistics.variance(l_dsl)
dpd = statistics.stdev(l_dsl)
vt = statistics.variance(lt)
dpt = statistics.stdev(lt)
f.close()
print('\nSSF')
print('Quantidade de deslocamento:', dslc)
print('Quantidade media de deslocamento:', m_dslc)
print('Variancia:', vd)
print('Desvio padrao:', dpd)
print('Tempo medio de deslocamento:', m_seek)
print('Variancia tempo:', vt)
print('Desvio padrao tempo:', dpt)
print('Arquivo:', name)
def scan(cil, pos, time, req):
r = copy.copy(req)
f = open("scan.txt", "w")
n = len(r)
dslc = 0
start = pos
l_dsl = []
# seek to end from starting pos
for x in range(start, cil):
if (x in r):
dslc += abs(pos-x)
l_dsl.append(abs(pos-x))
pos = x
r.remove(x)
f.write(str(x))
f.write("-")
# seek back up from end to 0
count = cil
while count >= 0:
if (count in r):
dslc += abs(pos-count)
l_dsl.append(abs(pos-count))
pos = count
r.remove(count)
f.write(str(count))
f.write("-")
count -= 1
lt = [time * d for d in l_dsl]
m_dslc = dslc / n
m_seek = time * dslc / n
name = f.name
vd = statistics.variance(l_dsl)
dpd = statistics.stdev(l_dsl)
vt = statistics.variance(lt)
dpt = statistics.stdev(lt)
f.close()
print('\nSCAN')
print('Quantidade de deslocamento:', dslc)
print('Quantidade media de deslocamento:', m_dslc)
print('Variancia:', vd)
print('Desvio padrao:', dpd)
print('Tempo medio de deslocamento:', m_seek)
print('Variancia tempo:', vt)
print('Desvio padrao tempo:', dpt)
print('Arquivo:', name)
# Circular Scan
def cscan(cil, pos, time, req):
r = copy.copy(req)
f = open("cscan.txt", "w")
dslc = 0
n = len(r)
start = pos
l_dsl = []
# seek to end from starting pos
for x in range(start,cil):
if (x in r):
dslc += abs(pos-x)
l_dsl.append(abs(pos-x))
pos = x
r.remove(x)
f.write(str(x))
f.write("-")
# go back to beginning and continue seeking
end = max(r)
for i in range(0,end):
if (i in r):
dslc += abs(pos-i)
l_dsl.append(abs(pos-i))
pos = i
r.remove(i)
f.write(str(i))
f.write("-")
lt = [time * d for d in l_dsl]
m_dslc = dslc / n
m_seek = time * dslc / n
name = f.name
vd = statistics.variance(l_dsl)
dpd = statistics.stdev(l_dsl)
vt = statistics.variance(lt)
dpt = statistics.stdev(lt)
f.close()
print('\nCSCAN')
print('Quantidade de deslocamento:', dslc)
print('Quantidade media de deslocamento:', m_dslc)
print('Variancia:', vd)
print('Desvio padrao:', dpd)
print('Tempo medio de deslocamento:', m_seek)
print('Variancia tempo:', vt)
print('Desvio padrao tempo:', dpt)
print('Arquivo:', name)
def main():
args = sys.argv[1:]
while len(args) < 4:
print('\n[python3]EXECUTE: python main.py <qnt_cilindros> <posicao_inicial> <tempo_seek> <nome_arquivo>\n')
exit(-1)
qnt_cilindros = int(args[0])
posicao_inicial = int(args[1])
tempo_seek = int(args[2])
nome_arquivo = args[3]
req = read_file(nome_arquivo)
print(req)
fifo(posicao_inicial, tempo_seek, req)
ssf(posicao_inicial, tempo_seek, req)
scan(qnt_cilindros, posicao_inicial, tempo_seek, req)
cscan(qnt_cilindros, posicao_inicial, tempo_seek, req)
main()