-
Notifications
You must be signed in to change notification settings - Fork 3
/
CLOOK.py
77 lines (72 loc) · 2.63 KB
/
CLOOK.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
def CLOOK(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)
right.sort(reverse = True)
for i in right:
x.append(i)
x_approx.append(start)
x_approx.append(min(x))
x_approx.append(max(x))
x_approx.append(x[-1])
headmovement_approx = abs(start-min(x))
headmovement_approx = headmovement_approx + abs(min(x)-max(x))
headmovement_approx = headmovement_approx + abs(max(x)-x[-1])
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)
left.sort()
for i in left:
x.append(i)
x_approx.append(start)
x_approx.append(max(x))
x_approx.append(min(x))
x_approx.append(x[-1])
headmovement_approx = abs(start-max(x))
headmovement_approx = headmovement_approx + abs(max(x)-min(x))
headmovement_approx = headmovement_approx + abs(min(x)-x[-1])
y_approx.append(0)
size = len(x)
for i in range(0,size):
y.append(-i)
if((x[i]==min(x) or x[i]==max(x))and(i!=size)):
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="CLOOK")
plt.plot(x_approx,y_approx, dashes = [6,2] , color="red", markerfacecolor = 'red', marker='D', markersize = 5, linewidth = 0.5, label="Approx CLOOK")
plt.ylim = (0,size)
plt.xlim = (0,CYLINDER_MAX)
plt.yticks([])
plt.title("CLOOK 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()