=============================================== bank11: A simple example using a Monitor =============================================== :Author: G A Vignaux :Date: $Date: 2004/02/19 $ Description ------------- The purpose of this example is show *Monitor* in use to estimate the average waiting time for customers in a bank. The example is taken from the *Bank* tutorial, included in the SimPy documentation. It simulates a bank with customers who arrive at random to be served at one of two counters. A customer chooses the shortest queue to join and takes a random time to be served. Code ----- .. include:: bank11.py :literal: Comments --------- The *Customer* class is a SimPy process with a PEM called *visit*. On arrival the time is recorded and the shortest queue chosen (variable *join*). The function *NoInSystem* is used to find the number at each counter. A request is made for that particular *counter[join]*, and, when service starts, the waiting time, *wait* is calculated. This is Monitored. The actual time for service, *tib* is sampled (from a distribution with mean *timeInBank*) and the counter held for that time before release. Customers are generated using the *Source* process which creates and activates a *Customer* at exponential (random) delays with mean *interval*. The problem is set up in the function *model*. Doing this within a function is a little clumsy as it involves the use either of a number of arguments or, as I have done here, of global variables, like *counter* and *waitMonitor*, but it means that a number of independent runs can be made within the same script. Here I did not use the full power of this technique. I ran a single run of 50 customers (in the call of *generate*) for a maximum time of 2000. The result is: .. include:: bank11.out :literal: