LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_gldsingle.m
1%{
2%{
3 % @file pfqn_gldsingle.m
4 % @brief Exact normalizing constant for single-class load-dependent models.
5%}
6%}
7
8%{
9%{
10 % @brief Exact normalizing constant for single-class load-dependent models.
11 % @fn pfqn_gldsingle(L, N, mu, options)
12 % @param L Service demand vector (Mx1).
13 % @param N Population (scalar).
14 % @param mu Load-dependent rate matrix (MxN).
15 % @param options Solver options.
16 % @return lG Logarithm of normalizing constant.
17 % @return G Normalizing constant.
18%}
19%}
20function [lG,G]=pfqn_gldsingle(L,N,mu,options)
21% G=PFQN_GLDSINGLE(L,N,MU)
22
23if nargin<4
24 options = [];
25end
26
27[M,R]=size(L);
28if R>1
29 line_error(mfilename,'multiclass model detected. pfqn_gldsingle is for single class models.');
30end
31Nscal = N(1); % codegen: ensure scalar loop bound
32
33% Logarithms are only defined for this recursion when the demands are real and
34% non-negative and the rates are real and positive (Inf allowed: it zeroes the
35% term). pfqn_rd calls this function with load-dependent rates beta that may be
36% negative, which makes the intermediate g negative and log(G) complex (hence
37% the real() wrapper at its call site), so that case keeps the linear-scale
38% recursion below.
39useLog = isreal(L) && isreal(mu) && all(L(:)>=0) && all(mu(:)>0);
40
41if useLog
42 % pfqn_ncld normalizes the demands into [0,1] before calling, which makes
43 % the delay contribution of order 1/Nscal! and drives g below realmin for
44 % moderate populations (e.g. Nscal>=190 for a Delay+multiserver layer). In
45 % linear scale g then underflows to exactly 0 and log(G) returns -Inf,
46 % silently propagating NaN throughputs to the caller. Logarithms keep every
47 % intermediate in range; the two recursion terms are combined by a pairwise
48 % log-sum-exp.
49 lg = -Inf(M+1, Nscal+1, Nscal+2);
50 % lg(0+1,n+1,1+1) stays -Inf for n>=1: no station can hold n>=1 jobs.
51 lL = log(L); % -Inf where the demand is zero
52 lmu = log(mu); % +Inf where the rate is infinite, zeroing the term
53 for m=1:M
54 for tm=1:(Nscal+1)
55 lg(m +1,0 +1,tm +1)=0; % log(1): zero jobs
56 end
57 for n=1:Nscal
58 for tm=1:(Nscal-n+1)
59 a = lg(m-1 +1, n +1, 1 +1);
60 b = lL(m) + lg(m +1, n-1 +1, tm+1 +1) - lmu(m,tm);
61 % pairwise log-sum-exp of a and b, stable when either is -Inf
62 if a > b
63 if b == -Inf
64 lg(m +1, n +1, tm +1) = a;
65 else
66 lg(m +1, n +1, tm +1) = a + log1p(exp(b-a));
67 end
68 else
69 if a == -Inf
70 lg(m +1, n +1, tm +1) = b;
71 else
72 lg(m +1, n +1, tm +1) = b + log1p(exp(a-b));
73 end
74 end
75 end
76 end
77 end
78 lG = lg(M +1,Nscal +1,1 +1);
79 G = exp(lG);
80else
81 g = zeros(M+1, Nscal+1, Nscal+2);
82 for n=1:Nscal
83 g(0 +1,n +1, 1 +1)=0;
84 end
85 for m=1:M
86 for tm=1:(Nscal+1)
87 g(m +1,0 +1,tm +1)=1;
88 end
89 for n=1:Nscal
90 for tm=1:(Nscal-n+1)
91 g(m +1, n +1, tm +1)= g(m-1 +1, n +1, 1 +1)+L(m)*g(m +1, n-1 +1, tm+1 +1)/mu(m,tm);
92 end
93 end
94 end
95 G = g(M +1,Nscal +1,1 +1);
96 lG = log(G);
97end
98end
Definition Station.m:245