diff --git a/logic/clook.py b/logic/clook.py index 7d326bc..ded7beb 100644 --- a/logic/clook.py +++ b/logic/clook.py @@ -6,21 +6,30 @@ def calculate_metrics(path, start): def CLOOK(requests, start, end, initial_position): requests = sorted(requests) path = [] + if initial_position <= start: - path = [start] + requests + # Move upwards to handle all requests + path = [initial_position] + requests elif initial_position >= end: - path = requests + [end] + # Handle all requests from the top + path = [initial_position] + requests else: - path = [r for r in requests if r >= initial_position] + [r for r in requests if r < initial_position] - path = [initial_position] + path + # Split requests into those above and below the initial position + above = [r for r in requests if r >= initial_position] + below = [r for r in requests if r < initial_position] + # Move upwards, then jump to the lowest request and continue upwards + path = [initial_position] + above + below + total_distance, avg_seek_time = calculate_metrics(path, initial_position) return path, total_distance, avg_seek_time + + if __name__ == "__main__": - requests = [3, 15, 6, 18, 2, 10, 8, 12] + requests = [1, 9, 4, 7, 3, 6] initial_position = 5 start = 0 - end = 19 + end = 10 path, total_distance, avg_seek_time = CLOOK(requests, start, end, initial_position) print("CLOOK Path:", path) @@ -28,10 +37,10 @@ def CLOOK(requests, start, end, initial_position): print("Average Seek Time:", avg_seek_time) #Results - ''' -CLOOK Path: [5, 6, 8, 10, 12, 15, 18, 2, 3] -Total Distance: 30 -Average Seek Time: 3.3333333333333335 - ''' +''' +CLOOK Path: [5, 6, 7, 9, 1, 3, 4] +Total Distance: 15 +Average Seek Time: 2.142857142857143 +''' diff --git a/logic/cscan.py b/logic/cscan.py index 3e1e215..daea53d 100644 --- a/logic/cscan.py +++ b/logic/cscan.py @@ -17,11 +17,11 @@ def CSCAN(requests, start, end, initial_position): return path, total_distance, avg_seek_time if __name__ == "__main__": - requests = [3, 15, 6, 18, 2, 10, 8, 12] + requests = [1, 9, 4, 7, 3, 6] initial_position = 5 start = 0 - end = 19 - + end = 10 +''' path, total_distance, avg_seek_time = CSCAN(requests, start, end, initial_position) print("CSCAN Path:", path) print("Total Distance:", total_distance) @@ -29,8 +29,8 @@ def CSCAN(requests, start, end, initial_position): #Results -''' -CSCAN Path: [5, 6, 8, 10, 12, 15, 18, 19, 0, 2, 3] -Total Distance: 36 -Average Seek Time: 3.272727272727273 + +CSCAN Path: [5, 6, 7, 9, 10, 0, 1, 3, 4] +Total Distance: 19 +Average Seek Time: 2.111111111111111 ''' \ No newline at end of file diff --git a/logic/fcfs.py b/logic/fcfs.py index 8a2dc64..b8a0245 100644 --- a/logic/fcfs.py +++ b/logic/fcfs.py @@ -9,7 +9,7 @@ def FCFS(requests, initial_position): return path, total_distance, avg_seek_time if __name__ == "__main__": - requests = [3, 15, 6, 18, 2, 10, 8, 12] + requests = [1, 9, 4, 7, 3, 6] initial_position = 5 path, total_distance, avg_seek_time = FCFS(requests, initial_position) @@ -19,32 +19,7 @@ def FCFS(requests, initial_position): #Results ''' -FCFS Path: [5, 3, 15, 6, 18, 2, 10, 8, 12] -Total Distance: 65 -Average Seek Time: 7.222222222222222 +FCFS Path: [5, 1, 9, 4, 7, 3, 6] +Total Distance: 27 +Average Seek Time: 3.857142857142857 ''' -def calculate_metrics(path, start): - total_distance = sum(abs(path[i] - path[i - 1]) for i in range(1, len(path))) - avg_seek_time = total_distance / len(path) - return total_distance, avg_seek_time - -def FCFS(requests, initial_position): - path = [initial_position] + requests - total_distance, avg_seek_time = calculate_metrics(path, initial_position) - return path, total_distance, avg_seek_time - -if __name__ == "__main__": - requests = [3, 15, 6, 18, 2, 10, 8, 12] - initial_position = 5 - - path, total_distance, avg_seek_time = FCFS(requests, initial_position) - print("FCFS Path:", path) - print("Total Distance:", total_distance) - print("Average Seek Time:", avg_seek_time) - -#Results -''' -FCFS Path: [5, 3, 15, 6, 18, 2, 10, 8, 12] -Total Distance: 65 -Average Seek Time: 7.222222222222222 -''' \ No newline at end of file diff --git a/logic/look.py b/logic/look.py index 99b4050..fb603fc 100644 --- a/logic/look.py +++ b/logic/look.py @@ -17,10 +17,10 @@ def LOOK(requests, start, end, initial_position): return path, total_distance, avg_seek_time if __name__ == "__main__": - requests = [3, 15, 6, 18, 2, 10, 8, 12] + requests = [1, 9, 4, 7, 3, 6] initial_position = 5 start = 0 - end = 19 + end = 10 path, total_distance, avg_seek_time = LOOK(requests, start, end, initial_position) print("LOOK Path:", path) @@ -29,8 +29,8 @@ def LOOK(requests, start, end, initial_position): #Results ''' -LOOK Path: [5, 6, 8, 10, 12, 15, 18, 3, 2] -Total Distance: 29 -Average Seek Time: 3.2222222222222223 +LOOK Path: [5, 6, 7, 9, 4, 3, 1] +Total Distance: 12 +Average Seek Time: 1.7142857142857142 ''' \ No newline at end of file diff --git a/logic/scan.py b/logic/scan.py index 5d97af1..e717faa 100644 --- a/logic/scan.py +++ b/logic/scan.py @@ -17,9 +17,9 @@ def SCAN(requests, start, end, initial_position): return path, total_distance, avg_seek_time if __name__ == "__main__": - requests = [3, 15, 6, 18, 2, 10, 8, 12] + requests = [1, 9, 4, 7, 3, 6] start = 0 - end = 19 + end = 10 initial_position = 5 path, total_distance, avg_seek_time = SCAN(requests, start, end, initial_position) @@ -29,7 +29,7 @@ def SCAN(requests, start, end, initial_position): #Results ''' -SCAN Path: [5, 6, 8, 10, 12, 15, 18, 19, 3, 2] -Total Distance: 31 -Average Seek Time: 3.1 +SCAN Path: [5, 6, 7, 9, 10, 4, 3, 1] +Total Distance: 14 +Average Seek Time: 1.75 ''' diff --git a/logic/sstf.py b/logic/sstf.py index 46b750c..2c9a61a 100644 --- a/logic/sstf.py +++ b/logic/sstf.py @@ -13,7 +13,7 @@ def SSTF(requests, initial_position): return path, total_distance, avg_seek_time if __name__ == "__main__": - requests = [3, 15, 6, 18, 2, 10, 8, 12] + requests = [1, 9, 4, 7, 3, 6] initial_position = 5 path, total_distance, avg_seek_time = SSTF(requests, initial_position) @@ -23,9 +23,9 @@ def SSTF(requests, initial_position): #Results ''' -SSTF Path: [5, 6, 8, 10, 12, 15, 18, 3, 2] -Total Distance: 29 -Average Seek Time: 3.2222222222222223 +SSTF Path: [5, 4, 3, 1, 6, 7, 9] +Total Distance: 12 +Average Seek Time: 1.7142857142857142 ''' \ No newline at end of file