Tutorial III: Collecting ResultsΒΆ

In the previous tutorials, we defined and simulated our bank for a week, and saw how to access parts of the simulation engine:

>>> import ciw
>>> N = ciw.create_network(
...     Arrival_distributions=[['Exponential', 0.2]],
...     Service_distributions=[['Exponential', 0.1]],
...     Number_of_servers=[3]
... )
>>> ciw.seed(1)
>>> Q = ciw.Simulation(N)
>>> Q.simulate_until_max_time(1440)

We can quickly get a list of all data records collected by all customers have have finished at least one service, using the get_all_records method of the Simulation object:

>>> recs = Q.get_all_records()

This returns a list of named tuples. Each named tuple contains the following information:

  • id_number
  • customer_class
  • node
  • arrival_date
  • waiting_time
  • service_start_date
  • service_time
  • service_end_date
  • time_blocked
  • exit_date
  • destination
  • queue_size_at_arrival
  • queue_size_at_departure

More information on each of these is given in List of Available Results.

Using list comprehension, we can get lists on whichever statistic we like:

>>> # A list of service times
>>> servicetimes = [r.service_time for r in recs]
>>> servicetimes
[2.94463..., 5.96912..., 0.28757..., ..., 10.46244...]

>>> # A list of waits
>>> waits = [r.waiting_time for r in recs]
>>> waits
[0.0, 0.0, 0.20439..., ..., 5.63781...]

Now we can get summary statistics simply by manipulating these lists:

>>> mean_service_time = sum(servicetimes) / len(servicetimes)
>>> mean_service_time

>>> mean_waiting_time = sum(waits) / len(waits)
>>> mean_waiting_time

We now know the mean waiting time of the customers! In next tutorial we will show how to get more representative results (as we have only simulated one given day here).

Further summary statistics can be obtained using external libraries. We recommend numpy, pandas and matplotlib. Using these further statistics and plots can be explored. The histogram of waits below was created using matplotlib, using the following code:

>>> import matplotlib.pyplot as plt 
>>> plt.hist(waits); 
Histogram of waits for Tutorial III.

If we’d like to see how busy or idle the servers have been throughout the simulation run, we can look at the server_utilisation of a Node. This is the average utilisation of each server, which is the amount of time a server was busy (with a customer), divided by the total amount of time the server was on duty:

>>> Q.transitive_nodes[0].server_utilisation

Thus in our bank, on average the servers were busy 60.5% of the time.

The next tutorial will show how to use Ciw to get trustworthy results, and finally find out the average waiting time at the bank.