You are on page 1of 17

Simulation and Modeling

Chapter-1. Modeling and Simulation Basics


1.1. Systems Basics
Systems are groups of components or objects that are interconnected,
interrelated, integrated and having a well defined order to satisfy a central
objective.
A system can also be viewed as a unit or process, which exists and operates
in time and space through the interaction of its parts.
Systems can be simple or complex. Simple systems are systems in which all
the components are not subsystems, i.e. they all are simple objects.
System complexity can be of the two types: detail complexity and dynamic
complexity.
Detail complexity is a complexity that results because of the number and
type of the components of a system. A system that has another system as a
component is complex system.
Dynamic complexity is a complexity that is because of the change of
behavior of a system through time and space. In these systems, it is difficult
to readily see the connections between parts of the systems and their
interactions.
Complex systems are networks made of a number of components that
interact with each other, typically in a nonlinear fashion. Nonlinear means
that the outputs of a system are not given by a linear combination of the
inputs (like a constant multiplied by a variable, a constant itself and/or
their sum). Non linear systems can be represented by mathematical
equations such as squares, cubes, trigonometric equations, radicals etc. In
the context of system behavior, the inputs and outputs can be the current
and next states of the system, and if their relationship is not linear, the
system is called a nonlinear system.
Complex systems may arise and evolve through self-organization, such that
they are neither completely regular nor completely random. A system is self-
organizing if when it organizes itself to produce a structural or behavioral
change through time.
Examples of complex systems include:
 A manufacturing plant with the machineries
 A bank service
 A distribution network of transportation system
 A computer network with servers, clients, hard disks, printers,
operators etc
 Traffic controlling systems of roads

Page 1 of 17
Simulation and Modeling

 A supermarket with inventory control, checkout, and customer service


 physiological systems of an organism,
 brains and other neural systems,
 stock markets,
 the Internet, and
 social media
Conventional statistical methods can’t be applied in complex system to
define the correlation or interaction of their components.

1.2. What is Simulation?


Simulation refers to all methods and applications to mimic/imitate the
behavior of a real system usually using computers and the appropriate
software. It is the imitation of the operation of real-world process or system
over time.
In order to study a system scientifically we often have to make a set of
assumptions about how it works. These assumptions, which usually take
the form of mathematical or logical relationships, constitute a model that is
used to try to gain some understanding of how the corresponding system
behaves.
If the relationships that compose the model are simple enough, it may be
possible to use mathematical methods (such as algebra, calculus, or
probability theory) to obtain exact information on questions of interest; this
is called an analytic solution. However, most real-world systems are too
complex to allow realistic models to be evaluated analytically, and these
models must be studied by means of simulation. In a simulation we use a
computer to evaluate a model numerically, and data are gathered in order to
estimate the desired true characteristics of the model.

Like any other analysis activities, simulation involves systems and models. A
model is a simplified representation of a system. It can be conceptual,
verbal, diagrammatic, physical, or formal (mathematical).
Models are representation of a real or theoretical system at a particular time
or place intended to provide understanding of the system; whereas,
simulation refers to running/manipulating those models so as to
learn/study the behavior of the system through time and space.
Following are some approaches to study systems:

Page 2 of 17
Simulation and Modeling

If it is possible (and cost-effective) to alter the system physically and


then let it operate under the new conditions, it is probably desirable to do
so, for in this case there is no question about whether what we study is
relevant. However, it is rarely feasible to do this, because such an
experiment would often be too costly or too disruptive to the system.
More importantly, the system in focus might not even exist, but we
nevertheless want to study it in its various proposed alternative
configurations to see how it should be built in the first place. For this
reason, it is usually necessary to build a model as a representation of the
system and study it as a surrogate for the actual system. When using a
model, there is always the question of whether it accurately reflects the
system for the purposes of the decisions to be made.

Page 3 of 17
Simulation and Modeling

The aim of studying systems includes the following:


 to measure performance of existing systems, like to what extent traffic
light system resolve traffic problems at rush hours
 to get an aid on how to perform a task, like how to troubleshoot
computer problems
 Designing and operating transportation facilities such as freeways,
airports, subways, or ports
 to improve operation so that efficiency increases, or
 to design a new system
