0

我试图模拟从商店获取东西依赖于其他东西的情况。

假设我有一个生产者将物品放入容量有限的存储 S1 中。当且仅当 (1) S1 中有物品并且 S2 中有空间时,这些物品会转移到另一个商店S2

P -> S1 -> S2

问题是我需要从 S1 中删除一个项目以在 S2 中有空间为条件。

在代码中:

from simpy import *

env = Environment()
S1 = Store(env, capacity=1)
S2 = Store(env, capacity=1)

def producer():
    i = 0
    while True:
        yield S1.put(i)
        print("Producer put item: %s"%i)
        i += 1

def s1_to_s2():
    while True:
        item = yield S1.get()
        yield S2.put(item)

env.process(producer())
env.process(s1_to_s2())
env.run(until=20)

产生

Producer put item: 0
Producer put item: 1
Producer put item: 2

我对此建模的方式使它看起来像在 S1 和 S2 之间有 1 个额外的存储插槽,这是我不想要的。由于我有 2 个存储单元,每个容量为 1,生产者应该只能插入 2 个单元。

4

1 回答 1

0

I'm afraid this is not possible with SimPy out-of-the-box. You can, however, subclass Store and the according events to model inter-store-dependencies.

于 2017-03-27T07:57:17.883 回答