+ All Categories
Home > Documents > Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov,...

Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov,...

Date post: 01-Jun-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
52
Introduction to simulations Lecturer: Dmitri A. Moltchanov E-mail: [email protected].fi http://www.cs.tut.fi/˜moltchan/modsim/ http://www.cs.tut.fi/kurssit/TLT-2706/
Transcript
Page 1: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Introduction to simulations

Lecturer: Dmitri A. Moltchanov

E-mail: [email protected]

http://www.cs.tut.fi/˜moltchan/modsim/

http://www.cs.tut.fi/kurssit/TLT-2706/

Page 2: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

OUTLINE:

• Why do we need simulations;

• Example: GI/G/1 queuing system;

• Basics of simulations;

• Discrete-event simulations;

• Example: GI/G/1 queuing system;

• Simulations models;

• Example: machine interference problem;

• Example: production line.

Lecture: Introduction to simulations 2

Page 3: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

1. Why do we need simulations?Two ways to estimate performance parameters in communication networks:

• analytical analysis;

• simulation studies.

Example: analysis of queuing system:

• modeling of arrival process as a stochastic process;

• modeling of service time are a stochastic process;

• representation of interactions of these processes as an another process.

What is important for analytical analysis:

• often analytical analysis of the queue is too complicated or even not possible;

• requires restrictive assumptions to be introduced.

Lecture: Introduction to simulations 3

Page 4: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

2. Example: GI/G/1 queuing systemWe know how to analyze analytically:

• M/M/-/-/- type of systems;

• G/M/-/-/- and M/G/-/-/- systems.

You have to note:

• arrival and service processes can be general;

• this is the case in telecommunications networks.

Examples:

• IP router serving user’s traffic from a number of access connections;

• size of IP packet varies and cannot be approximated by Poisson distribution;

• service time of one bit is constant: service time of packets is not exponential.

How to model: GI/G/1 queuing system.

Lecture: Introduction to simulations 4

Page 5: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

2.1. Description of the system

Graphical representation of this queuing system is shown below.

......unlimited # of waiting positionsarrivals server

Figure 1: Graphical representation of GI/G/1 queuing system.

System is characterized by:

• arbitrary i.i.d. distributed interarrival times (GI);

• arbitrary i.i.d. distributed service times (G);

• single server;

• FCFS queuing discipline.

Lecture: Introduction to simulations 5

Page 6: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

2.2. Analysis of GI/G/1 queuing system

We will need the following notions:

• sn be the service time of nth customer;

• τn be the interarrival time between nth and (n + 1)th customers.

We assume that:

• {s1, s2, . . . } is sequence of independent random variables with the same PDF:

G(x) = Pr{sn ≤ x}, n = 1, 2, . . . , x ≥ 0 (1)

• {t1, t2, . . . } is a sequence of independent random variables with the same PDF:

F (x) = Pr{τn ≤ x}, n = 1, 2, . . . , x ≥ 0 (2)

• sn, n = 1, 2, . . . , and τn, n = 1, 2, . . . , are independent of each other;

• both F (x) and G(x) are differentiable:

– both sn and τn, n = 1, 2, . . . , have pdfs.

Lecture: Introduction to simulations 6

Page 7: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Mean arrival rate and mean service rate are:

λ =1

E[τ ], µ =

1

E[s]. (3)

Let Wn, n = 1, 2, . . . , be the waiting time of the n = 1, 2, . . . customer:

• we assume that first customer enters the empty system;

• we may assume any other number as an initial condition.

For waiting time of the customers in the system (Wn, n = 1, 2, . . . ) we have:

Wn+1 = max(0, Wn + sn − τn), n = 1, 2, . . . . (4)

• which is often called Lindley’s equation.

One should note that the system is stable when:

λ < µ, ρ =λ

µ< 1. (5)

• ρ is the offered load to the system.

Lecture: Introduction to simulations 7

Page 8: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

What should be noted:

• Lindley’s equation is the only exact result for GI/G/1;

• Lindley’s equation is pretty obvious.

Approximate solution can be derived for:

• overloaded GI/G/1 system (λ → µ);

• unloaded GI/G/1 system (λ << µ);

• results in terms of bounds.

Notes on GI/G/1 queue:

• GI/G/1 does not capture correlation between arrivals;

• arrival processes in real networks are often correlated;

• simulation is the only suitable way in this case.

Lecture: Introduction to simulations 8

