1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
============
Movie Renege
============
Covers:
- Resources: Resource
- Condition events
- Shared events
This examples models a movie theater with one ticket counter selling tickets
for three movies (next show only). People arrive at random times and triy to
buy a random number (1--6) tickets for a random movie. When a movie is sold
out, all people waiting to buy a ticket for that movie renege (leave the
queue).
The movie theater is just a container for all the related data (movies, the
counter, tickets left, collected data, ...). The counter is
a :class:`~simpy.resources.resource.Resource` with a capacity of one.
The *moviegoer* process starts waiting until either it's his turn (it acquires
the counter resource) or until the *sold out* signal is triggered. If the
latter is the case it reneges (leaves the queue). If it gets to the counter,
it tries to buy some tickets. This might not be successful, e.g. if the process
tries to buy 5 tickets but only 3 are left. If less then two tickets are left
after the ticket purchase, the *sold out* signal is triggered.
Moviegoers are generated by the *customer arrivals* process. It also chooses a
movie and the number of tickets for the moviegoer.
.. literalinclude:: code/movie_renege.py
The simulation's output:
.. literalinclude:: code/movie_renege.out
|