You are on page 1of 34

KKKT 6274 Modeling and Simulation of Communication and Computer Network

Prof. Dr. Mahamod Ismail mahamod@eng.ukm.my

TEACHING PLAN (1/3)


Week 1 (MBI) 2 (MBI) 3 (MBI) 4 (MBI) Topics Introduction to Simulation and Performance Modeling: Analytical and Monte Carlo Simulation Principle: Event and Time Driven Simulation Model: Statistical, Random and Queue Model Verification/Validation, Input/Output Analysis

LECTURE 2
SIMULATION PRINCIPLE

Introduction

Introduction
Stochastic (random process) or deterministic (a computation that given an initial state of the system will always produce the same final state when given the same input) Steady-state or dynamic Continuous (small changes in the input result in small changes in the output) or discrete (ex: events over time) Local or distributed (using two or more computers communicating over a network to accomplish a common objective or task)

Introduction
Stochastic models use random number generators to model the chance or random events; they are also called Monte Carlo simulations. Ex: rainfall/runoff models A discrete event simulation (DE) manages events in time. Most computer simulations are of this type. In this type of simulation, the simulator maintains a queue of events sorted by the simulated time they should occur. The simulator reads the queue and triggers new events as each event is processed. It is not important to execute the simulation in real time. It's often more important to be able to access the data produced by the simulation, to discover logic defects in the design, or the sequence of events.

Introduction
A continuous simulation uses differential equations, implemented numerically. Periodically, the simulation program solves all the equations, and uses the numbers to change the state and output of the simulation. Most flight and racing-car simulations are of this type. This may also be used to simulate electrical circuits. Distributed models run on a network of interconnected computers, possibly through the Internet. Simulations dispersed across multiple host computers like this are often referred to as "distributed simulations". There are several military standards for distributed simulation.

Introduction
Computer simulations are used in a wide variety of practical contexts, such as:
analysis of air pollutant dispersion using atmospheric dispersion modeling design of complex systems such as aircraft and also logistics systems. design of Noise barriers to effect roadway noise mitigation flight simulators to train pilots weather forecasting

Can you think of others?

Deterministic vs. Stochastic


Computer simulation has to do with using computer models to imitate real life or make predictions. A model consists of a certain number of input parameters and a few equations that use those inputs to give a set of outputs (or response variables). The model is usually either deterministic or stochastic.

Deterministic vs. Stochastic


In the deterministic model, the results will be the same no matter how many times recalculate is done.

10

Deterministic vs. Stochastic

11

Deterministic v. Stochastic
Deterministic Fixed Data 7% Fixed Outcomes $1,200,00

Stochastic Variable data


Monthly Savings

Variable Outcomes

350.00

425.00

500.00

575.00

650.00

Deterministic vs. Stochastic


A stochastic model is one that involves probability or randomness. For example, random selection of parts in order to assemble the hinge.

13

Monte Carlo Simulation


A Monte Carlo method is a technique or computational algorithm that involves using repeated random numbers and probability to solve problems. The term Monte Carlo Method was coined by S. Ulam and Nicholas Metropolis in reference to games of chance, a popular attraction in Monte Carlo, Monaco (Hoffman, 1998; Metropolis and Ulam, 1949). Monte Carlo simulation is a method for iteratively evaluating a deterministic model using sets of random numbers as inputs.
15

Monte Carlo Simulation


Monte Carlo simulation is often used when the model is complex, nonlinear, or involves more than just a couple uncertain parameters. A simulation can typically involve over 10,000 evaluations of the model, a task which in the past was only practical using super computers. The Monte Carlo method is analyze uncertainty propagation, where the goal is to determine how random variation, lack of knowledge, or error affects the sensitivity, performance, or reliability of the system that is being modelled. 16

Monte Carlo Simulation


Monte Carlo simulation is categorized as a sampling method because the inputs are randomly generated from probability distributions to simulate the process of sampling from an actual population. The data generated from the simulation can be represented as probability distributions (or histograms) or converted to error bars, reliability predictions, tolerance zones, and confidence intervals.

