LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_bs.m
1%{
2%{
3 % @file pfqn_bs.m
4 % @brief Bard-Schweitzer Approximate Mean Value Analysis (MVA).
5%}
6%}
7
8function [XN,QN,UN,RN,it]=pfqn_bs(L,N,Z,tol,maxiter,QN0,type)
9%{
10%{
11 % @brief Bard-Schweitzer Approximate Mean Value Analysis (MVA).
12 % @fn pfqn_bs(L, N, Z, tol, maxiter, QN0, type)
13 % @param L Service demand matrix.
14 % @param N Population vector.
15 % @param Z Think time vector.
16 % @param tol Tolerance for convergence.
17 % @param maxiter Maximum number of iterations.
18 % @param QN0 Initial guess for queue lengths.
19 % @param type Scheduling strategy type (default: PS).
20 % @return XN System throughput.
21 % @return QN Mean queue lengths.
22 % @return UN Utilization.
23 % @return RN Residence times.
24 % @return it Number of iterations performed.
25%}
26%}
27% [XN,QN,UN,RN]=PFQN_BS(L,N,Z,TOL,MAXITER,QN)
28
29if nargin<3%~exist('Z','var')
30 Z=0*N;
31end
32if nargin<4%~exist('tol','var')
33 tol = 1e-6;
34end
35if nargin<5%~exist('maxiter','var')
36 maxiter = 1000;
37end
38
39[M,R]=size(L);
40CN=zeros(M,R);
41if nargin<6 || isempty(QN0) %~exist('QN','var')
42 QN = repmat(N,M,1)/M;
43else
44 QN = QN0;
45end
46if nargin<7
47 type = SchedStrategy.PS * ones(M,1);
48end
49
50XN=zeros(1,R);
51UN=zeros(M,R);
52for it=1:maxiter
53 QN_1 = QN;
54 for r=1:R
55 if N(r) == 0
56 % Empty class: it contributes no jobs anywhere. Without this the
57 % Schweitzer term below evaluates QN*(N(r)-1)/N(r) = 0*(-Inf) = NaN,
58 % which then propagates to every other class through the s~=r term,
59 % so a single empty class returns an all-NaN solution.
60 XN(r) = 0;
61 CN(:,r) = 0;
62 QN(:,r) = 0;
63 UN(:,r) = 0;
64 continue;
65 end
66 for ist=1:M
67 CN(ist,r) = L(ist,r);
68 if L(ist,r) == 0
69 % 0 service demand at this station => this class does not visit the current node
70 continue;
71 end
72 for s=1:R
73 if s~=r
74 if type(ist) == SchedStrategy.FCFS
75 CN(ist,r) = CN(ist,r) + L(ist,s)*QN(ist,s);
76 else
77 CN(ist,r) = CN(ist,r) + L(ist,r)*QN(ist,s);
78 end
79 else
80 CN(ist,r) = CN(ist,r) + L(ist,r)*QN(ist,r)*(N(r)-1)/N(r);
81 end
82 end
83 end
84 XN(r) = N(r)/(Z(r)+sum(CN(:,r)));
85 end
86 for r=1:R
87 for ist=1:M
88 QN(ist,r) = XN(r)*CN(ist,r);
89 end
90 end
91 for r=1:R
92 for ist=1:M
93 UN(ist,r) = XN(r)*L(ist,r);
94 end
95 end
96 % Convergence is measured on the non-empty classes only: an empty class has
97 % QN = QN_1 = 0, and 0/0 = NaN would make the test never fire.
98 nz = N > 0;
99 if isempty(find(nz,1)) || max(max(abs(1-QN(:,nz)./QN_1(:,nz)))) < tol
100 break
101 end
102end
103RN = QN ./ repmat(XN,M,1);
104RN(:,N==0) = 0; % 0/0 for an empty class; its residence time is 0, not NaN
105end
Definition Station.m:245