Chapter 12 - Simulation and Modeling
(12.1) - Introduction
In this chapter we examine computational modeling -
an application of computers that is having a major impact on
chemistry, biology, medicine, meteorology, ecology, geography,
economics, and a number of other quantitative sciences.
(12.2) - Computational Modeling
(12.2.1) - Introduction to Systems and Models
The scientific method is a fundamental way of obtaining
new scientific knowledge:
- observe the behavior of a system;
- formulate a hypothesis that tries to explain the behavior; and
- carry out experiments to either prove or disprove the
validity of the hypothesis.
Scientists often conduct their experiments on a model of the
system they are observing. Before the advent of computers the
models were physical models; e.g., a model airplane in a wind
tunnel to see how a full-sized aircraft would behave. Now the
models are often computational models or simulation
models running a set of mathematical equations and/or
algorithms on a computer.
There are a number of reasons why one might construct a
simulation model of a physical system:
- the system may not yet exist.
- the system may be a social system, like welfare policies
or labor practices, that can only be simulated on a computer.
- it may be dangerous to experiment on the actual system.
- it may take too much time to construct a physical model.
- the system may change too slowly (like the birth of a
star) or too quickly (like the 10-15-second
lifetime of an atomic particle) to be accurately measured.
- it is easier to change the parameters of a simulation
than a physical model.
(12.2.3) - An Example of Model Building
An owner of a new take-out restaurant under construction
wonders how many server stations should be built:
- if there are not enough server stations then the
lines will be too long and many customers will leave; or
- if there are too many server stations then money will
be wasted constructing them and hiring personnel to man them.
Figure 12.3 is a model of the take-out restaurant
with arriving customers standing in a single line waiting
to be served by one of the N servers: S1,
S2, S3, ...,
SN.
The state of the model changes whenever a new customer arrives
and whenever a customer is served and departs. Figure 12.4
shows the algorithm for New Customer Arrival.
| Record the time that this customer entered
the restaurant |
| If all servers are busy |
| then |
| Put this customer at the end of the waiting line
|
| Increase the length of the waiting line by 1
|
| else | (server Sj is idle) |
| Mark that server Sj
is now busy |
| Determine Tserve, the time
it will take to serve the customer |
| Schedule a customer departure event for
(current time + Tserve) |
| Increase the time that server
Sj has worked by Tserve
|
The time it takes to serve a customer, Tserve,
is a stochastic or random variable -
Tserve will have a small value for a customer
with a simple order or a large value for a customer with a
complicated order. We don't know what Tserve
will be for any particular customer but we probably know that
Tserve follows some
statistical distribution like that shown in Figure 12.5:
- 5% of the customers are served in less than 1 minute;
- 15% of the customers are served in 1 to 2 minutes;
- 40% of the customers are served in 2 to 3 minutes;
- 30% of the customers are served in 3 to 4 minutes; and
- 10% of the customers are served in 4 to 5 minutes.
A random number generator can be used to determine
the value of Tserve according to this
distribution.
Another random variable in the simulation is
Tinterval, the interval of time between
the arrivals of two successive customers,
Ci and Ci+1.
Figure 12.7 shows the algorithm for the event when server
Sj is done serving a customer:
| Determine the total time that this customer
spent in the restaurant |
| If there is someone in line |
| then |
| Take the next customer out of the line |
| Decrease the length of the line by one |
| Determine Tserve for this customer |
| Schedule a customer departure event for (current time +
Tserve) |
| Increase the time that server Sj has
worked by Tserve |
| else |
| Mark Sj as idle |
Figure 12.8 shows the main algorithm of the simulation model:
| Set current time to zero |
| Set the length of the waiting line to zero |
| Get N, the number of servers |
| Set all N servers, S1,
S2, S3, ..., SN
to idle |
| Get an input value for the number of customers, M |
| Schedule M customer arrivals and put them on
the list of events
|
| - each arrival occurs Tinterval time units
after the previous one |
| While there is still a scheduled event on the list |
| do |
| Get the next event on the list |
| Move current time to the time of this event |
| If this is a New Customer Arrival event |
| then |
| | Execute the arrival algorithm of Figure 12.4 |
| else |
| | Execute the departure algorithm of Figure 12.7 |
| Remove this event from the list of scheduled events |
| End of the loop |
| Print out data that describes the behavior of the system |
The print out might show the:
- Number of servers,
- Average Customer Waiting Time,
- Maximum Line Length, and
- Server Busy Percentage
The user can run the model with different numbers of servers to
decide how many server stations he should build.
(12.3) - Running the Model and Visualizing Results
There is very little data output in the example simulation model described
in section (12.2) so all that's required is a text output. Complex
simulation models have a lot of data to output so a graphics output
might be needed. Scientific visualization is the field concerned with
visualizing data to highlight its important characteristics.
Data outputs from some simulations are best displayed in two-dimensional graphs.
Figure 12.9 is a chart showing the daily ocean tide at some place.
Figure 12.10 is a chart showing ocean tide and water temperature.
Other simulation models might show data in a three-dimensional display.
Figure 12.11 shows a region of the earth's surface.
Chemical molecules can be displayed in three dimensions with atoms
of different elements shown in different colors. Figure 12.12 shows
a molecule of methyl nitrite (CH3NO2) with
three hydrogen atoms (red), one carbon atom (purple), two oxygen
atoms (yellow) and one nitrogen atom (blue.)
Figure 12.13 is a visualization of a dispersion of a toxic gas
in the downtown area of a major city at a certain time.
Image animation can be used to show how the gas disperses
as a function of time.
Figure 12.14 shows the results of a model of ozone layers in
the atmosphere at two different days in the year.
Kenneth E. Batcher - 1/13/2008