To study a system, you may need to use simulation. Following are some
systems that you needn’t simulate them to study their behavior, in which
case an observation is enough:
 A network administrator that finds out the best network topology so as
to achieve the best network performance. This is because the
administrator might try a number of different topologies and select the
one that gives the best performance.
 Finding the best sequencing of lighting of traffic light system so as to
provide the best service at rush hours
And following are some system study practices that you need to use
simulation:
 To get the best layout of a factory for a better performance
 Trying out the best check-in system in an airport
 Demonstration of how explosives work in the military area
 Demonstration of how a given disease disseminate from place to place
 etc
In the above systems, you need simulation. This is because nobody gets hurt
and you would have the freedom to try wide range of ideas with the model
which you might not be able to try it with the real system.
However, you would have to build the model carefully so that it can mimic to
the real one.
We categorize systems to be of two types, discrete and· continuous. A
discrete system is one for which the state variables change instantaneously
at separated points in time. A bank is an example of a discrete system, since
state variables--e.g., the number of customers in the bank changes only
when a customer arrives or when a customer finishes being served and
departs. A continuous system is one for which the state variables change
continuously with respect to time. An airplane moving through the air is an

Page 4 of 17
Simulation and Modeling

example of a continuous system, since state variables such as position and


velocity can change continuously with respect to time. Few systems in
practice are wholly discrete or wholly continuous, but since one type of
change predominates for most systems, it will usually be possible to classify
a system as being either discrete or continuous.

1.3. Advantages and Disadvantages


Following are some advantages in using modeling and simulation over
playing directly to the real system:
 Lets you choose the correct/better system modification: lets you test
every aspect of a proposed change or addition without committing
resources to their acquisition (without resource wastage)
 Compress and expand time: It allows you to speed up or slow down
phenomena so that you can investigate the behavior of the system
better.
 Explore different possibilities: You can explore new policies, operating
procedures or methods without the need of experimenting with the real
world systems.
 Diagnose problems: Some systems are so complex that it is impossible
to consider all the interactions taking place in a given moment. With
modeling and simulation, you can better understand the interactions
among the variables that make up the complex system.
 Identify constraints: Bottlenecks in a system is an effect rather than a
cause. Doing bottleneck analysis with modeling and simulation, you
can discover the cause of the delays in work process, information,
material or other processes.
 Visualize the plan: Modeling and simulation lets you see your system
actually running. You can also detect design flaws that appear
credible.
 Training purpose: Modeling and simulation can provide excellent
training delivery. The trainees can simply provide decision inputs to
the simulation as it progress, and observe the outputs.

And the following are some disadvantages of modeling and simulation:


 Model building requires special training: Modeling and simulation is
an art that is learned over time and through experience. Two models of
the same system developed by two different individuals may have
similarities, but it is unlikely to be completely the same. Building a
realistic model may require domain knowledge that can only be
acquired from a subject matter expert.

Page 5 of 17
Simulation and Modeling

 Simulation results may be difficult to interpret: This is because of the


fact that most simulation results are essentially random variables.
 Simulation and modeling can be time consuming and expensive: This
may happen when incorrect or poor models are used which requires
another model, and to design another one, it requires time and cost.

1.4. Computer Simulation Model Types


There are lots of ways to classify simulation model types. The following are
the major ones:
 Static and Dynamic simulation models: If time is a factor to
affect/change behavior of the model, then, this kind of model is
dynamic; this is because time is considered to be one of the state
variables of the system as far as it impacts the state of the system at
that instant of time. Otherwise, it is static. Static simulation models
are based on current exposures and assume a constant balance with
no new growth/change. In contrast, dynamic simulation models rely
on detailed assumptions regarding changes in existing business lines,
new business, and changes in management and customer behavior.
Static model is more structural than behavioral while dynamic model is
a representation of the behavior of the static components of the
system. Static modeling includes class diagram and object diagrams
and help in depicting static constituents of the system. Dynamic
modeling on the other hand consists of sequence of operations, state
changes, activities, interactions and memory.
Static modeling is more rigid than dynamic modeling as it is a time
independent view of a system. It cannot be changed in real time and
this is why it is referred to as static modeling. Dynamic modeling is
flexible as it can change with time as it shows what an object does
with many possibilities that might arise in time.
Examples of static simulations are Monte Carlo models.

 Continuous and Discrete simulation models: In a continuous model,


