Page 134 - DCAP601_SIMULATION_AND_MODELING
P. 134
Simulation and Modelling
Notes 1 0 0.33996
0 1 1.0999
0 0 1.9058
function [A A D T E ] = sriesv( T, lam, l , l )
1 2 p v 1 2
% Two Servers in Series Q Simulation
t = 0; na = 0; nd = 0; n = 0; n = 0; j = 0;
1 2
ta = -log(rand)/lam; t = inf; t = inf;
1 2
while ta <= T % time left
if ta <= min( t , t ) % new arrival
1 2
t = ta; n = n + 1; na = na + 1;
1 1
ta = t - log(rand)/lam; A1(na) = t;
if n == 1, t = t + G(l ); end
1 1 1
elseif t <= t % departure from Q
1 2 1
t = t ; n = n - 1; n = n + 1; A (n -n ) = t;
1 1 1 2 2 2 a 1
if n > 0, t = t + G(l ); else, t = inf; end
1 1 1 1
if n == 1, t = t + G(l ); end
2 2 2
else % departure from Q
2
t = t ; n = n - 1; n = n + 1; D(n ) = t;
2 2 2 d d d
if n > 0, t = t + G(l ); else, t = inf; end
2 2 2 2
end, j = j + 1; Ev(j,:) = [ n n t ];
1 2
end % no more arrivals
while n > 0 % empty Q
1 1
if t <= t , t = t ; n = n - 1; n = n + 1;
1 2 1 1 1 2 2
if n > 0, t = t + G(l ); else, t = inf; end
1 1 1 1
if n == 1, t = t + G(l ); end, A (n -n ) = t;
2 2 2 2 a 1
else, t = t ; n = n - 1; n = n + 1; D(n ) = t;
2 2 2 d d d
if n > 0, t = t + G(l ); else, t = inf; end
2 2 2 2
end, j = j + 1; Ev(j,:) = [ n n t ];
1 2
end % Q is empty
1
while n > 0 % empty Q
2 2
t = t ; n = n - 1; nd = n + 1; D(n ) = t;
2 2 2 d d
if n > 0, t = t + G(l ); else, t = inf; end
2 2 2 2
j = j + 1; Ev(j,:) = [ n n t ];
1 2
end, T = max(t-T,0); % Q is empty, find T
p 2 p
% end sriesv
function Y = G(a), Y = -log(rand)/a; % Exponential(a) RV
Two Servers in Parallel
1. Hypothesis: nonhomogeneous (t) Poisson arrivals;
arrivals form single queue, service at server 1 or 2 as obtainable;
service times are RVs with distribution G and G ;
1 2
no consumers after final arrival time T.
2. Instances: airline checkin, doctor’s office, restaurant.
3. Variables: time t;
counters N , (C ,C ) #s of customers served;
A 1 2
system state SS = (n, i , i ) = customers in system, with customer # i at server j;
1 2 j
output (A(i),D(i)) customer i arrival and departure times;
event list EL = (t , t , t ) next arrival and completion times.
A 1 2
128 LOVELY PROFESSIONAL UNIVERSITY