============ 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 try to buy a random number (1--6) of 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 than 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