the state of the system can change continuously overtime. But, in case
of discrete models, changes may occur only at separated points in
time.
Continuous models are based on mathematical equations. They
are used for simulating continuous values for all points in time.
Example of continuous model: The amount of time a person
spends in a queue.

Page 6 of 17
Simulation and Modeling

Discrete models are used for simulating specific values or


specific points.
Example of discrete model: Number of people in a waiting line
(queue).

 Deterministic and Stochastic simulation models: Models that have


no random (no probablistic) input are called deterministic. It is a
model that doesn’t contain probability. Every run of the model results
the same. So, it is enough to run the model only once to evaluate the
result.
In a deterministic simulation, all of the events and relationships
among the variables are governed entirely by a combination of known,
but possibly complicated, rules.
Deterministic simulations are often used to study the behavior of
physical systems.
Stochastic models operate on random inputs. A stochastic model
contains probability, so they are also called probabilistic simulations.
Units, processes, events or their parameters are initiated randomly
using random numbers. If different runs are initiated with different
random number, every run will result differently. Therefore, multiple
runs are required to evaluate the results. Statistics, such as averages
and standard deviations are used for evaluation.
Stochastic model is a tool for estimating probability distributions of
potential outcomes by allowing for random variation in one or more
inputs over time. The random variation is usually based on
fluctuations observed in historical data for a selected period using
standard time-series techniques.
An example of stochastic model can be a model for the operation of a
bank that customers arrive in a random fashion and have a different
length of service times.
Most queuing and inventory systems are modeled stochastically.
Stochastic simulation models produce output that is itself random,
and must therefore be treated as only an estimate of the true
characteristics of the model and this is one of the main disadvantages
of simulation.

Page 7 of 17
Simulation and Modeling

1.5. Program Structures for Dynamic Simulation


A dynamic simulation program that is written in a general purpose
programming language must:
i) keep track of ‘‘simulated’’ time,
ii) schedule events at ‘‘simulated’’ times in the future, and
iii) cause appropriate changes in state to occur when ‘‘simulated’’ time
reaches the time at which one or more events take place
The structure of a simulation program may be either time-driven or event-
driven, depending on the nature of the basic loop of the program. In time-
driven models each time through the basic loop, simulated time is advanced
by some ‘‘small’’ (in relation to the rates of change of the variables in the
program) fixed amount, and then each possible event type is checked to see
which, if any, events have occurred at that point in simulated time. In event-
driven models, events of various types are scheduled at future points in
simulated time. The basic program loop determines when the next scheduled
event should occur, as the minimum of the scheduled times of each possible
event. Simulated time is then advanced to exactly that event time, and the
corresponding event handling routine is executed to reflect the change of
state that occurs as a result of that event.
The table below illustrates the program structure for time driven and event
driven program structures.

Time driven structure Event driven structure


initialize; initialize;

time := startingTime timeToStop := false

loop loop

exit when time >= endingTime exit when TimeToStop

Collect statistics and record remove entry for next event from event list
measurements.
time := NextEventTime
Call event routines for each type of event
Collect statistics and record measurements.
that has occurred by this time.
Call event routine for next event
time += timeIncrement
(end of simulation event sets TimeToStop).
end loop
Insert next occurrence of this event type in
event list.

Page 8 of 17
Simulation and Modeling

end loop

The choice of whether a time- or event-driven program structure should be


used depends on the nature of the model. In general, an event driven
structure means that the basic program loop gets executed fewer times
(since an event is guaranteed to take place every time through the loop).
However, there is overhead involved in managing the event list, so that the
‘‘cost’’ (i.e., execution time) of going around the loop once is, in general,
substantially higher than it would be for a time-driven structure. Thus, a
time-driven structure is generally better for models in which it is possible to
find a time increment that is both small enough to distinguish among the
times at which events occur that cannot be treated as simultaneous, and
also large enough for at least one event to occur at a significant proportion of
the times through the basic program loop. If such a compromise is not
possible (because events occur at irregular intervals), an event-driven
structure is preferable.

1.6. General Modeling Types


