Running the Simulation
00:00
Now that the processes available in the theater have been defined, as well as the route a moviegoer will take, it’s time to set up a function to actually run the simulation. Define a new function called run_theater()
, and with this, you’ll pass in the env
(environment) and the num_employees
(number of employees) that you have. So, the num_cashiers
(number of cashiers), the num_servers
(number of servers), and then the num_ushers
(number of ushers).
00:24
You can then create a theater
, and this will be an instance of a Theater
, which also has the env
, the num_cashiers
, num_servers
, and the num_ushers
.
00:40
The manager also notes that when they open, there tends to be a line of moviegoers waiting and ready to go! On average, this is about three people, so if you want to start off with three moviegoers, you can do this with a for
loop.
00:53
So, for moviegoer in range(3):
to run this three times. You’ll say env.process(go_to_movies())
, pass in the env
, the moviegoer
, and the theater
.
01:10 Now, to address additional moviegoers arriving on their own time, you can turn this function into a generator that will loop forever. The manager has informed you that moviegoers tend to arrive to the theater on average every 12 seconds—or one fifth of a minute.
01:26
So you can do something like while True:
and you’ll yield env.timeout()
, and since 12 seconds is a fifth of a minute, you can say something like 0.20
.
01:38
And this will increment the moviegoer
by 1
, so moviegoer += 1
, and send another moviegoer
to the movies. So go_to_movies()
, pass in the env
, the moviegoer
, and the theater
.
01:56 And that’s all there is to it! In the next lesson, you’re going to set up a function to calculate the average wait times so you can see how each simulation performs and compare them.
Become a Member to join the conversation.