LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_mvald.m
1%{
2%{
3 % @file pfqn_mvald.m
4 % @brief Exact MVA for load-dependent closed queueing networks.
5%}
6%}
7
8%{
9%{
10 % @brief Exact MVA for load-dependent closed queueing networks.
11 % @fn pfqn_mvald(L, N, Z, mu, stabilize)
12 % @param L Service demand matrix.
13 % @param N Population vector.
14 % @param Z Think time vector.
15 % @param mu Load-dependent rate matrix (MxNt).
16 % @param stabilize Force non-negative probabilities (default: true).
17 % @return XN System throughput.
18 % @return QN Mean queue lengths.
19 % @return UN Utilization.
20 % @return CN Cycle times.
21 % @return lGN Logarithm of normalizing constant evolution.
22 % @return isNumStable Numerical stability flag.
23 % @return pi Marginal queue-length probabilities.
24%}
25%}
26function [XN,QN,UN,CN,lGN,isNumStable,pi]=pfqn_mvald(L,N,Z,mu,stabilize)
27% [XN,QN,UN,CN,LGN]=PFQN_MVALD(L,N,Z,MU)
28
29[M,R]=size(L); % get number of queues (M) and classes (R)
30
31XN = zeros(M,R);
32QN = zeros(M,R);
33UN = zeros(M,R);
34CN = zeros(M,R);
35WN = zeros(M,R);
36lGN = -Inf;
37
38if any(N<0)
39 isNumStable = true;
40 return
41end
42% stabilize ensures that probabilities do not become negative
43if nargin<5
44 stabilize = true;
45end
46
47warn = true;
48isNumStable = true;
49Xs=zeros(R,prod(N+1)); % throughput for a model with station i less
50pi=ones(M,sum(N)+1,prod(N+1)); % marginal queue-length probabilities pi(k)
51n=pprod(N); % initialize the current population
52lGN = 0;
53while n~=-1
54 WN=0*WN;
55 for s=1:R
56 if n(s)>0
57 for ist=1:M
58 WN(ist,s)=0;
59 for k=1:sum(n)
60 WN(ist,s)=WN(ist,s)+(L(ist,s)/mu(ist,k))*k*pi(ist,(k-1)+1,hashpop(oner(n,s),N));
61 end
62 end
63 Xs(s,hashpop(n,N))=n(s)/(Z(s)+sum(WN(:,s)));
64 end
65 end
66
67 % compute pi(k|n)
68 for k=1:sum(n)
69 for ist=1:M
70 pi(ist,(k)+1,hashpop(n,N))=0;
71 end
72 for s=1:R
73 if n(s)>0
74 for ist=1:M
75 pi(ist,(k)+1,hashpop(n,N)) = pi(ist,(k)+1,hashpop(n,N)) + (L(ist,s)/mu(ist,k))*Xs(s,hashpop(n,N))*pi(ist,(k-1)+1,hashpop(oner(n,s),N));
76 end
77 end
78 end
79 end
80
81 % compute pi(0|n)
82 for ist=1:M
83 p0 = 1-sum(pi(ist,(1:sum(n))+1,hashpop(n,N)));
84 if p0<0
85 if warn
86 line_warning(mfilename,'MVA-LD is numerically unstable on this model, LINE will force all probabilities to be non-negative.\n');
87% N
88 warn=false;
89 isNumStable = false;
90 end
91 if stabilize
92 pi(ist,(0)+1,hashpop(n,N)) = eps;
93 else
94 pi(ist,(0)+1,hashpop(n,N)) = p0;
95 end
96 else
97 pi(ist,(0)+1,hashpop(n,N)) = p0;
98 end
99 end
100
101 last_nnz = find(n>0, 1, 'last' );
102 if sum(n(1:last_nnz-1)) == sum(N(1:last_nnz-1)) && sum(n((last_nnz+1):R))==0
103 logX = log(Xs(last_nnz,hashpop(n,N)));
104 %hashpop(n,N)
105 if ~isempty(logX)
106 lGN(end+1) = lGN(end) - logX;
107 end
108 end
109
110 n=pprod(n,N); % get the next population
111end
112X=Xs(:,hashpop(N,N));
113XN=X';
114pi=pi(:,:,hashpop(N,N));
115QN = WN.*repmat(XN,M,1);
116%UN = repmat(XN,M,1) .* L;
117UN = 1-pi(:,1);
118CN = N./XN - Z; % cycle time exclusive of think time
119end
120
121function i=hashpop(n,N)
122% I=HASHPOP(N,N)
123
124i=1; % index of the empty population
125for r=1:length(N)
126 i=i+prod(N(1:r-1)+1)*n(r);
127end
128end