Generally, models can be physical or logical, also called mathematical.
Physical models are replica of a system. An example of this type can be the
use of physical flight simulator to train pilots.
Logical models are a set of assumptions and approximations that describe
how a system works. A logical model is usually represented in a computer
program to address possible questions arising regarding how the system
behaves. This kind of model is cheaper and easy to learn.

1.7. How to Create a Model


There are a number of approaches for scientific model building, which can
be categorized in the following two groups:
Descriptive modeling: In this approach, the modelers try to specify the
actual state of a system at a given point of time (or at multiple time points)
in a descriptive manner.
This kind of model can be put using quantitative methods, like diagrams,
pictures, physical models, texts, equations, statistics, and computational
algorithms. Pattern recognition models are examples of this type. This
modeling technique try to capture “what the system looks like”, rather than
how the system will behave in the future, i.e., it describes the static behavior
of the system.
Rule-based modeling: In this approach, the modelers try to come up with
dynamical rules that can explain the observed behavior of a system. This
allows researchers to make predictions of its possible future states.

Page 9 of 17
Simulation and Modeling

Dynamical equations belong to this family of modeling effort. This is usually


done using quantitative methods, but it can also be achieved at conceptual
levels as well. They all try to capture “how the system will behave.”
A typical cycle of rule-based modeling effort goes through the following
steps:
i. Observe the system of your interest.
ii. Reflect on the possible rules that might cause the system’s
characteristics that were seen in the observation.
iii. Derive predictions from those rules and compare them with reality.
iv. Repeat the above steps to modify the rules until you are satisfied with
the model.

Example: Derive a rule-based mathematical model from your observation in


the following system:

Solution: This one is quite easy, because the observed data show that
nothing changed over time.
So, the mathematical model can be put as follows:

f(time) = C

The challenge in developing a model becomes particularly tough when it


comes to the modeling of complex systems, because their unique properties,
such as their networks and nonlinearity, are not what we are familiar with.
We usually think about things on a single scale in a step-by-step, linear
chain of reasoning, in which causes and effects are clearly distinguished and

Page 10 of 17
Simulation and Modeling

discussed sequentially. But this approach is not suitable for understanding


complex systems where a massive amount of components are interacting
with each other interdependently to generate patterns over a broad range of
scales.
Therefore, it is extremely difficult for us to come up with a reasonable model
when we are facing something unfamiliar. Because, the valid models
themselves will also be complicated and we might not able to get a
mathematical model, and in such situations simulation comes in.
We need to become experienced and familiar with various dynamics of
complex systems to become a good modeler of them. Computational modeling
and simulation is becoming a reasonable, practical method for this purpose.

1.8. Characteristics of Good Model


Following is a description of good models in general.
 Simple: A model should be described using the list possible
combination of variables that can affect the dynamic behavior of the
system. The main objective of any model is to describe a reality in a
shorter, simpler and cheaper fashion.
 Valid: This is all about how closely the model’s prediction agrees with
the observed reality. This is of utmost importance from a practical
viewpoint. If your model’s prediction doesn’t reasonably match the
observation, the model is not representing reality and is probably
useless. It is not enough to check only the validity of the model’s
prediction, but also the assumptions made while building the model.
Note that there is often a trade-off between trying to achieve simplicity
and validity of a model. If you increase the model complexity (i.e. if it is
too much detail), you may be able to achieve a better fit to the
observed data, but the model’s simplicity is lost (i.e. it will be overly
complicated to understand) and you also have the risk of over-fitting—
that is, the model prediction may become adjusted too closely to a
specific observation at the cost of generalization of other cases. You
need to strike the right balance between those two criteria. On the
contrary, if your model is too little detailed, it will have a risk of
missing relevant interactions. And if that is so, the model can’t
describe the real system.
 Robust: This shows how insensitive the model’s prediction is to minor
variations of model assumptions and/or parameter settings. If the
prediction made by your model is sensitive to their minor variations,
then the conclusion derived from it is probably not reliable. But if your
model is robust, the conclusion will hold under minor variations of
model assumptions and parameters, therefore it will more likely apply
to reality, and we can put more trust in it.

Page 11 of 17
Simulation and Modeling

1.9. Common Mistakes in Computer Simulation


Following are some common types of mistakes that are observed in computer
simulation.
 Inappropriate level of detail: The level of detail of the simulation work
