# How to Simulate For a Certain Number of CustomersΒΆ

A simulation run may be terminated once a certain number of customers have passed through. This can be done using the `simulate_until_max_customers` method. The method takes in a variable `max_customers`. There are three methods of counting customers:

• `'Finish'`: Simulates until `max_customers` has reached the Exit Node.

• `'Arrive'`: Simulates until `max_customers` have spawned at the Arrival Node.

• `'Accept'`: Simulates until `max_customers` have been spawned and accepted (not rejected) at the Arrival Node.

The method of counting customers is specified with the optional keyword argument `method`. The default value is is `'Finish'`.

Consider an M/M/1/3 queue:

```>>> import ciw
>>> N = ciw.create_network(
...     arrival_distributions=[ciw.dists.Exponential(rate=10)],
...     service_distributions=[ciw.dists.Exponential(rate=5)],
...     number_of_servers=[1],
...     queue_capacities=[3]
... )
```

To simulate until 30 customers have finished service:

```>>> ciw.seed(1)
>>> Q = ciw.Simulation(N)
>>> Q.simulate_until_max_customers(30, method='Finish')
>>> recs = Q.get_all_records()
>>> len([r for r in recs if r.record_type=="service"])
30
```

To simulate until 30 customers have arrived:

```>>> ciw.seed(1)
>>> Q = ciw.Simulation(N)
>>> Q.simulate_until_max_customers(30, method='Arrive')
>>> recs = Q.get_all_records()
>>> (
...     len([r for r in recs if r.record_type=="service"]),
...     len(Q.nodes[1].all_individuals),
...     len([r for r in recs if r.record_type=="rejection"])
... )
(13, 4, 13)
```

To simulate until 30 customers have been accepted:

```>>> ciw.seed(1)
>>> Q = ciw.Simulation(N)
>>> Q.simulate_until_max_customers(30, method='Accept')
>>> recs = Q.get_all_records()
>>> (
...     len([r for r in recs if r.record_type=="service"]),
...     len(Q.nodes[1].all_individuals)
... )
(27, 3)
```