Page 9: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

3. Basics of simulations

Define the problem

Analyze data

Formulate submodels

Combine submodels

Collect data

Write the program

Debug

Validate model

Design experiments

Run the simulator

Analyze the results

Implement results

Lecture: Introduction to simulations 9

Page 10: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

3.1. Variables

Variables in simulations: based on accessability:

• controllable variables: cannot be manipulated;

• uncontrollable variables: can be manipulated to come up with solution.

Variables in simulations: based on the type of creation:

• exogenous: not affected during simulation;

• endogenous: is determined by other variables.

Example: M/M/1 queuing system:

• exogenous:

– examples: number of servers, service and interarrival times, priority discipline, etc.

• endogenous:

– example: mean waiting time;

– example: mean number of customers in a queue.

Lecture: Introduction to simulations 10

Page 11: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Exogenous and endogenous variables can be:

• controllable;

• uncontrollable.

Example:

• studying impact of the N on waiting time in M/M/N: N – controllable;

• studying impact of the service time on waiting time in M/M/N: N – uncontrollable.

State variables:

• most important variables;

• form the core of the simulation model and used to obtain endogenous variables.

Example: M/M/1 queuing system: state of the system is number of jobs in.

Lecture: Introduction to simulations 11

Page 12: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

3.2. Classification: involved processes

Based on the nature of involved stochastic processes:

• discrete-time discrete-state simulations;

• discrete-time continuous-state simulations;

• continuous-time discrete-state simulations;

• continuous-time continuous-state simulations.

# of cust. in the

system

t

amount of fuel in

the tank

t

Figure 2: Continuous-time discrete-state and continuous-time continuous-state simulations.

Lecture: Introduction to simulations 12

Page 13: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

3.3. Classification: time usage

Continuous simulations:

• real time is used (note that computer time is discrete);

• time increments as fine as possible: to capture all state changes.

Discrete simulations:

• system is observed at discrete times t0, t0 + ∆t, t0 + 2∆t, . . . .

Discrete event simulations:

• we focus on system changes only at event times;

• after processing the current event, the system clock is forwarded to another event

• simulation moves from the current system state to the event occurring next;

• processing of the event may create additional events;

• event list which is updated for the system.

Lecture: Introduction to simulations 13

Page 14: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

t0 t1 t2 t3 t4 t5

t0 t1 t3

Discrete-event

Discrete

t0 t1

Continuous

t2 t3 t4 t5 t6 t7

...

Figure 3: Illustration of different types of simulations.

Lecture: Introduction to simulations 14

Page 15: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

3.4. Simulations vs. analytic: queue example

Simulation of a queue consists of:

• representation of the arrival process as a stochastic one;

• representation of service time as a stochastic process;

• representation of interoperation as a stochastic process;

• simulation run;

• collection of data;

• statistical analysis of obtained data;

• drawing conclusions.

Differences between analytical analysis and simulations:

• incorporation of simulation execution;

• incorporation of data collection and analysis.

Lecture: Introduction to simulations 15

Page 16: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

3.5. Advantages/shortcoming of simulations

Advantages:

• does not require restrictive assumption or require less of them;

• model structure, algorithms and variable may be changed quickly;

• models of traffic and service times can be used as is just from measurements;

• may provide results which are not obtainable using analytical techniques.

Shortcomings:

• time consuming, it may take much more time that analytic;

• computationally expensive;

• validation of results take additional time;

• results may be inaccurate when time of analysis is not sufficient;

• simulations may be of higher complexity than required;

• relationship between variables is hard to visualize and explain;

• sensitivity analysis is difficult.

Lecture: Introduction to simulations 16

Page 17: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

3.6. Advantages/shortcoming of analytical analysis

Advantages:

• results are straightforward (they are analytical in nature);

• exact (accurate) results are produced;

• allows optimization tasks;

• gives deep insights to the behavior of the system;

• relationship and inter-influence of variables are explainable;

• often analysis is fast (M/M/1 queue, for example).

Shortcomings:

• often requires restrictive assumptions;

• sometimes very hard;

• often impossible at all.

Lecture: Introduction to simulations 17

Page 18: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

3.7. Simulation program

Simulation program can be implemented using:

• general purpose programming languages:

– C: suitable for one purpose simulations;

– C++: suitable for writing multiple purposes simulations.

+: very flexible languages;

−: there are no simulation specific functions and error detection.

