Course
project: Souvlaki Taverna Simulation
Objective
Develop
objects that represent objects in the real world.
Explanation
Imagine
you are thinking about opening a Souvlaki Taverna on a popular location. You
need to decide how large the store should be and how many tables there should
be. If you plan too small, customers will be turned away when there is
insufficient space, and you will lose profits. On the other hand, if you plan
too large, most of the seats will be unused, and you will be paying useless rent
on the space and still lose profits. So you need to choose approximately the
right
You
decide to do a simulation. You first examine similar operations in comparable
locations and form a model that includes, among other factors, an estimation of
the number of customers you can expect to arrive in any period of time, the
length of time it will take a customer to choose a flavor and the length of time
the customer will then sit at a table and eat ice cream. Based on this, you can
design a simulation.
Objects
in the simulation represent objects in the real world, and are programmed to
react as much as possible as the real objects would react.
A priority queue is used to store a representation of “events” that
are waiting to happen. This queue is stored in order, based on the time the
event should occur, so the smallest element will always be the next event to be
modeled. As an event occurs, it can spawn other events. These subsequent events
are placed into the queue as well. Execution continues until all events have
occurred or until a preset time for the simulation is exceeded.
To
see how we might design a simulation of the souvlaki taverna, consider a typical
scenario. A group of customers arrive at the taverna. From the measurements of
similar stores we derive a probability that indicates how frequently this
occurs. For example, suppose we assume that groups will consist of one to five
people, selected uniformly over the range. (In actual simulations the
distribution would seldom be uniform. For example, groups of size two and three
might predominate, with groups of size one and groups larger than three being
relatively less frequent. The mathematics involved in forming nonuniform
distributions is subtle and not particularly relevant to our discussion. We will
therefore use uniform distributions throughout.) These groups will arrive at
times spaced from one to ten minutes apart, again selected uniformly. Once they
arrive, a group will either be seated or see that there no seats and leave. If
seated, they will take from 2 to 10 minutes to order, and once they order, they
will remain from 15 to 35 minutes in the taverna. We know that every customer
order from one to three souvlakis and that the store makes a profit of 35 euros
on each souvlaki.
The
primary object in the simulation is the taverna itself. It might seem odd to
provide “behavior” for an inanimate object such as a taverna, but we can
think of the taverna as a useful abstraction for the servers and managers who
work in the taverna. The taverna manages two data items: the number of available
seats and the amount of profit generated. The behavior of the store can be
described by the following list.
·
When
a customer group arrives, the size of the group is compared to the number of
seats. If insufficient seats are available, the group leaves. Otherwise, the
group is seated and the number of seats decreased.
·
When
a customer orders and is served, the amount of profit is computed.
·
When
a customer group leaves, the seats are released for another customer group.