问题描述
我想使用simpy包模拟前10个客户。我遇到错误,无法找到实际错误。请帮帮我。
代码如下:
Source function is like below. SRTFunc is used to get service time.
data =pd.read_csv(path)
data=data.head(10)
number = len(data) # Total number of customers
interval = data['timeBtArrival'] # Generate new customers in minutes
customerData = data
env = simpy.Environment()
counter = simpy.Resource(env,capacity=4)
def source(env,number,interval,counter,customerData):
"""Source generates customers randomly"""
for i in range(number):
value1 = SRTFunc(p1=customerData["col1"][i],p2=customerData["col2"]
[i],p3=customerData["col3"][i],p4= customerData['col4'][i])
c = customer(env,'customer%02d' %i,timetoService= (value1))
env.process(c)
t= customerData['timeBtArrival'][i] # Inter arrival time between the customers in minutes
yield env.timeout(t)
客户功能如下:
def customer(env,name,timetoService):
"""Customer arrives,is served and leaves."""
arrive = env.Now
print('%7.4f %s: Here I am' % (arrive,name))
with counter.request() as req:
yield req
wait = env.Now - arrive
print('%s waited %6.3f' % (name,wait))
yield env.timeout(timetoService)
print('%s Finished at %7.4f' % (name,env.Now))
运行模拟
# Start processes and run
proc = env.process(source(env,patientData))
env.run(until=proc)
我收到如下错误:
0.0000 Customer00: Here I am
Customer00 waited 0.000
1.0000 Customer01: Here I am
Customer01 waited 0.000
9.0000 Customer02: Here I am
Customer02 waited 0.000
11.0000 Customer03: Here I am
Customer03 waited 0.000
13.0000 Customer04: Here I am
Customer00 Finished at 18.0000
Customer04 waited 5.000
Customer01 Finished at 19.0000
Customer02 Finished at 27.0000
Customer03 Finished at 29.0000
Customer04 Finished at 36.0000
39.0000 Customer05: Here I am
Customer05 waited 0.000
Traceback (most recent call last):
File "<ipython-input-5-c616845faff0>",line 23,in customer
yield env.timeout(srTime)
File "C:\Users\algol\Anaconda3\lib\site-packages\simpy\events.py",line 230,in __init__
if delay < 0:
File "C:\Users\algol\Anaconda3\lib\site-packages\pandas\core\generic.py",line 1479,in __nonzero__
f"The truth value of a {type(self).__name__} is ambiguous. "
ValueError: The truth value of a Series is ambiguous. Use a.empty,a.bool(),a.item(),a.any() or a.all().
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<ipython-input-6-39f233a6cad2>",line 2,in <module>
env.run(until=proc)
File "C:\Users\algol\Anaconda3\lib\site-packages\simpy\core.py",line 254,in run
self.step()
File "C:\Users\algol\Anaconda3\lib\site-packages\simpy\core.py",line 206,in step
raise exc
ValueError: The truth value of a Series is ambiguous. Use a.empty,a.any() or a.all().
我已经检查了服务时间值和到达时间。所有值都大于零。 请帮我。我已经尝试了2天并进行了搜索,但没有找到满意的答案。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)