is unlimited. But it is difficult to determine which level of detail best
fits the real system. Conceptually, the more detail, the more the model
will fit the real system; but this may not work for all times. This is
because more detailed model requires more time to develop and run
the model, and while doing so, more bugs may be introduced letting
the model to behave in the wrong way.
 Improper language usage: Choice of language can have significant
impact on time to develop. You can use general purpose languages,
such as C++ and Java, or special purpose languages, such as C++Sim
and JavaSim, for the simulation work. Special-purpose languages can
make implementation, verification and analysis easier.
 Usage of invalid models: As simulation programs are very large, they
require special steps to develop. Invalid models may work without
error, but doesn’t represent the real system. So, before using models,
we need to validate the model by analytic, measurement or any other
method.
 Improperly handled initial conditions: When simulating systems, it is
important to identify the initial state of the system, i.e. the initial value
of the variables, or attributes, of the system when to start running the
model.
 Too short simulation runs: We need to run the simulation model for a
reasonable number of times. If we run the model for a lesser number
of times, then we may not be able to draw the righteous knowledge.

Page 12 of 17
Simulation and Modeling

Chapter-2. Generating Random Variables for


Simulation Purpose

2.1. What is Random Variable?


A random variable is a variable say X whose value x depends on the outcome
of some random event.
A random variable can be characterized by the set of possible values that it
can take on, together with the probability that it takes on each of those
possible values, say x, which can be expressed as a probability density
function, fX(x).
The ability to generate random variables is of fundamental importance since
they are usually the building block for generating other random variables.
Generating random variables can be done using either of the following forms:
 Sampling from continuous distributions, or
 Sampling from discrete distributions

2.2. Characteristics of Good Random Number Generators


A ‘good’ random-number generator should satisfy the following properties:
 Uniformity: The numbers generated appear to be distributed uniformly
on (0, 1)
 Independence: The numbers generated show no correlation with each
other;
 Replication: The numbers should be replicable (e.g., for debugging or
comparison of different systems).
 Cycle length: It should take long before numbers start to repeat;
 Speed: The generator should be fast;
 Memory usage: The generator should not require a lot of storage.

2.3. Generating Discrete Uniform Random Variable


A discrete random variable can take on only a finite or countable number of
different values v 1, v2, . . . , v N. In this case, 0 <= f X (vj) <= 1, and we have

Page 13 of 17
Simulation and Modeling

Specifying distributions of random variables (e.g., inter-arrival times,


processing times) and assigning parameter values can be based on:
 Historical numerical data
 Expert opinion
In practice, there is sometimes real data available, but often the only
information of random variables that is available is their mean and standard
deviation.
Empirical data can be used to:
 construct empirical distribution functions and generate samples from
them during the simulation;
 fit theoretical distributions and then generate samples from the fitted
distributions

The Mid-square Method of Generating Random Variables


This method follows the technique below to generate uniform random
numbers in the range (0, 1). The output are in the form v0, v1, v2, … vn.
i. Start with a 4-digit number v 0 (seed)
ii. Square it to obtain 8-digits (if necessary, append zeros to the left)
iii. Take the middle 4 digits to obtain the next 4-digit number v 1;
iv. Then square v1 and take the middle 4-digits again, and so on.
We get uniform random number by placing the decimal point at the left of
each vi (i.e., divide by 10000).
Example:
 For v0 = 1234 we get 0.1234, 0.5227, 0.3215, 0.3362, 0.3030, 0.1809,
0.2724, 0.4201, 0.6484, 0.0422, 0.1780, 0.1684, 0.8361, 0.8561,
0.2907, ...
 For v0 = 2345 we get 0.2345, 0.4990, 0.9001, 0.0180, 0.0324, 0.1049,
0.1004, 0.0080, 0.0064, 0.0040, ... Two successive zeros behind the
decimal will never disappear.
 For v0 = 2100 we get 0.2100, 0.4100, 0.8100, 0.6100, 0.2100,
0.4100, ... Already after four numbers the sequence starts to repeat
itself.

Page 14 of 17
Simulation and Modeling

2.4. Constructing Sample Simulation Model


