0% found this document useful (0 votes)
6 views

modelling and simulation eksu

Modelling in computer science

Uploaded by

topzy0804
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

modelling and simulation eksu

Modelling in computer science

Uploaded by

topzy0804
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

School of Compu ng

Department of Computer Science


The Federal University of Technology, Akure, Nigeria

Modelling & Simula on1 (Tutorial)

What is the experimental defini on of probability?


Pr =

What does it mean for events to be independent?


For independent events, the occurrence of one event does not make it more or less probable that
some other event occurs.

Assume that you have three computers and two sensors in a subway train. If all three computers and
one or both sensors fail, then the subway train is uncontrolled. If the probability of a computer failing
is p and the probability of a sensor failing is q at any given me interval, what is the probability of the
subway train becoming uncontrolled in any given me interval? Assume that failures are independent.

All failure events are independent, so Pr[train uncontrolled in an interval] = p3(1 – (1 – q)2). The first
term is the probability of all three computers failing. The second term is the probability of 1 or more
sensors failing. The second term is derived as follows (1 – q) is the probability of a sensor being up,
so (1 – q)2 is the probability of both sensors being up. Then (1 – (1 – q)2) is the probability of both
sensors being not up (that is, one or two have failed).

What is a heavy tailed distribu on (i.e., what are its key proper es or characteris cs)? Give an example
of a real-life event (related to informa on technology systems) that may be heavy tailed.
A heavy-tailed distribu on has most of its mass in its tail. O8en, a heavy tailed distribu on will have
infinite mean and/or variance. Download sizes may be heavy-tailed. Most downloads are small, but
a very few are extremely large (say, network back-ups of an en re hard drive).

Define X to be a random variable that takes on the value of the number of failed servers for a given
period of observa on. Over many observa on periods you have found the probability that 0 servers
fail in a given period of observa on is 0.5, 1 server fails is 0.2, and 2 servers fail is 0.3. What is the mean
value of X? What is the standard devia on of X? Plot the probability mass func on and cumula ve
distribu on func on of X.

Pr[X = 0] = 0.5, Pr[X = 1] = 0.2, and Pr[X = 2] = 0.30.


E[X] = (0.5)(0) + (0.2)(1) + (0.3)(2) = 0.80
σ2 = E[X2] – E[X]2 = ((0.5)(0)2 + (0.2)(1)2 + (0.3)(2)2) – (0.8)2 = 0.76

1
Olumide Sunday Adewale, fsca
Assume you have made measurements on the size of file downloads. You have observed 1 million file
downloads and found that 900,000 downloads were exactly 10 KBytes, 199,999 downloads were
exactly 100 Kbytes, and 1 download was exactly 1 GByte. Download sizes are independent of each
other. Write a C func on that returns a download size based on an empirical distribu on from the
measurements made. You may assume that you have a func on randUnif() that returns a uniformly
distributed random value between 0 and 1.

int downloadSize()
{
double z;
// Uniform random number (0 < z < 1)
// Pull a uniform random number (0 <= z <= 1)
z = randUnif();
// Return a download size based on an empirical distribu on
if (z < ((double) 900000 / 1000000)) return(10*1024);
if (z < ((double) 999999 / 1000000)) return(100*1024);
return(1024*1024*1024);
}

What are the key characteris cs of queues?


Key characteris cs are arrival process, service me distribu on, number of servers, system capacity,
popula on size, and service discipline.

Describe the Kendall nota on. Describe it.


Kendall nota on describes a queue as A/S/c/k/m where A is the arrival process, S is the service me
distribu on, c is the number of servers, k is the system capacity, and m is the customer popula on.
A and S can be M for Markov (exponen al), D for determinis c, and G for general. A category with
a numerical quan ty that is infinity is omiOed.

State LiOle's Law.


L = λW where L = number of customers in the system, λ = arrival rate of customers, and W = wait
me (this includes service me) of a customer in the system.

Given an M/M/1 queue with u liza on of 90%, what is the mean number of customers in the system?
What is the mean number of customers in the queueing area?

