-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk_scheduling - seek time without graph.py
104 lines (91 loc) · 2.4 KB
/
disk_scheduling - seek time without graph.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
l = [98, 183, 41, 122, 14, 124, 65, 67]
h = 53
rang = [0, 199]
l.insert(0, h)
print(l)
n =len(l)
def fcfs():
global l, n
seek_time = 0
print('FCFS:')
for i in range(1, n):
print('(', l[i], '-', l[i-1], ')', end = ' + ')
seek_time += abs(l[i] - l[i-1])
print('\nSeek Time: ', seek_time)
def sstf():
global l, n
li = [a for a in l]
seek_time = 0
print('SSTF:')
now = li[0]
li.remove(li[0])
for i in range(n-1):
small = 10000000
ele = -1
for j in li:
if (abs(now - j) < small and now - j):
small = abs(now - j)
ele = j
print('(', now, '-', ele, ')', end = ' + ')
seek_time += abs(now - ele)
if now in li:
li.remove(now)
now = ele
print('\nSeek Time: ', seek_time, '\n')
def scan():
global l, n, h, rang
li = [a for a in l]
li.append(rang[1])
li.sort()
seek_time = 0
print('SCAN:')
ind = li.index(h)
li = li[ind: ] + li[:ind][::-1]
for i in range(0, n):
print('(', li[i], '-', li[i+1], ')', end = ' + ')
seek_time += abs(li[i] - li[i+1])
print('\nSeek Time: ', seek_time, '\n')
def cscan():
global l, n, h, rang
li = [a for a in l]
li.append(rang[0])
li.append(rang[1])
li.sort()
seek_time = 0
print('C-SCAN:')
ind = li.index(h)
li = li[ind: ] + li[:ind]
for i in range(0, n+1):
print('(', li[i], '-', li[i+1], ')', end = ' + ')
seek_time += abs(li[i] - li[i+1])
print('\nSeek Time: ', seek_time, '\n')
def look():
global l, n, h, rang
li = [a for a in l]
li.sort()
seek_time = 0
print('LOOK:')
ind = li.index(h)
li = li[ind: ] + li[:ind][::-1]
for i in range(0, n-1):
print('(', li[i], '-', li[i+1], ')', end = ' + ')
seek_time += abs(li[i] - li[i+1])
print('\nSeek Time: ', seek_time, '\n')
def clook():
global l, n, h, rang
li = [a for a in l]
li.sort()
seek_time = 0
print('C-LOOK:')
ind = li.index(h)
li = li[ind: ] + li[:ind]
for i in range(0, n-1):
print('(', li[i], '-', li[i+1], ')', end = ' + ')
seek_time += abs(li[i] - li[i+1])
print('\nSeek Time: ', seek_time, '\n')
fcfs()
sstf()
scan()
cscan()
look()
clook()