• simulation oriented programming languages:

– OPNET: general networks;

– OMNET++: ad hoc networks;

– ns2: general networks:

+: reliable approach;

−: sometimes not fast (incorporate a lot of functionality;)

−: sometimes limited to specific functionality;

−: one more language to learn.

Lecture: Introduction to simulations 18

Page 19: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

4. Discrete event simulationThe basic idea:

• only events change the state of the system;

• no need to track state of the system between events.

The whole system consists of the following components:

• system under consideration:

– process under considerations: product of other processes and RVs.

• system state:

– state of the stochastic process.

• simulation clock:

– tells the occurrence time of the next event.

• event list:

– holder for events: consider it as a two dimensional vector: time and event.

Lecture: Introduction to simulations 19

Page 20: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

The idea of the event list is illustrated in the following figure:

• Ti, i = 1, 2, . . . , are event times;

• Ei, i = 1, 2, . . . , are corresponding events.

E1

T1

E2

T2

E3

T3

...Ei

Ti

...

Figure 4: The idea of the event list.

Events are identified by event time and event type.

There are two general types of events:

• basic events:

– these events modify the state of the system: arrivals/departures of customers.

• additional events:

– these are events needed by additional tasks of simulation: run, stoppage, collection of data.

Lecture: Introduction to simulations 20

Page 21: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

General algorithm:

• initialization procedure:

– system clock should be set to zero;

– system state is assigned an initial value;

– generate list of the event and place the next event to this list.

• handling of events during a simulation:

– system clock should be set to the occurrence time of the first (next) event in event list;

– handle the event making all appropriate actions associated with the event;

– update the system state.

• stop of simulation.

Note that the following is not included:

• storing of statistical data;

• statistical analysis of obtained data.

Lecture: Introduction to simulations 21

Page 22: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

4.1. Time advance methods

Time advance methods in discrete-event simulations:

• event-advance method;

• unit-advance method.

t0 t1 t2 t3 t4 t5

t0 t1 t3

event advance:

unit-time advance:

Figure 5: Time advance techniques in discrete-event simulations.

Lecture: Introduction to simulations 22

Page 23: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

5. Example: GI/G/1 queueAssume that we are given a queuing system:

• arrival process is renewal one;

• interarrival times are gamma distributed with mean E[X] and PDF GA(a, b);

• service times are gamma distributed with mean E[Y ] and PDF GS(c, d);

• there is only one server associated with queuing system;

• the capacity of the system is infinite (there are infinitely many waiting positions).

...server

arrivals

inifnitely many waiting positions

Figure 6: Queuing system under consideration.

Note: for the system to be stable we assume that ρ = E[Y ]/E[X] < 1.

Lecture: Introduction to simulations 23

Page 24: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

What kind of analysis can we use? These are:

• first analytical approach

– consider GI/G/1 or G/G/1 system;

– only approximate results are available.

• another analytical approach:

– approximate interarrival and service times by mix of exponentials;

– analyze PH/PH/1 queuing system.

• one more analytical one:

– approximate by simpler distributions;

– most probably results will be incorrect.

• simulation approach:

– always possible;

– may be time-consuming but works.

Lecture: Introduction to simulations 24

Page 25: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

We have the following initial data for the simulation:

• renewal arrival process with gamma-distributed interarrival times with PDF GA(a, b);

• one server whose service times are gamma distributed with PDF GS(c, d).

Let us define the following for simulation:

• two types of events:

– customer arrivals;

– customer departures;

• list of events composed of available events;

• time of simulation T that is assigned an arbitrary high value Tmax;

• state of the system denoted N(t) the number of customers in that system.

It is wise to replace arbitrary choice of Tmax by a judged choice. It depends on:

• what kind of result we are asked to get (steady-state or transient);

• what type of data collection we use.

Lecture: Introduction to simulations 25

Page 26: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Simulation program should consists of the following blocks:

• initialization:

– system state N(0) = 0;

– generate time till the next arrival RV with gamma distribution GA(a, b).

• handling of arrival event:

– update the system state N(t) = N(t − 0) + 1;

– generate time till the next arrival from distribution GA(a, b).

• handling of departure event:

– update the system state N(t) = N(t − 0) − 1;

– if N(t) > 0 generate time till the next departure from distribution GS(a, b).

• stoppage:

– after every handling you may check the condition T > Tmax?. If yes: program is terminated;

