I am trying to simulate a simple supply chain environment in Python using Simpy. I have a supplier, a retailer and a warehouse with safety stock. Retailer Places a order, warehouse delivers and if the safety stock goes below threshold, orders goods from suppliers. While executing, I am getting the error
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'
Here is my code:
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)
Any idea what I am doing wrong? Thanks in advance!
Just doing a quick look I see one issue (there may be more)
env.timeout
wants a number for a parameter
env.process(supplier(env,warehouse_stock_level))
returns a event not a number
try changing the line to just
yield env.process(supplier(env,warehouse_stock_level))
which just mean wait until the process is done