-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCAN__CSCAN.py
116 lines (87 loc) · 4.17 KB
/
SCAN__CSCAN.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
import numpy as np
def SCAN(total_tracks, current_head, direction, requested_tracks):
outermost_track = 0
innermost_track = total_tracks
track_list = []
if direction.upper() == "U":
track_list = [innermost_track, current_head]
elif direction.upper() == "D":
track_list = [outermost_track, current_head]
track_list.extend(requested_tracks)
track_list.sort()
sequence = []
if direction.upper() == "U":
upward_scan = [track for track in track_list if current_head <= track]
downward_scan = [track for track in reversed(track_list) if current_head > track]
sequence = upward_scan + downward_scan
elif direction.upper() == "D":
upward_scan = [track for track in track_list if current_head < track]
downward_scan = [track for track in reversed(track_list) if current_head >= track]
sequence = downward_scan + upward_scan
head_movements_calculation_string = []
total_head_movements = 0
currentTime = 0
rand_floats = [currentTime]
for i in range(len(sequence)-1):
currentTime += np.random.random_integers(0, 10)
if currentTime in rand_floats:
currentTime += 0.5
rand_floats.append(currentTime)
for index in range(len(sequence) - 1):
total_head_movements += abs(sequence[index] - sequence[index + 1])
if index == len(sequence) - 1:
plus_symbol = ""
else:
plus_symbol = " +"
if sequence[index] > sequence[index + 1]:
bigger = sequence[index]
smaller = sequence[index + 1]
else:
bigger = sequence[index + 1]
smaller = sequence[index]
head_movements_calculation_string.append("(" + str(bigger) + "-" + str(smaller) + ")" + plus_symbol)
head_movements_calculation_string = " ".join(head_movements_calculation_string)
head_movements_calculation_string = head_movements_calculation_string.rstrip('+')
print(f"SCAN: {head_movements_calculation_string}")
print(f"SCAN: {sequence}")
return rand_floats, total_head_movements, head_movements_calculation_string, sequence
def CSCAN(total_tracks, current_head, direction, requested_tracks):
outermost_track = 0
innermost_track = total_tracks
track_list = [outermost_track, innermost_track, current_head]
track_list.extend(requested_tracks)
track_list.sort()
sequence = []
if direction.upper() == "U":
upward_scan = [track for track in track_list if current_head <= track]
downward_scan = [track for track in track_list if current_head > track]
sequence = upward_scan + downward_scan
elif direction.upper() == "D":
upward_scan = [track for track in reversed(track_list) if current_head < track]
downward_scan = [track for track in reversed(track_list) if current_head >= track]
sequence = downward_scan + upward_scan
head_movements_calculation_string = []
total_head_movements = 0
currentTime = 0
rand_floats = [currentTime]
for i in range(len(sequence)-1):
currentTime += np.random.random_integers(0, 10)
if currentTime in rand_floats:
currentTime += 0.5
rand_floats.append(currentTime)
for index in range(len(sequence) - 1):
total_head_movements += abs(sequence[index] - sequence[index + 1])
if index == len(sequence) - 1:
plus_symbol = ""
else:
plus_symbol = " +"
if sequence[index] > sequence[index + 1]:
bigger = sequence[index]
smaller = sequence[index + 1]
else:
bigger = sequence[index + 1]
smaller = sequence[index]
head_movements_calculation_string.append("(" + str(bigger) + "-" + str(smaller) + ")" + plus_symbol)
head_movements_calculation_string = " ".join(head_movements_calculation_string)
head_movements_calculation_string = head_movements_calculation_string.rstrip('+')
return rand_floats, total_head_movements, head_movements_calculation_string, sequence