-
Notifications
You must be signed in to change notification settings - Fork 3
/
SCAN.py
74 lines (70 loc) · 2.43 KB
/
SCAN.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
def SCAN(sequence,start,direction):
temp = sequence.copy()
left = []
right = []
x = []
y = []
x_approx = []
y_approx = []
headmovement = 0
headmovement_approx = 0
x.append(start)
if(direction=="Left"):
for i in temp:
if i<start:
left.append(i)
else:
right.append(i)
left.sort(reverse = True)
for i in left:
x.append(i)
x.append(0)
right.sort()
for i in right:
x.append(i)
x_approx.append(start)
x_approx.append(min(x))
x_approx.append(max(x))
headmovement_approx = abs(start-0)
headmovement_approx = headmovement_approx + abs(0-max(x))
elif(direction=="Right"):
for i in temp:
if i>start:
right.append(i)
else:
left.append(i)
right.sort()
for i in right:
x.append(i)
x.append(CYLINDER_MAX)
left.sort(reverse = True)
for i in left:
x.append(i)
x_approx.append(start)
x_approx.append(max(x))
x_approx.append(min(x))
headmovement_approx = abs(start-199)
headmovement_approx = headmovement_approx + abs(199-min(x))
y_approx.append(0)
size = len(x)
for i in range(0,size):
y.append(-i)
if(x[i]==0 or x[i]==199):
y_approx.append(-i)
if i!=(size-1):
headmovement = headmovement + abs(x[i]-x[i+1])
else:
y_approx.append(-i)
string = 'Headmovement = ' + str(headmovement) + ' cylinders'
string2 = str(x)
string3 = 'Approx Headmovement = ' + str(headmovement_approx) + ' cylinders'
plt.plot(x,y, color="green", markerfacecolor = 'blue', marker='o', markersize = 5, linewidth = 2, label="SCAN")
plt.plot(x_approx,y_approx, dashes = [6,2] , color="red", markerfacecolor = 'red', marker='D', markersize = 5, linewidth = 0.5, label="Approx SCAN")
plt.ylim = (0,size)
plt.xlim = (0,CYLINDER_MAX)
plt.yticks([])
plt.title("SCAN Scheduling Algorithm")
plt.text(182.5, -10.85, string, horizontalalignment='center',verticalalignment='center',fontsize=12)
plt.text(182.5, -12.5, string2, horizontalalignment='center',verticalalignment='center',fontsize=12)
plt.text(182.5, -11.5, string3, horizontalalignment='center',verticalalignment='center',fontsize=12)
plt.show()