我想用simpy模拟一个超市结账,包括
Simpy提供了许多不同的概念,如流程、资源、存储等。 我尝试了以下方法:
import simpy
FEEDIN_TIME = 3
SCAN_TIME = 1
def myProcess(env, jobId):
# describe the process
feed2clerk = env.process(productInfeed(env, jobId, belt))
yield feed2clerk
bufferInfeed1_ = env.process(bufferInfeed1(env, jobId, buffer1))
yield bufferInfeed1_
bufferInfeed2_ = env.process(bufferInfeed2(env, jobId, buffer2))
yield bufferInfeed2_
def productInfeed(env, jobId, res):
with res.request() as req:
yield req
print('Product %d is moving to clerk 1 at %d' % (jobId,env.now))
feedin_duration = FEEDIN_TIME
yield env.timeout(feedin_duration)
print('Product %d arrived in clerk at %d' % (jobId,env.now))
prodScan = env.process(productScan(env, jobId, clerk))
yield prodScan
def productScan(env, jobId, res):
with res.request() as req:
yield req
print('Product %d is scanning at %d' % (jobId,env.now))
scanin_duration = SCAN_TIME
yield env.timeout(scanin_duration)
print('Product %d is scanned at %d' % (jobId,env.now))
def bufferInfeed1(env, jobId, res):
with res.request() as req:
yield req
print('Product %d is moving to buffer zone 1 at %d' % (jobId,env.now))
feedin_duration = FEEDIN_TIME
yield env.timeout(feedin_duration)
print('Product %d arrived in buffer zone 1 at %d' % (jobId,env.now))
def bufferInfeed2(env, jobId, res):
with res.request() as req:
yield req
print('Product %d is moving to buffer zone 2 at %d' % (jobId,env.now))
feedin_duration = FEEDIN_TIME
yield env.timeout(feedin_duration)
print('Product %d arrived in buffer zone 2 at %d' % (jobId,env.now))
# Creating environment
env = simpy.Environment()
# Creating resources
belt = simpy.Resource(env, capacity=1)
clerk = simpy.Resource(env, capacity=1)
buffer1 = simpy.Resource(env, capacity=1)
buffer2 = simpy.Resource(env, capacity=1)
# Describe the process
for i in range(4):
env.process(myProcess(env, i))
# run the process
env.run()
它产生以下结果
Product 0 is moving to clerk 1 at 0
Product 0 arrived in clerk at 3
Product 0 is scanning at 3
Product 0 is scanned at 4
Product 1 is moving to clerk 1 at 4
Product 0 is moving to buffer zone 1 at 4
Product 1 arrived in clerk at 7
Product 0 arrived in buffer zone 1 at 7
Product 1 is scanning at 7
Product 0 is moving to buffer zone 2 at 7
Product 1 is scanned at 8
Product 2 is moving to clerk 1 at 8
Product 1 is moving to buffer zone 1 at 8
Product 0 arrived in buffer zone 2 at 10
Product 2 arrived in clerk at 11
...
我至少做到了
其他要求我都没有成功。我的问题有什么样的样板吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