– alternatively, you may handle program termination as an event.

Lecture: Introduction to simulations 26

Page 27: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Here is the trace of data that may be obtained from simulation.

N(t)

time

time

Figure 7: Arrivals, departures and N(t) as a function of time.

Lecture: Introduction to simulations 27

Page 28: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Discrete-event simulation of G/G/1 queue

INITIALIZATION

time:=0;

queue:=0;

sum:=0;

throughput:=0;

generate first interarrival time;

MAIN PROGRAM

while time < runlength do

case nextevent of

arrival event:

time:=arrivaltime;

add customer to a queue;

start new service if the service is idle;

generate next interarrival time;

departure event:

time:=departuretime;

throughput:=throughtput + 1;

remove customer from a queue;

if (queue not empty)

sum:=sum + waiting time;

start new service;

OUTPUT

mean waiting time = sum / throughput

Lecture: Introduction to simulations 28

Page 29: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Simulation of G/G/1 based on Lindley’s eqn: Wn+1=max(Wn+Bn-An,0)

INITIALIZATION

n:= 0;

w:= 0;

sum:= 0;

MAIN PROGRAM

while time < max

do

a:= new interarrival time;

b:= new service time;

w:= max(w+b-a,0);

sum:= sum+w;

n:= n+1;

end

OUTPUT

mean waiting time = sum / n

• not always we have such a simple relation;

• may not suitable for other performance measures!

Lecture: Introduction to simulations 29

Page 30: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

General procedure for discrete-event simulation

INITIALIZATION

set simulation time to 0;

initialize system state;

initialize statistical counter;

initialize event list;

MAIN PROGRAM

while time < runlength

do

determine next event type;

advance simulation time;

update system state and counters;

generate future events and add them to event list

end

OUTPUT

compute estimated;

print estimates;

Lecture: Introduction to simulations 30

Page 31: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

6. Simulations modelsThe general approach:

• problem formulation;

• construction of the model;

• model validation;

• evaluate available alternatives;

• implement the solution.

The basis is a model: representation of the real life system.

Models are classified to:

• iconic: exact replica of the properties in smaller scale (e.g. map);

• analogue: uses a set of properties in analogue structure;

• symbolic: uses mathematical relationship of certain properties.

Lecture: Introduction to simulations 31

Page 32: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Models are classified to:

• deterministic:

– do not contain elements of probability;

– examples of disciplines: linear programming, non-linear programming, etc.

– examples: finding max or min of a function.

• stochastic:

– contain elements of probability;

– examples of disciplines: queuing theory, reliability theory, etc.

– examples: model of a buffer of the switch, model of the repairment process.

Solution of the model:

• try to solve analytically;

• if not possible simulate.

Lecture: Introduction to simulations 32

Page 33: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

6.1. When we need models

There are two cases:

• evaluate the performance of the existing system;

• evaluate the performance of the system that does not exist.

Evaluate the performance of the existing system::

• what is the performance limit?

• how to optimize the system?

• how to extend the performance of the system?

Evaluate the performance of the system that does not exist:

• what the performance of system elements should be?

• what is the performance limit?

Lecture: Introduction to simulations 33

Page 34: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

6.2. Building a model

General note: a real life situation can be viewed as a system:

• system is a collection of entities which are logically related to each other.

The following elements of the system should be considered:

• environment:

– each system is a part of a broader system;

• subsystems:

– what are the subsystems of the system;

• interdependency:

– what are relations with environment?

• organization:

– what are relations between subsytems?

• change:

– what changes are allowed for the state of the system.

Lecture: Introduction to simulations 34

Page 35: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Important note:

• we do not model a whole system;

• we model only a part which is of interest.

Le

ve

lo

fd

eta

ils

Figure 8: Beard’s pyramid: shaded areas are included into the model.

Lecture: Introduction to simulations 35

Page 36: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Example: input/output queuing router servicing best effort traffic only:

• there are N input links, M output links;

• question: what the buffer space should be assigned to serve the traffic?

Input buffer 1

Input buffer i

Input buffer N

Output buffer 1

..

..

.

Internal Switching

Output buffer M

.Output buffer j

..

Figure 9: Modeling the router.

Lecture: Introduction to simulations 36

Page 37: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Example: a network:

• there are 5 routers, traffic of interest goes via 1 − 2 − 5;

• question: what the buffer space should be assigned to serve the traffic?

