Python-磁盘调度算法

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)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

窗外藏深海

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值