【问题标题】:knowing the Store object corresponding to the StoreGet object知道StoreGet对象对应的Store对象
【发布时间】:2018-04-14 16:37:26
【问题描述】:

我有多个进程,每个进程都有其适当的存储,它将以随机的时间间隔与单个进程通信。因为我使用了 Environment.any_of(all_stores.get()),这将返回一个字典,其中键是 StoreGet 对象,值是商店中的值。

我希望有一种方法可以知道字典中的每个条目对应的商店(如果不可能,则处理)。

import simpy,random
def worker(ident,env,sstore):
    while True:
        yield env.timeout(random.randint(0,10))
        # calculation
        sstore.put(random.random())
def mon(env,lstores):
    while True:
        resultat=yield env.any_of([s.get() for s in lstores])
        # calculation depending of the values and the source 
        # need to know the source of each information 
env=simpy.Environment()
lstores=[simpy.Store(env,capacity=1) for x in range(5)]
lworkers=[env.process(worker((i+1),env,lstores[i])) for i in range(5)]
env.process(mon(env,lstores))
env.run(until=30)

【问题讨论】:

    标签: python python-3.x simpy


    【解决方案1】:

    evt.resourceevt.proc 是你的朋友。

    它们在基础Put/Get 事件类中是无证的并且受到威胁:https://bitbucket.org/simpy/simpy/src/e84015dcf54c05868712683fb1d9fcfd2cc44089/src/simpy/resources/base.py?at=default&fileviewer=file-view-default#base.py-29

    【讨论】:

      猜你喜欢
      • 2011-05-07
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多