Discrete Events Simulation Dr. Anis Koubâa CS433 Modeling and Simulation

advertisement
Al-Imam Mohammad Ibn Saud University
CS433
Modeling and Simulation
Lecture 09 – Part 02
Discrete Events Simulation
http://10.2.230.10:4040/akoubaa/cs433/
27 Dec 2008
Dr. Anis Koubâa
Outline
 Basic Concepts of Simulation
 Why using simulations?
 Advantages and drawback of simulations
 Types of simulations
 Steps in a simulation study
 Discrete Event Simulation (DES)
Basic Concepts

Simulation: It is a numerical technique for conducting experiments with
certain types of mathematical models describing the behavior of complex
systems on a digital computer over extended periods of time
(Naylor 1971)

In a Simulation, a computer is used to evaluate a model numerically, and
then gather data in order to estimate the desired characteristics of the
model.

Example: A manufacturing firm that is thinking to build a large extension
onto one of its plants.

Question: Will the potential gain in productivity justify the construction
cost?

Problem: It would not be cost effective to build the extension and then
remove it later if it does not work out.

Solution: Simulation!
When and Why to use Simulations?
 Simulation enables the study of complex system.
 Simulation is a good approach when analytic study of a system is
not possible or very complex.
 Informational, organizational, and environmental changes can be
simulated.
 The knowledge gained in designing a simulation model may be of
great value toward suggesting improvement in the system under
investigation.
 Simulation can be used to experiment with new designs or policies
prior to implementation (what if scenarios).
 Experiments can be very expensive , dangerous …
 The modern system is so complex that the interactions can be
treated only through simulation.
When Simulation Cannot be Used?
 when the problem can be solved using common sense
 when the problem can be solved analytically
 when it is easier to perform direct experiments
 when the costs exceed the savings
 when the resources or time are not available
 when the ability to verify and validate the model is very limited
 when the system behavior is too complex or cannot be defined
Application Areas of Simulation
Advantages/Drawbacks of Simulation
 Advantages
 Adequate for assessing models too complicated for analytical
or numerical study;
 New policies, decision rules, etc., can be explored without
disrupting ongoing operations of the real system;
“What if” scenarios can be analyzed which are useful in the
design of new systems.
 Drawbacks
 Sometimes very time consuming/costly;
 To analyze a certain problem, better methods than simulation
may exist;
 Simulations provide “random output”
(lots of misinterpretation possible).
Types of Simulation
 Static vs. Dynamic
 Does time have a role in the model?
 Continuous-change vs. Discrete-change
 Can the “state” change continuously or only at discrete
points in time?
 Deterministic vs. Stochastic
 Is everything for sure or is there uncertainty?
 Most operational models
 Dynamic, Discrete-change, Stochastic
Types of Simulation
Concepts in Discrete Event Simulation
Steps of a Simulation Study
Steps in Simulation Study
1- Problem formulation: Every study should begin
with a statement of the problem
2- Setting of objectives and overall project plan:
The objectives indicate the questions to be
answered by simulation.
3- Model conceptualization: The construction
of a model of a system is probably as much art
as science
4- Data collection: There is a constant interplay
between the construction of the model and the
collection of the needed input data [Shannon,
1975]. As the complexity of the model changes,
the required data elements may also change
Steps in Simulation Study
5- Model translation: the model must be entered
into a computer-recognizable format.
6- Verification: Is the computer program
performing properly?
7- Validation: Does the simulation model
replicate this system measure?
8- Experimental design: The alternatives that are
to be simulated must be determined
9- Production runs and analysis: Production runs,
and their subsequent analysis, are used to estimate
measures of performance for the system designs
that are being simulated.
Steps in Simulation Study
10- More runs? determines if additional runs are
needed and what design those additional
experiments should follow.
11- Documentation and Reporting.
12- Implementation.
Discrete-Event Simulation
Outline





Time-stepped implementation: critique
Discrete event fundamentals
Simulation engine
Example: Airport Simulation
Discrete event simulation critique
State Variables
queue
server
customer
State:

InTheAir: number of aircraft either landing or waiting to land

OnTheGround: number of landed aircraft

RunwayFree: Boolean, true if runway available
Time Step Implementation
/* ignore aircraft departures */
Float InTheAir: # aircraft landing or waiting to land
Float OnTheGround: # landed aircraft
Boolean RunwayFree: True if runway available
Float NextArrivalTime: Time the next aircraft arrives
Float NextLanding: Time next aircraft lands (if one is landing)
For (Now = 1 to EndTime) { /* time step size is 1.0 */
if (Now >= NextArrivalTime) { /* if aircraft just arrived */
InTheAir := InTheAir + 1;
NextArrivalTime := NextArrivalTime + RandExp(A);
if (RunwayFree) {
RunwayFree := False;
NextLanding := Now + RandExp(L);
}
}
if (Now >= NextLanding) { /* if aircraft just landed */
InTheAir := InTheAir - 1;
OnTheGround := OnTheGround + 1;
if (InTheAir > 0) NextLanding := Now + RandExp(L)
else {RunWayFree := True; NextLanding := EndTime+1;}
}
}
Problems With Time Step Approach

State changes may occur between time steps


Multiple state changes within the same time step may
be processed in the wrong order


Use small time steps to minimize error
Solvable by ordering state changes within time step (this
imposes more work)
Inefficient

Many time steps no state changes occur, especially if small
time steps
Discrete Event Simulation


Discrete Event Simulation: computer model for a system where changes in the
state of the system occur at discrete points in simulation time.
Fundamental concepts:





