使用simpy计算资源的空闲时间?

时间:2017-12-17 15:03:42

标签: python simpy

我正在尝试使用M/M/c来模拟SimPy队列3在Python 3.6上,很容易计算各种效果指标,例如service timewaiting time...但是我似乎无法找到计算idle time资源的方法,我已查看SimPy的文档,但没有运气,请帮助我一直在这好几天

我有一种感觉,我必须延长Resource课程,但我只是不知道Python来完成这项工作

arrival = prng.PRNG(50000)

service = prng.PRNG(10000)

simulation_time =  30.0

service_time = 10.0

arrival_time = 2.5

data = [[], [], [], [], [], [], [], []]

data[3].append(0)

def source(env, counter):
    i = 0
    while True:
        i += 1
        t = arrival.nextExponential(1.0 / arrival_time)
        c = customer(env, i, t, counter, service_time)
        env.process(c)
        yield env.timeout(t)

def customer(env, i, t, counter, service_time):

    arrive = env.now

    data[6].append(len(counter.queue))

    with counter.request() as req:

        data[0].append(i)

        data[1].append(t)

        data[2].append(arrive)

        if (len(data[2])) >= 2:
            n = len(data[2]) - 1
            p = n - 1
            data[3].append(data[2][n] - data[2][p])

        results = yield req

        wait = env.now - arrive

        data[5].append(wait)

        tib = service.nextExponential(1.0 / service_time)

        data[4].append(round(tib, 2))

        data[7].append(wait + tib)

        yield env.timeout(tib)

env = simpy.Environment()

counter = simpy.Resource(env, capacity=5)

env.process(source(env, counter))

env.run(until=simulation_time)

total_wait_time = 0.0

total_time_in_system = 0.0

total_service_time = 0.0

total_interarrival_time = 0.0

print("No.\tArrival Time\tClock Time\tInterarrival Time\tService Time\tWait Time\tQueue Length\tTotal Time In System")

def display(i):
    print()
    print("Average Waiting Time => %.2f Minutes" % (total_wait_time / i))
    print("Average Service Time => %.2f Minutes" % (total_service_time / i))
    print("Average Time Spent In System => %.2f Minutes" % (total_time_in_system / i))
    print("Average Interarrival Time => %.2f Minutes" % (total_interarrival_time / i))

for i in range(0, len(data[0])):
    try:
        id = data[0][i]
        arrivalTime = data[1][i]
        clockTime = data[2][i]
        interarrivalTime = data[3][i]
        serviceTime = data[4][i]
        waitTime = data[5][i]
        queueLength = data[6][i]
        totalTimeInSystem = data[7][i]

        total_wait_time += waitTime

        total_time_in_system += totalTimeInSystem

        total_service_time += serviceTime

        total_interarrival_time += interarrivalTime

        print("%d\t%.2f\t\t%.2f\t\t%.2f\t\t\t%.2f\t\t%.2f\t\t%0d\t\t%.2f" % (id, arrivalTime, clockTime, interarrivalTime, serviceTime, waitTime, queueLength, totalTimeInSystem))
    except IndexError as identifier:
        display(i + 1)
        exit()

display(i + 1)

所以我需要的是资源总数idle time

谢谢

0 个答案:

没有答案