'Process' 和 'int' 实例之间不支持 Simpy '<'

Simpy '<' not supported between instances of 'Process' and 'int'

我正在尝试使用 Simpy 在 Python 中模拟一个简单的供应链环境。我有一个供应商、一个零售商和一个有安全库存的仓库。零售商下订单,仓库发货,如果安全库存低于阈值,则从供应商处订购货物。执行时出现错误

CHECK 1000
100.0
Order number 0 received with demand 339 at 0
Order number 1 received with demand 351 at 0
Order number 2 received with demand 208 at 1
Order number 3 received with demand 223 at 1
Order number 4 received with demand 259 at 1
CHECK 661
66.10000000000001
Order number  0 delivered at  3
Order number 5 received with demand 354 at 3
Order number 6 received with demand 343 at 3
Order number 7 received with demand 383 at 3
Order number 8 received with demand 379 at 5
CHECK 310
31.0
Placing Order to Supplier at  6
Order number  1 delivered at  6
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-95-097951220430> in warehouse_control(env, warehouse_stock_level)
     26       print("Placing Order to Supplier at ", env.now)
---> 27       yield env.timeout(env.process(supplier(env,warehouse_stock_level)))
     28 

3 frames
TypeError: '<' not supported between instances of 'Process' and 'int'

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/simpy/core.py in step(self)
    204             exc = type(event._value)(*event._value.args)
    205             exc.__cause__ = event._value
--> 206             raise exc
    207 
    208     def run(

TypeError: '<' not supported between instances of 'Process' and 'int'

这是我的代码:

SAFETY_STOCK_LEVEL = 1000      # SAFETY STOCK LEVEL IN WAREHOUSE
CUSTOMER_DEMAND = [200,400]   # DEMAND FROM RETAILER
THRESHOLD = 60                # in %
PRODUCTION_TIME = 5           # DAYS TO PRODUCE GOOD BY SUPPLIER
RETAIL_ORDER_TIME = [0,2]     # FREQUENCY OF RETAIL ORDER PLACED IN DAYS
SIMULATION_TIME = 100        # TIEM TO RUN THE SIMULATION
PACK_SEND_TIME = 3            # TIME TO PACK AND SEND TO RETAILER FROM WAREHOUSE

def warehouse_packing_activity(env,order_number,goods_demand,warehouse_activity,warehouse_stock_level):
  """ DO THE PACKING"""
  print("Order number ", order_number," received with demand ", goods_demand, " at ", env.now, sep="")
  
  with warehouse_activity.request() as req:
    start = env.now
    yield req

    yield warehouse_stock_level.get(goods_demand)
    yield env.timeout(PACK_SEND_TIME)
    print("Order number ", order_number, "delivered at ", env.now - start)

def warehouse_control(env,warehouse_stock_level):
  while True:
    print("CHECK", warehouse_stock_level.level)
    print(warehouse_stock_level.level / warehouse_stock_level.capacity * 100)
    if ((warehouse_stock_level.level / warehouse_stock_level.capacity) * 100) < THRESHOLD:
      print("Placing Order to Supplier at ", env.now)
      yield env.timeout(env.process(supplier(env,warehouse_stock_level)))
    
    yield env.timeout(3) #Checking every 3 unit days

def supplier(env,warehouse_stock_level):
  """Supply goods to warehouse when requested"""
  yield env.timeout(PRODUCTION_TIME)
  amount = warehouse_stock_level.capacity - warehouse_stock_level.level
  print("Order quantity is ", amount)
  yield warehouse_stock_level.put(amount)
  print("Replenishment order fullfilled at ", env.now)

  

def retail_order_generator(env,warehouse_activity,warehouse_stock_level):
  """GENERATE ORDER"""
  for i in itertools.count():
    goods_demand = random.randint(*CUSTOMER_DEMAND)
    env.process(warehouse_packing_activity(env,i,goods_demand,warehouse_activity,warehouse_stock_level))
    yield env.timeout(random.randint(*RETAIL_ORDER_TIME))

env = simpy.Environment()
warehouse_activity = simpy.Resource(env,1)
warehouse_stock_level = simpy.Container(env,SAFETY_STOCK_LEVEL,SAFETY_STOCK_LEVEL)
env.process(retail_order_generator(env,warehouse_activity,warehouse_stock_level))
env.process(warehouse_control(env,warehouse_stock_level))

env.run(until=SIMULATION_TIME)

知道我做错了什么吗?提前致谢!

快速浏览了一下,我发现了一个问题(可能还有更多)

env.timeout 想要参数的数字 env.process(supplier(env,warehouse_stock_level)) returns 事件不是数字

尝试将行更改为

yield env.process(supplier(env,warehouse_stock_level))

这意味着等待过程完成