Router 1

Router 2

Router 3

Router 4

Router 5

k positions

...

n positions

...

m positions

...

interfering traffic interfering traffic interfering traffic

1� 2� 3�

Figure 10: Modeling the network.

Lecture: Introduction to simulations 37

Page 38: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Example: analysis of a queuing network.

...

...

...

...

Queue 1

Queue 3

Queue 4

Queue 2

under some conditions

...

...

...

...

Queue 1

Queue 3

Queue 4

Queue 2

one can analyze queues in isolation

4

1 2 3 4

1

( , , , ) ( )i i

i

p n n n n p n�

� �

Figure 11: Further modeling the queuing network.

Lecture: Introduction to simulations 38

Page 39: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

7. Example: machine interference problemProblem description:

• there are M machines of the same type;

• each machine is operational for a constant time and then breaks down;

• there is one repairmen;

• repair time of a machine is constant;

– machines are served in FIFO order;

– the service is non-preemptive;

• down time of a machine is a sum:

– waiting for a repairmen;

– repair time.

• machine immediately becomes operational after it has been fixed.

Measures of interest: downtime and utilization of the machine.

Lecture: Introduction to simulations 39

Page 40: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Figure 12: A full cycle of the machine.

Note the following:

• usually we know operational and repair time of machine in terms of pdf (our case: constant);

• to calculate down time we have to estimate the queuing time.

Figure 13: A model for downtime of the machine (queue is of D/D/1/∞/M type).

Lecture: Introduction to simulations 40

Page 41: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

State of the system: k, k = 0, 1, . . . , M number of broken down machines.

• k = 0: queue is empty, all machines are in operational state, repairmen is idle;

• k = 1: queue is empty, M − 1 machines are in operational state, repairmen is busy;

• k > 1: queue is not empty, M − k machines are in operational state, repairmen is busy.

Events that cause k to change:

• arrival to the queue: machine breaks down;

• departure from the queue: machine is fixed.

We assume the following:

• operational time is the same for all machines and equals to 10 time units;

• repair time is the same and equals to 6 time units.

Lecture: Introduction to simulations 41

Page 42: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Figure 14: Arrival and departure events.

Lecture: Introduction to simulations 42

Page 43: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

We need the following clocks:

• master clock:

– keeps track of the simulation times.

• clock associated with each machine:

– show time at which each machine breaks down;

– at any time clock of operational machines is of interest.

• departure clock

– shows time when currently served machine will become operational.

From the point of view of events:

• all in all we have (M + 1) + 1 clocks for M machines;

– 1 clock is global simulation time;

– M clocks associated with with arrival event;

– 1 clock is associated with departure event.

• comparing the value of clock we decide which event to occur next.

Lecture: Introduction to simulations 43

Page 44: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Figure 15: Manipulating events.

Lecture: Introduction to simulations 44

Page 45: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Special case:

• we have only 3 machines;

• clocks CL1, CL2 and CL3 clocks for arrival events;

• clock CL4 is associated with departure event;

• clock MC is the master clock.

Initial condition: all machines are operational, CL1 = 1, CL2 = 4 and CL3 = 9.

Figure 16: Calculation of parameters by hand.

Lecture: Introduction to simulations 45

Page 46: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Lecture: Introduction to simulations 46

Page 47: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

8. Example: production lineTwo-stages production line with one unreliable machine:

• machine 1 produces some material and puts it into buffer;

– production rate is r1;

– machine is not reliable;

– mean up time E[X] and mean repair time E[Y ] are known.

• machine 2 takes material out of that buffer and do something;

– production rate is r2;

– machine is reliable (perfect).

• buffer between two machines is of limited capacity K;

• if the buffer is full production time of machine 1 is reduced to r2;

• we have fluid in-out flows;

• we assume that r1 > r2;

Measure of interest: average production rate E[P ] of the production line.

Lecture: Introduction to simulations 47

Page 48: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

8.1. Analytical analysis

We consider:

• exponentially distributed up times and repair with means λ = 1/E[X] and µ = 1/E[Y ];

• K = 0;

• K → ∞.

If K = 0:

• P = r2 if machine 1 is working, 0 if machine 1 is not working;

• E[X] = (r2E[X])/(E[X] + E[Y ]).

If K → ∞:

• if machine 1 is working, it works at full rate r1;

• E[P1] = (r1E[X])/(E[X] + E[Y ]);

