Chapter 3 Monte Carlo Computations & Simulation
Chapter 3 Monte Carlo Computations & Simulation
Chapter 3 Monte Carlo Computations & Simulation
Monte Carlo Simulation: refers to the type of simulation in which a static, approximate, and
stochastic model is used for a deterministic system.
These techniques are based on the use of random numbers and probability statistics to investigate
problems in areas as diverse as economics, nuclear physics, and flow of traffic.
4
System Simulation and Modeling - ITec4163 Department of IT
Let us illustrate the use of the MC technique as a method of integration and let us begin with a
simple geometric MC experiment which calculates the value of π based on a "hit and miss"
integration.
Monte Carlo integration: Such an integral can be partitioned into segments above or below the
horizontal axis. Without loss of generality, let us assume f (x)>=0, a <= x<=b. We can then
bound the curve with a rectangle with borders of x = a, x = b, y = 0, and y = y max, where y max
is the maximum value of f (x) in the interval [a, b]. By generating random points uniformly
distributed over this rectangular area, and deciding whether they fall above or below the curve f
(x), we can estimate the integral.
4
System Simulation and Modeling - ITec4163 Department of IT
MC simulation gives properties via ensemble averaging. Random numbers are used to
generate large number of states of the system (members of an ensemble) with a
distribution characteristic for a given statistical mechanics ensemble.
Metropolis Monte Carlo – a method to generate a sequence of random states of the
system with probability distribution characteristic for the system in equilibrium.
If we start our simulation away from the equilibrium, the random walk in MC should
bring us to the equilibrium. We can use MC to find equilibrium structure and
composition.
Simulations discussed until now are performed at constant T without any special efforts.
No need to ensure that energy is conserved after a trail move.
MC can be adapted to the calculation of averages in any statistical mechanics ensemble.
For example, simulation of isothermal – isobaric ensemble involves random volume
change (volume is added to the set of independent variables that characterize the state of
the system); simulation of grand-canonical ensemble has “moves” that insert/delete
atoms/molecules.
MC cannot address kinetics or dynamical properties (diffusion, mean square
displacements, velocity autocorrelation functions, vibrational spectra etc.)
4
System Simulation and Modeling - ITec4163 Department of IT
Dynamic Simulation
Dynamic stochastic simulation models will be emphasized. A dynamic simulation program that
is written in a general purpose programming language (such as
Turing) must:
keep track of ‘‘simulated’’ time,
schedule events at ‘‘simulated’’ times in the future, and
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.
Stochastic Simulation:
A stochastic simulation is a simulation that traces the evolution of variables that can
change stochastically (randomly) with certain probabilities.
With a stochastic model we create a projection which is based on a set of random values. Outputs
are recorded and the projection is repeated with a new set of random values of the variables.
These steps are repeated until a sufficient amount of data is gathered. In the end,
the distribution of the outputs shows the most probable estimates as well as a frame of
expectations regarding what ranges of values the variables are more or less likely to fall in.
4
System Simulation and Modeling - ITec4163 Department of IT
Pure Pursuit Problem: A fighter aircraft sights an enemy bomber and flies directly toward it,
in order to catch up and destroy it. We have to determine the attack course of the fighter and how
long does the fighter take to catch up with the bomber.
If the target flies along a straight line, the problem can be solved directly with analytic
techniques. But if the path of the bomber is curved, the problem cannot be solved directly. We
can solve such problems using simulation.
We are given following conditions:
Both target and pursuer are flying in the same 2 dimensional plane.
The fighter's speed is constant that is VF.
The target's path is known.
Minimum distance required by the fighter to fire a missile at bomber is 10 units.
If the target is not caught within given time t∘ (here t∘ = 12), the target escapes.
Initial coordinates of the pursuer (fighter) are known.
4
System Simulation and Modeling - ITec4163 Department of IT
We will choose our coordinate system such that, initially target will be lying on the X axis and
pursuer will be lying on Y axis as shown in the figure below.
The fighter looks at the target at instant t, aligns its velocity vector with line of sight (i.e. points
itself towards the target). It continues to fly in that direction for one unit of time (up to t+1). At
(t+1) it looks at the target again and realigns itself.
4
System Simulation and Modeling - ITec4163 Department of IT
4
System Simulation and Modeling - ITec4163 Department of IT
Queueing Systems
Most simulations contain queues as part of the model. Queueing theory refers to the
mathematical models used to simulate these queues.
A queueing system consists of at least a server, a waiting line, and a calling population.
A queueing system is described by • Calling population • Arrival rate • Service mechanism •
System capacity • Queueing discipline.
Examples;
Discipline refers to the logical order in which customers are served. Often used models are:
FIFO (first-in-first-out), LIFO (last-in-first-out);
SIRO (service in random order);
SPT (shortest processing time first);
4
System Simulation and Modeling - ITec4163 Department of IT
PR (service according to priority).
Example
Problem:
As a first example, we look at a simple queue model which has an infinite population, one queue,
and one server.
Solution:
Suppose inter-arrival times are determined by rolling a die. If the numbers 6, 1, 4, 3, 6, 5 are
rolled this means that the customers arrive at times 0,6,7,11,14,20,25 as in the following table:
4
System Simulation and Modeling - ITec4163 Department of IT
Two-Server Model
We consider a second simulation. Here two servers serve one queue. We assume that a customer
is served by the server that is available. If both servers are available then the customer is
assigned randomly to one of the servers. The servers take different times to serve a customer
(these could be mechanics, one being more senior and faster than the other, or network servers,
where one model is older than the other).
4
System Simulation and Modeling - ITec4163 Department of IT
An inventory control system should take into account key factors such as demand fluctuation
based on market trends, spoilage in unstable goods such as food or chemicals, shrinkage due to
spills, product damaged in shipping, and shrinkage caused by staff. Demand fluctuation based on
market trends can only be predicted in a general sense by analyzing past precedences with
similar products and how they relate to new items. In contrast, the spoilage of unstable goods is
usually a very predictable process and can be minimized by effectively estimating how much
product will be sold before the shelf-life of the item expires, thereby eliminating over-
purchasing. Within inventory control, estimating the market demand for unstable goods and
ensuring that the company does not buy too much or too little of a product is among the most
difficult of tasks, and must be supported by large volume data samples before an informed
decision can be made. Shrinkage due to spills can be minimized through the employee training
programs, although the exact amount of shrinkage will vary dramatically between locations and
require some real-world data gathering. Shrinkage due to internal and external staff can be
virtually eliminated by enhancing systemic security protocols, including adequate security
monitoring and loss-prevention technology.
Choosing an inventory control strategy for the simulation experiment requires an intimate
knowledge of the specific nature of the business being analyzed. A small-scale greengrocer, for
example, should focus their inventory control strategy on anticipating consumer demand and
minimizing loss due to spoilage, whereas a large stable goods retailer such as Wal-Mart, Kmart
or Target can afford to make large purchase orders of items, store them in a warehouse and
distribute them internally while receiving volume purchasing discounts. To provide efficient
service to customers, it is necessary to choose reorder point with proper consideration of demand
during lead time. If the lead time and demand of inventory per unit time both are random
4
System Simulation and Modeling - ITec4163 Department of IT
variables, then the simulation techniques can be applied to determine the effect of alternate
inventory policies on a stochastic inventory system i.e. different combinations of order quantity
and reorder point. Thus, we run the inventory system artificially by generating the future
observations on the assumptions of the same distributions. In inventory control, the problem of
determining the replenishment policy due to uncertain demand and lead time can be solved by
simulation. Instead of trying manually the three replenishment alternatives for each level of
demand and lead time for a period of one year and then selecting the best one, we process on the
computer and obtain the results in a very short time at a small cost. Uncertainty and variation in
construction process has an important influence on project performance. The common practice to
deal with variation is the holding of inventory. A suitable inventory improves the performance of
project. However, excessive inventory induces no-added value. Simulation experiments show
that application of DES (discrete event simulation) and CONWIP(constant work-in-progress)
provides an effective way of inventory control, simultaneously, maintain throughout the cycle
time .