-
Notifications
You must be signed in to change notification settings - Fork 3
/
SSTF.py
43 lines (41 loc) · 1.34 KB
/
SSTF.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
def SSTF(sequence,start):
temp = sequence.copy()
def next_in_sequence(seq,val):
diff = 0
mindiff = math.inf
nextval = 0
#print(seq)
for i in range(0,len(seq)):
if(seq[i]!=val):
diff = abs(seq[i]-val)
if(diff<mindiff):
mindiff=diff
nextval = seq[i]
return nextval
temp.insert(0,start)
val = start
x = []
y = []
size = 0
x.append(start)
headmovement = 0
while(len(temp)):
val = next_in_sequence(temp,val)
#print(val)
x.append(val)
temp.remove(val)
size = len(x)
for i in range(0,size):
y.append(-i)
if i!=(size-1):
headmovement = headmovement + abs(x[i]-x[i+1])
string = 'Headmovement = ' + str(headmovement) + ' cylinders'
string2 = str(x)
plt.plot(x,y, color="green", markerfacecolor = 'blue', marker='o', markersize = 5, linewidth = 2, label="SSTF")
plt.ylim = (0,size)
plt.xlim = (0,CYLINDER_MAX)
plt.yticks([])
plt.title("Shortest Seek Time First Scheduling Algorithm")
plt.text(182.5, -10.85, string, horizontalalignment='center',verticalalignment='center',fontsize=12)
plt.text(182.5, -11.5, string2, horizontalalignment='center',verticalalignment='center',fontsize=12)
plt.show()