import math
def avg_seek_length(list = []):
sum = 0
for i in range(0, len(list) - 1):
sum += int(abs(list[i] - list[i + 1]))
print(sum / len(list))
def handle_data(list= []):
if abs(list[0] - list[1]) > abs(list[2] - list[1]):
return list[2]
elif abs(list[0] - list[1]) < abs(list[2] - list[1]):
return list[0]
return None
if __name__=="__main__":
start = 100
os = [88,147,95,177,94,150,102,175,138]
# ----------- FCFS ------------------
FCFS = os
FCFS.insert(0,start)
FCFS_sum = 0
print("**********FCFS**********")
print(FCFS)
#---------- FCFS平均寻道长度 ----------
print("平均寻道长度")
avg_seek_length(FCFS)
# ---------- CSCAN ------------------
one_handle_os = os
one_handle_os.sort(reverse=False)
for i in range(0, len(one_handle_os)):
if one_handle_os[i] >= start:
CSCAN = one_handle_os[i::]
for j in range(0, i):
CSCAN.append(one_handle_os[j])
break
print("**********CSCAN**********")
print(CSCAN)
# ---------- CSCAN平均寻道长度 ----------
print("平均寻道长度")
avg_seek_length(CSCAN)
# -------- SCAN --------------------
two_handle_os = os
two_handle_os.sort(reverse=False)
for i in range(0, len(two_handle_os)):
if two_handle_os[i] >= start:
SCAN = two_handle_os[i::]
for j in range(i-1,-1,-1):
SCAN.append(two_handle_os[j])
break
print("**********SCAN**********")
print(SCAN)
# ---------- SCAN平均寻道长度 ----------
print("平均寻道长度")
avg_seek_length(SCAN)
# ---------- SSTF ------------------
three_handle_os = os
SSTF = []
handle = []
three_handle_os.sort(reverse=False)
for item in three_handle_os:
differ = 999
for item in three_handle_os:
if differ > abs(item - start) :
differ = abs(item - start)
new_start = item
SSTF.append(new_start)
three_handle_os.remove(new_start)
for item in three_handle_os:
SSTF.append(item)
print("**********SSTF**********")
print(SSTF)
# ---------- SSTF平均寻道长度 ----------
print("平均寻道长度")
avg_seek_length(SSTF)