0.9
= = =9
1 1 0.9
$= , $ = 8.1
Repeat the above ques on for an M/D/1 queue.

( )1
' *+( ,
= '
2)1 ,
0.9( )1 ' 0,
= 0.9 ' = 4.95
2)1 0.9,

Consider the following single-server queueing system from me = 0 to me = 20 sec. Arrivals and
service mes are:
• Customer #1 arrives at t = 1 second and requires 5 seconds of service me
• Customer #2 arrives at t = 1 second and requires 2 seconds of service me
• Customer #3 arrives at t = 2 seconds and requires 3 seconds of service me
• Customer #4 arrives at t = 12 seconds and requires 6 seconds of service me
Solve: for system throughput (X), total busy me (B), mean service me (Ts), u lisa on (U), mean
system me (delay in system) (W), and mean number in the system (L).

* 4
0= = = 0.2 23
1 20

4 16
B = 16 seconds (by inspec on)
1 = = = 4.0 23
* 4
4 16
6= = = 80%
1 20
9 27
8= = = 6.75
* 4
9 27
= = = 1.35
1 20

Write a Monte Carlo simula on to integrate sin(x) from 0 to π (that is, find the area under sin(x) from
0 to π; where π = 3.14159). Note that C does include a sin() func on in the math library. Focus on the
main program. You may assume that you have a func on named randUnif()that returns a uniformly
distributed random value between 0 and 1.

#include <stdio.h>
#include <math.h>
#define NUM_ITER 1000000 // Number of itera ons to run for
double rand_val(int seed); // RNG for uniform(0.0, 1.0) from Jain
int main()
{
double x, y; // X and Y values
double x_max; // Integra on bound for x for f(x)
double y_max; // Integra on bound for y for f(x)
double hitCount; // Count of hits within the quarter circle
double area_est; // Es mated area
int i; // Loop counter
// Ini alize x_max and y_max
x_max = 3.14159;
y_max = 1;
// Seed the RNG and ini alize hitCount to zero
rand_val(1);
hitCount = 0.0;
// Do for NUM_ITER itera ons
for (i=0; i<NUM_ITER; i++)
{
// Throw the dart
x = rand_val(0) * x_max;
y = rand_val(0) * y_max;
// Determine if the dart is under the sin(x) curve
if (y < sin(x)) hitCount++;
}
// Es mate the area
area_est = (hitCount / 1000000) * (x_max * y_max);
// Output results
prin[("Es mated area (from 0 to %f) = %f \n", x_max, area_est);
return(0);
}

a) For an M/M/1 queue we know that the mean number of customers in the system (L) is equal to the
u liza on divided by one minus the u liza on. Using basic laws and rela onships, derive the mean
wait in the system (W), the mean number of customers in the queueing area (Lq), and the mean wait
in the queuing area (Wq) as a func on of arrival rate and service rate. For full credit, your expressions

= 32< where = > where λ = customer arrival rate and μ = customer service rate.
< =
need to be simplified.
Recall that
LiOle's Law states that L = λW. Recall also that Lq = L − ρ and 8$ = 8 Therefore, 8 = >2=,
3 3
>
.
8$ = )>2=,>, and $ = 32<.
= <?

Consider a single server queue with Poisson arrivals (rate λ) and a uniformly distributed service me
(with minimum value a seconds and maximum value b seconds). Solve for the mean number of
customers in the system (L). You do not need to simplify your expression for L.

This is an M/G/1 queue where G is uniform with @ = )A ' , and B ( = ) A,( and therefore
3 3
( 3(
D
C .)E2F,
* = . Recall that = =
D? (=
D
)FGE, FGE
. Using the Pollaczek-Khintchine formula (for M/G/1), then
?
?
D
C .)OSM,
?L ? D?
KMNOP QR D T U
)MNO,

' = FGE '


