0

我想使用 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, counter, 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, counter, 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, number, interval, counter,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.bool(), a.item(), a.any() or a.all().

我检查了服务时间值和到达时间。所有值都大于零。请帮我。我已经尝试了 2 天并搜索了它,但我没有找到任何令人满意的答案。

4

0 回答 0