• E[P ] = min((r1E[X])/(E[X] + E[Y ]), r2).

Note: these gives the lower and upper bound on the production for K �= 0.

Lecture: Introduction to simulations 48

Page 49: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

If K is limited we denote state of the system: (i, x) where

• i is indicator: i = 0 – machine is in repair; i = 1 – machine is working;

• x, 0 ≤ x ≤ K: buffer content;

• this process is two-dimensional continuous Markov one!

Introduce jpdf:

Ft(i, x) = Pr{i(t) = j, x(t) ≤ k}, F (i, x) = Pr{i = j, x ≤ k}. (6)

Construct the following equations for the state of the system:

Ft+∆t(0, x) = Ft(0, x + r2∆t)(1 − µ∆t) + Ft(1, x + O(∆t))λ∆t + O((∆t)2),

Ft+∆t(1, x) = Ft(1, x + (r2 − r1)∆t)(1 − λ∆t) + Ft(1, x + O(∆t))µ∆t + O((∆t)2). (7)

Divide by ∆t and letting ∆t → 0 we get:

∂Ft(0, x)

∂t− r2

∂Ft(0, x)

∂x= −µFt(0, x) + λFt(1, x),

∂Ft(1, x)

∂t− (r1 − r2)

∂Ft(1, x)

∂x= µFt(0, x) − λFt(1, x), (8)

Lecture: Introduction to simulations 49

Page 50: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Letting t → ∞ observe that:

limt→∞

Ft(i, x) = F (i, x), limt→∞

∂Ft(i, x)

dt= 0. (9)

Using above we get for stationary F (i, x):

− r2F′(0, x) = −µF (0, x) + λF (1, x),

(r1 − r2)F′(1, x) = µF (0, x) − λF (1, x). (10)

Rewrite it as:⎛⎝F ′(0, x)

F ′(1, x)

⎞⎠ = A

⎛⎝F (0, x)

F (1, x)

⎞⎠ , A =

⎛⎝ µ/r2 −λ/r2

µ/(r1 − r2) −λ/(r1 − r2)

⎞⎠ . (11)

The solution is given by:⎛⎝F (0, x)

F (1, x)

⎞⎠ = C1�v1e

α1x + C2�v2eα2x, (12)

• α1, α2 are eigenvalues of A, �v1, �v2 are eigenvectors of A.

Lecture: Introduction to simulations 50

Page 51: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

The solution is then:⎛⎝F (0, x)

F (1, x)

⎞⎠ = C1

⎛⎝λ

µ

⎞⎠ + C2

⎛⎝r1 − r2

r2

⎞⎠ e(µ/r2−λ/(r1−r2))x (13)

Using boundary conditions F (1, 0) = 0, F (0, K) = λ/(λ + µ) we can find C1, C2.

Finally we have:⎛⎝F (0, x)

F (1, x)

⎞⎠ =

λ

λ + µ(λr2 − µ(r1 − r2)e

α2K)

⎛⎝r2

⎛⎝λ

µ

⎞⎠ − µ1e

α2K

⎛⎝r1 − r2

r2

⎞⎠

⎞⎠ (14)

• where α2 = µ/r2 − λ/(r1 − r2).

The average production rate:

E[P ] = r2(1 − F (0, 0)) = r2µ

λ + µ

λr1 − (λ + µ)(r1 − r2)Eα2K

λr2 − µ(r1 − r2)eα2K. (15)

Lecture: Introduction to simulations 51

Page 52: Introduction to simulations · Lecture: Introduction to simulations 3. Simulations D.Moltchanov, TUT, 2006 2. Example: GI/G/1 queuing system We know how to analyze analytically: ...

Simulations D.Moltchanov, TUT, 2006

Why is the problem? analytical analysis is possible for exponential lifetimes and repairs only!

Procedure for discrete-event simulation

INITIALIZATION

time:= 0;

buffercontent:= 0;

empty:=0;

MAIN PROGRAM

while time < runlength

do

x:=new lifetime;

time:=time+x;

buffercontent:=min(buffercontent+x(r1 -r2),K)

y:=new repairtime;

time:=time+y;

if buffercontent-yr2 < 0

then empty:=empty+y-buffercontent / r2;

buffercontent:=max(buffercontent-yr2,0)

end

OUTPUT

throughput:=r2*( (1-empty) / time);

Lecture: Introduction to simulations 52


Recommended