<? H3GI+? J (= ?

()32<, (K32
?L
P
(simplifica on is not necessary).
MNO

Write a Monte Carlo simula on to model a biased coin as follows. When flipped if the coin show tails
it has a 50% chance of tails or heads on the next flop. However, if the coin shows heads then it has
75% chance of showing heads again on the next flip. The Monte Carlo simula on should determine
the probability of a head showing. You may assume that you have access to a func on rand_val() that
returns uniform(0.0, 1.0).
int main()
{
double head_prob; // Probability of flipping a head
double heads, tails; // Counters for heads and tails
int i; // Loop counter
rand_val(1);
head_prob = 0.50;
heads = tails = 0;
for (i=0; i<NUM_ITER; i++)
{
if (rand_val(0) < head_prob)
{
heads++;
head_prob = 0.75;
}
else
{
tails++;
head_prob = 0.50;
}
}
prin[("Pr[head] = %f \n", (double) heads / (heads + tails));
return(0);
}

Define the term used in discrete event simula on: (i) system safe; (ii) list; (iii) event; (iv) future event
list; (v) delay; and (vi) system

System state: a collec on of variables that contain all the informa on necessary to describe the
system at any me
List: a collec on of (permanently or temporarily) associated en es ordered in some logical fashion
(such as all customers currently in a wai ng line, ordered by first come, first served, or by priority).
Event: an instantaneous occurrence that changes the state of a system as an arrival of a new
customer.
Future event list: a list of event no ces for future events, ordered by me of occurrence.
Delay: an instantaneous occurrence that changes the state of a system as an arrival of a new
customer.
System: a collec on of en es (for example, people and machines) that ii together over me to
accomplish one or more goals.

Consider the grocery store with one checkout counter. Prepare the simula on table for eight
customers and find out average wai ng me of customer in queue, idle me of server and average
service me. Given inter arrival me: 3,2,6,4,4,5,8; and service me (min): 3,5,5,8,4,6,2,3. Assume first
customer arrives at me t=0. The inter arrival me and service me are given in minutes.
Clock LQ(t) LS(t) Future Comment B MQ
event list
0 0 1 (D,4) First a occurs (a*=8) schedule 0 0
(A,8) next A (s*=4) schedule next D
(E,60)
4 0 0 (A,8) First D occurs; (D,4) 4 0
(E,60)
8 0 1 (D,9) Second A occurs; (a,8) (a*=6) 4 0
(A,14) schedule next A (s*=1)
(E,60) schedule next D
9 0 0 (A,14) Second D occurs; (D,9) 5 0
(E,60)

System state: LQ(t), LS(t) is the number of customers in the wai ng line and the number being served
(0 or 1) at me t. Events A, D represent arrival and departure respec vely. Event no ces: (A, t), (D, t)
represent an arrival event to occur at future me t & a customer departure at me t (see pages 44-
49 of the "simula on and modelling").

Suppose the maximum inventory level is M 11 units and the review period is 5 days es mate by
simula on the average ending units in inventory and number of days when a shortage condi on
occurs. Ini al simula on is started with level of 3 units and an order of 8 units scheduled to arrive in
two days me. Simulate for three cycles (15 days) The probability for daily demand and lead me is
given as follows:
Demand 0 1 2 3 4
Probability 0.1 0.25 0.35 0.2 0.1

Lead me 1 2 3
Probability 0.6 0.3 0.2

Random digits for demand: 24,35,65,25,8,85,77,68,28,5,92,55,49,69,70


Random digit for lead: 5,0,3

See pages 33-35 for the solu on

Six dump trucks are used to haul coal from the entrance of a small mine to railroad. Each truck is
loaded by one of two loaders. A8er loading truck moves to scale, to be weighed. A8er weighing a
truck begins to travel me and then returns to loader queue. It has been assumed that five of trucks
are at loader and one at scale at me 0. By using event scheduling algorithm find out busy me of
loader and scale while the stopping me E is 64 mins. The ac vity mes are provided as follows.

Loading me 10 5 5 10 15 10 10
Weighing me12 12 12 16 12 16 -
Travel me 60 100 40 40 80 - -

See pages 51-54

List any five situa ons each when simula on tool is appropriate and not appropriate tool.
 When simula on is the appropriate tool
 Simula on enables the study of and experimenta on with the internal interac ons of a complex
system, or of a subsystem within a complex system.
 Informa onal, organiza onal and environmental changes can be simulated and the effect of
those alterna ons on the model's behaviour can be observer.
 The knowledge gained in designing a simula on model can be of great value toward sugges ng
improvement in the system under inves ga on
 By changing simula on inputs and observing the resul ng outputs, valuable insight may be
obtained into which variables are most important and how variables interact
 etc

 When simula on is not appropriate


 Simula on should be used when the problem cannot be solved using common sense.
 Simula on should not be used if the problem can be solved analy cally.
 Simula on should not be used, if it is easier to perform direct experiments.
 Simula on should not be used, if the costs exceed savings.
 Etc

Explain with the aid of a suitable diagram verifica on of simula on model.

What is simula on? Explain with flow chart, the steps involved in simula on study.
A Simula on is the imita on of the opera on of a real-world process or system over me. The
behaviour of a system as it evolves over me is studied by developing a simula on model. This
model takes the form of a set of assump ons concerning the opera on of the system.
The simula on model building can be broken into 4 phases.
I Phase
 Consists of steps 1 and 2
 It is period of discovery/orienta on
 The analyst may have to restart the process if it is not fine-tuned
 Recalibra ons and clarifica ons may occur in this phase or another phase.

II Phase
 Consists of steps 3,4,5,6 and 7
 A con nuing interplay is required among the steps
 Exclusion of model user results in implica ons during implementa on

III Phase
 Consists of steps 8,9 and 10
 Conceives a thorough plan for experimen ng
 Discrete-event stochas c is a sta s cal experiment
 The output variables are es mates that contain random error and therefore proper sta s cal
analysis is required.
IV Phase
 Consists of steps 11 and 12
 Successful implementa on depends on the involvement of user and every steps
 successful comple on.

A grocery store has one checkout counter. Customers arrive at this checkout counter at random from
1 to 8 minutes apart and each interval me has the same probability of occurrence. The service mes
vary from 1 to 6 minutes with probability given as follows
Services(minutes) 1 2 3 4 5 6
Probability 0.10 0.20 0.30 0.25 0.10 0.05

Simulate the arrival of 6 customers and calculate: (a) average wai ng me for a customer; (b)
probability that a customer has to wait; (c) probability of a server being idle; and (d) average service
me. Use me between arrival and the following sequence of random numbers:
Random digit for arrival 913 727 015 948 309 922
Random digit for service me 84 10 74 53 17 79

Assume that the first customer arrives at me 0. Depict the simula on in a tabular form.
Explain event scheduling algorithm by genera ng system snapshots at clock=t and clock=O
The Event-Scheduling/Time-Advance Algorithm
Discuss the following: (i) systems; (ii) models; (iii) the various steps in a sound simula on study; (iv)
the advantages, disadvantages, and pi[alls of simula on; and (v) the importance of list processing in
simula on.

Let V3 , V( , … , V be the probabili es of zero person, one person, and two people and so on. From the
customer point of view, the customer is ordinarily interested in four types of parameters: length of
system, Ls; length of queue, Lq; wai ng me in the system, Ws; and wai ng me in the queue, Wq.
Suppose h is the small interval of me, then we have Pn(t + h) = Pn-1(t) (Probability of one arrival and
no service) (λh) + Pn+1(t) (Probability of one service and no arrival) (μh) + Pn(t) (Probability no arrival
and no service), that is,

V ) ' ℎ, = V 23 ) ,)Yℎ,)1 @ℎ, ' V G3 ) ,)@ℎ,)1 Yℎ, ' V )1 Yℎ,)1 @ℎ,


Z )1 ,; ] = 0, 1, 2, … and obtain
Show that VZ = Z
V[ = +, ^, 8+ , 8^ .

The following components will be found in most discrete-event simula on models using the next-event
me-advance approach programmed in a general-purpose language: system state; simula on clock;
sta s cal counters; ini alisa on rou ne; ming rou ne; event rou ne; library rou nes; report
generator; and main program. Represent the flow of control for the next-event me-advance approach
among these components.

Illustrate in detail the next-event me-advance approach for a single-server queuing system given the
following nota on: ti = me of arrival of the ith customer (t0 = 0); Ai = ti - ti-1 = interarrival me between
(i–1)st and ith arrivals of customers; Si = me that server actually spends serving ith customer
(exclusive of customer’s delay in queue); Di = delay in queue of ith customer; ci = ti + Di + Si = me that
ith customer completes service and departs; and ei = me of occurrence of ith event of any type (ith
value the simula on clock takes on, excluding the value e0 = 0).

Consider a single-server queuing system for which the interarrival mes A1, A2,... are independent and
iden cally distributed random variables, es mate the expected average delay in queue of the n
customers comple ng their delays during the simula on; expected average number of customers in
the queue (but not being served); and the propor on of me during the simula on the server is busy.
Simulate a single-server queuing system by showing how its simula on model would be represented
inside the computer at me e0 = 0 and the mes e1, e2,..., e13 at which the 13 successive events occur
that are needed to observe the desired number, n = 6, of delays in queue. Assume that the interarrival
and service mes of customers are: A1 = 0.4, A2 = 1.2, A3 = 0.5, A4 = 1.7, A5 = 0.2, A6 = 1.6, A7 = 0.2, A8
= 1.4, A9 = 1.9,...; S1 = 2.0, S2 = 0.7, S3 = 0.2, S4 = 1.1, S5 = 3.7, S6 = 0.6, … Give the first three snapshots
of the system itself and of a computer representa on of the system at each of the mes e0 = 0, e1 =
0.4, ..., e13=8.6

A company sells a single product and would like to decide how many items it should have in inventory
for each of the next n months (n is a fixed input parameter). The mes between demands are
independent and iden cally distributed exponen al random variables with a mean of 0.1 month. The
sizes of the demands, D, are independent and iden cally distributed random variables (independent
of when the demands occur), with

1
⎧1 9 ℎ A d
6
⎪ 1
⎪29 ℎ A d
_= 3
⎨39 ℎ 1
A d
⎪ 3
⎪ 1
⎩49 ℎ A d
6
At the beginning of each month, the company reviews the inventory level and decides how many items
to order from its supplier. If the company orders Z items, it incurs a cost of K + iZ, where K = N32 is the
setup cost and i = N3 is the incremental cost per item ordered. (If Z = 0, no cost is incurred.) When an
order is placed, the me required for it to arrive (called the delivery lag or lead me) is a random
variable that is distributed uniformly between 0.5 and 1 month. The company uses a sta onary (s, S)
policy to decide how much to order, that is,

g h h<
e=f
0 h≥

where I is the inventory level at the beginning of the month. When a demand occurs, it is sa sfied
immediately if the inventory level is at least as large as the demand. If the demand exceeds the
inventory level, the excess of demand over supply is backlogged and sa sfied by future deliveries. (In
this case, the new inventory level is equal to the old inventory level minus the demand size, resul ng
in a nega ve inventory level.) When an order arrives, it is first used to eliminate as much of the backlog
(if any) as possible; the remainder of the order (if any) is added to the inventory. Let I(t) be the
inventory level at me t [note that I(t) could be posi ve, nega ve, or zero]; let I+(t) = max{I(t), 0} be the
number of items physically on hand in the inventory at me t [note that I+(t) ≥ 0]; and let I-(t) = max{-

of I(t), I-(t), and I-(t). Obtain hG̅ and h 2̅ .


I(t), 0} be the backlog at me t [I-(t) = 0 as well]. With a suitable diagram, provide a possible realisa on

Applica on areas of simula on

Discuss Monte Carlo simula on, its important characteris cs, advantages & disadvantages. With the
aid of a suitable generalised flowchart of Monte Carlo simula on.

You might also like