Value error while simulating with simpy package in python

639 views Asked by At

I want to simulate first 10 customers using simpy package. I am getting error I could not able to find what is actual error. Please, help me.

Code is below:

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)

The customer function is below:

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))

Running the simulation

# Start processes and run
proc = env.process(source(env, number, interval, counter,patientData))
env.run(until=proc)

I am getting the error like below:

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().

I have checked the service time values and inter arrival times. All the values are greater than Zero. Please, help me. I have been trying this for 2 days and searched about it but I did not find any satisfactory answer.

0

There are 0 answers