Monte Carlo Simulation


Monte Carlo follows the five simple steps listed below:
Step 1: Create a parametric model, y = f(x1, x2, .., xq). Step 2: Generate a set of random inputs, xi1, xi2, .., xiq. Step 3: Evaluate the model and store the results as yi. Step 4: Repeat steps 2 and 3 for i = 1 to n. Step 5: Analyze the results using histograms, summary statistics, confidence intervals, etc.

Monte Carlo Simulation

Monte Carlo techniques can be used in Battleship

Monte Carlo Simulation


The first figure is simply a unit circle circumscribed by a square. We could examine this problem in terms of the full circle and square, but it's easier to examine just one quadrant of the circle.

Calculation of using Monte Carlo Techniques

Monte Carlo Simulation


Poor dart players simulate Monte Carlo techniques

Monte Carlo Simulation


# darts hitting shaded area / # darts hitting square = r2 / r2
= 4 [# darts hitting shaded area / # darts hitting square]

MC makes it easy as pi!

Time-Driven Simulation
In a time-driven simulation we have a variable recording the current time, which is incremented in fixed steps. After each increment we check to see which events may happen at the current time point, and handle those that do. For example, suppose we want to simulate the trajectory of a projectile.
At time zero we assign it an initial position and velocity. At each time step we calculate a new position and velocity using the forces acting on the projectile.

Time-Driven Simulation
Time-driven simulation is suitable here because there is an event (movement) that happens at each time step. How do know when to stop the simulation?
We can use either the criterion of time reaching a certain point, or the model reaching a certain state, or some combination of the two.

Time-Driven Simulation
General algorithm for time-driven simulation: 1. Initialize the system state and simulation time 2. while (simulation is not finished)
a) Collect statistics about the current state b) handle events that occurred between last step and now c) Increment simulation time

Event Driven Simulation


Use when
events aren't guaranteed to occur at regular intervals don't have a good bound on the time step (it shouldn't be so small as to make the simulation run too long, nor so large as to make the number of events unmanageable)

Example
A line-up at a bank, where customers don't arrive at regular time intervals, and may be deterred by a long line-up.

Event Driven Simulation


Use when
events aren't guaranteed to occur at regular intervals don't have a good bound on the time step (too small make simulation run too long; too large make the number of events unmanageable) when time reaches a certain point, or when the system reaches a certain state. A line-up at a bank, where customers don't arrive at regular time intervals, and may be deterred by a long line-up.

Stop program? Example

Event Driven Simulation


A generic event-driven algorithm:
1. Initialize system state 2. Initialize event list 3. While (simulation not finished)
a) Collect statistics from current state b) Remove first event from list, handle it c) Set time to the time of this event.

The list of events can be managed in ordered by increasing time (a priority heap might be efficient) and not to generate all the events in the list at the beginning.

Event Driven Simulation


We initialize the simulation with certain events, with their associated times. Certain events may be handled by scheduling later events, which are inserted at the appropriate place in the event list. Stop the event:
When time reaches or exceeds a certain point, or once the system reaches a certain state Can also be randomized:
Schedule a random pseudo-event which doesn't change the state of the model, but simply stops the simulation.

Discrete Event Model


An instant is a value of system time at which the value of at least one attribute of an object can be assigned. An interval is the duration between two successive instants. A time span is the contiguous succession of one or more intervals. The state of an object at a particular instant is the enumeration of all attribute values of that object at that instant, The state consists of all the object states at a particular instant.

Event Driven Simulation

Event Driven Simulation


An instant is a value of system time at which the value of at least one attribute of an object can be assigned. An interval is the duration between two successive instants. A time span is the contiguous succession of one or more intervals. The state of an object at a particular instant is the enumeration of all attribute values of that object at that instant, The state consists of all the object states at a particular instant.

Event Driven Simulation

References
Dr. Anis Kouba, CS433: Modeling and Simulation (http://coins.csrlab.org/imamu/akoubaa/cs433/) ref