System state (state variables)
State transitions (events)
Each event has a timestamp indicating when it occurs.
A DES computation can be viewed as a sequence of event computations, with
each event computation is assigned a (simulation time) time stamp
Each event computation can

Modify state variables

Schedule new events
Discrete Event Simulation Computation
 Example: air traffic at an airport
 Events: aircraft arrival, landing, departure
arrival
8:00
schedules
landed
8:05
schedules
departure
9:15
arrival
9:30
processed event
current event
unprocessed event
simulation time


Events that have been scheduled, but have not been simulated (processed) yet
are stored in a pending event list
Events are processed in time stamp order; why?
Discrete Event Simulation System
Model of the
physical
system
Independent
of the
simulation
application
Simulation Application
state variables
code modeling system behavior
I/O and user interface software
calls to
schedule
events
calls to event
handlers
Simulation Engine
event list management
managing advances in simulation time
Events


An event must be associated with any change in the
state of the system
Airport example:

Event 1: Aircraft Arrival
(InTheAir, RunwayFree)

Event 2: Aircraft Landing
(InTheAir, OnTheGround, RunwayFree)

Event 3: Aircraft Departure
(OnTheGround)
Event-Oriented World View
Event handler procedures
state variables
Arrival Event
{
…
}
Integer: InTheAir;
Integer: OnTheGround;
Boolean: RunwayFree;
Landed Event
{
…
}
Departure Event
{
…
}
Simulation Application
Simulation Engine
Now = 8:45
Pending Event List (PEL)
9:00
10:10
9:16
Event processing loop
While (simulation not finished)
E = smallest time stamp event in PEL
Remove E from PEL
Now := time stamp of E
call event handler procedure
Example: Air traffic at an Airport


Model aircraft arrivals and departures, arrival queuing
Single runway for incoming aircraft, ignore departure queuing




States





L = mean time runway used for each landing aircraft (exponential distrib.)
G = mean time on the ground before departing (exponential distribution)
A = mean inter-arrival time of incoming aircraft (exponential distribution)
Now: current simulation time
InTheAir: number of aircraft landing or waiting to land
OnTheGround: number of landed aircraft
RunwayFree: Boolean, true if runway available
Events



Arrival: denotes aircraft arriving in air space of airport
Landed: denotes aircraft landing
Departure: denotes aircraft leaving
Arrival Events
 Arrival Process: New aircraft arrives at airport.
 If the runway is free, it will begin to land.
 Otherwise, the aircraft must circle, and wait to land.
A: mean interarrival time of incoming aircraft
Now: current simulation time
InTheAir: number of aircraft landing or waiting to land
OnTheGround: number of landed aircraft
RunwayFree: Boolean, true if runway available
Arrival Event:
InTheAir := InTheAir+1;
Schedule Arrival event @ Now + RandExp(A);
If (RunwayFree) {
RunwayFree:=FALSE;
Schedule Landed event @ Now + RandExp(L);
}
Landed Event
Landing Process: An aircraft has completed its landing.
L = mean time runway is used for each landing aircraft
G = mean time required on the ground before departing
Now: current simulation time
InTheAir: number of aircraft landing or waiting to land
OnTheGround: number of landed aircraft
RunwayFree: Boolean, true if runway available
Landed Event:
InTheAir:=InTheAir-1;
OnTheGround:=OnTheGround+1;
Schedule Departure event @ Now + RandExp(G);
If (InTheAir>0)
Schedule Landed event @ Now + RandExp(L);
Else
RunwayFree := TRUE;
Departure Event
Departure Process: An aircraft now on the ground departs
for a new destination.
Now: current simulation time
InTheAir: number of aircraft landing or waiting to land
OnTheGround: number of landed aircraft
RunwayFree: Boolean, true if runway available
Departure Event:
OnTheGround := OnTheGround - 1;
Execution Example
State Variables
L=3
G=4
InTheAir 0
1
2
OnTheGround 0
1
0
1
2
RunwayFree true false
0
1
2
1
0
true
3
4
5
6
7
8
9
10
11
Simulation Time
Processing: Arrival F1
Arrival F2
Time Event
1 Arrival F1
Time
3 Arrival F2
Time
Event
3 Arrival F2
4 Landed F1
Event
4 Landed F1
Landed F1
Time
Event
7 Landed F2
8 Depart F1
Landed F2
Time
Event
Now=1
Now=3
Now=4
Depart F2
Time
Time
Event
Event
8 Depart F1
11 Depart F2
Now=0
Depart F1
Now=7
11 Depart F2
Now=8
Now=11
Output Statistics
Compute

The maximum number of aircraft that will be on the ground at one time

Average time an aircraft must wait before they are allowed to land
Solution


Maximum on ground

Variable for airport indicating number currently on ground

Maximum “on the ground” so far
Wait time

Variables for airport indicating total wait time, number of aircraft arrivals

State variable for each aircraft indicating the arrival time
Discrete Event Simulation

Avoids problems of time stepped execution
Error when events lie between time steps
 Time steps with no events


But…
Priority queue (pending event list) introduces some new
computational overhead
 What about events with the same time stamp?


More important than one might initially think!
Summary

Methodology


Important to have a reasonably clear conceptual and
specification model before moving to implementation
(computational model)
Key concepts: state variables and changes in state
Simulation engine: largely independent of application
 Simulation model: state variables and code to modify state


Time stepped vs. event driven execution
In principle, either can be used to model system
 Discrete-event simulation approach more commonly used to
model queuing systems

Download