【问题标题】:Queue size appears to be the ENV size in SimPy队列大小似乎是 SimPy 中的 ENV 大小
【发布时间】:2016-08-28 19:15:48
【问题描述】:

我刚刚开始进行事件模拟,但在监控队列时遇到了一些问题。

似乎每次我检查队列时,它实际上都在显示 Env.now。有什么建议吗?

import simpy

num_of_machines = 2

env = simpy.Environment()
bcs = simpy.Resource(env, capacity=num_of_machines)

def monitor(resource):
     """This is our monitoring callback."""

     print('Queue size: %s' % len(resource.queue))

def process_client(env, name):

    with bcs.request() as req:
        yield req
        print('%s starting to charge at %s' % (name, env.now))
        yield env.timeout(90)
        print('%s ending charge at %s' % (name, env.now))
        monitor(bcs)



def setup(env):
    i = 0

    while True:
        i += 1
        yield env.timeout(1)

        env.process(process_client(env, ('Car %s' % i)))

env.process(setup(env))

env.run(until=300)

结果:

Car 1 starting to charge at 1
Car 2 starting to charge at 2
Car 1 ending charge at 91
Queue size: 88
Car 3 starting to charge at 91
Car 2 ending charge at 92
Queue size: 88
Car 4 starting to charge at 92
Car 3 ending charge at 181
Queue size: 176
Car 5 starting to charge at 181
Car 4 ending charge at 182
Queue size: 176
Car 6 starting to charge at 182
Car 5 ending charge at 271
Queue size: 264
Car 7 starting to charge at 271
Car 6 ending charge at 272
Queue size: 264
Car 8 starting to charge at 272

【问题讨论】:

  • 那么你的问题到底是什么?
  • 我想知道有多少辆车在排队等待充电

标签: python simpy


【解决方案1】:

您在每个时间步生成一个process_client(),因此当这些进程中的第一个在 90 个时间步后完成时,您已经创建了 90 个正在排队的新进程。所以你的数字看起来很正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2010-11-24
    • 2014-11-05
    • 1970-01-01
    • 2018-10-25
    • 2018-01-24
    • 1970-01-01
    相关资源
    最近更新 更多