The first task is to identify those system components that should be
included in the model. This choice depends not only on the real system, but
also on the aspects of its behavior that we intend to investigate. The only
complete model of a system is the system itself. Any other model includes
assumptions or simplifications. Some components of a system may be left
out of the system model if their absence is not expected to alter the aspects
of behavior that we wish to observe.
For example, in simulating a bank customer service system so as to
determine the optimum number of bank tellers that are needed to serve the
customers efficiently, we really don’t need the type of service the customers
came to get; so for the simulation, we ignore that variable.
The following can be some of the bank teller system components to be
considered in simulating and modeling:
 Average idle time of each teller, may be in minutes
 Total service time of each customer and an average service time of all
customers measured in minutes. Service time of a customer may be
defined as the sum of waiting time and workload of the customer.
 Average performance of each teller, and an aggregate performance of
all, measured in number of customers served per minute. We might
consider this to evaluate the efficiency of the system
 Average waiting time of customers in minutes
 workload of the services that the customers came to get served,
measured in minutes, i.e. 5 minutes service, 10 minutes service etc.
[But here we assume that each service requires the same amount of
time, for instance, each workload requires 10 minutes]
 The system operates in a first-come-first served (FIFO) discipline; i.e.
the customers get served in their order of arrival.
 The arrival pattern of customers, which is defined as inter-arrival time.
This refers to the arrival time gap in between two consecutive
customers. We may assume this as if the inter-arrival is constant; i.e.
every customer reaches the bank every x minutes.
 And for the simulation purpose, we may take the system snapshot for
a period of time, like for one day. Note that, by the specified period of
time, a varying number of customers may appear in the reality. Or, we
may fix the number of customers to a particular number, like 50, 60,
100 etc and then simulate the system for the specified number of
customers.
 The simulation of the system might be useful to study/learn the
following information:

Page 15 of 17
Simulation and Modeling

 Know the optimum number of bank tellers required to make the


average waiting time of customers to the minimum
 Know the required number of bank tellers for a given average
waiting time of customers
 Know the average waiting time of customers for a given number of
bank tellers
 And to learn other ‘what if’ types of questions

We follow stochastic simulation to simulate the bank system. This is


because, in stochastic simulation, certain variables must be selected at
random from some probability distribution. The inter-arrival time of
customers, the workloads of the customers, the performance of the bank
tellers etc are selected at random from some probabilistic distribution in
their domain.
A value is calculated for each instance of a stochastic variable by generating
a ‘‘pseudorandom’’ (i.e., random-appearing, but actually algorithmically
computed) number using one of the pre-defined pseudo-random number
generators defined in the simulation language, like the ‘random()’ function
in C++, and then transforming it as necessary to match the specified
probability distribution for the stochastic variable.

2.5. Simulation General Steps


The following steps can be followed in the process of simulating systems:
i. Problem formulation
ii. Setting of objectives and overall project plan
iii. Model conceptualization and data collection
iv. Model translation
v. Verification
vi. Validation
vii. Experimental design
viii. Production runs and analysis
ix. Documentation and reporting
x. Implementation

Page 16 of 17
Simulation and Modeling

Chapter-3. Analysis of Simulation Results


The analysis of simulation results helps us know to what extent the model
represents the real system; i.e. how much the model is valid! And this can be
done in the two step process: first validation, and next verification.

3.1. Validation:
Validation process checks if the model that we get after making the different
assumptions really represents the real system. Sometimes over assumptions
might result a model far from the real system. So, we should make
assumptions reasonably.
In validation process, we are going to check three core things:
 Assumptions
 Input parameters and their distributions
 Output values and conclusions

3.2. Output Analysis


Once the simulation program has been completely written and carefully
tested, the actual simulation experiment must be carried out. The idea of the
experiment is to conduct one or more simulation ‘‘runs’’ from which
measurements are collected. The output from these runs is used to assess
the performance of the system.

3.3. Verification
Verification is a process that confirms how correctly the assumptions are
implemented in the system. Verification can be made in different techniques
like structured walk-through and tracing.
The things that you are going to test include:
 Continuity: that is whether a slight change in the input will make a
slight change in the output. If it doesn’t, there indicates an error in the
model.
 Degeneracy tests: try to give extreme input values, such as the
minimum and the maximum possible input combinations.
 Consistency tests: This is a test that checks if similar outputs will
result for repeated similar inputs.

Page 17 of 17

You might also like