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% see _kb/03-api-layer.md (pfqn/ family: scaling, log-domain switches, dispatch gates)
34useLog = isreal(L) && isreal(mu) && all(L(:)>=0) && all(mu(:)>0);
35
36if useLog
37 % see _kb/03-api-layer.md (pfqn/ family: scaling, log-domain switches, dispatch gates)
38 lg = -Inf(M+1, Nscal+1, Nscal+2);
39 % lg(0+1,n+1,1+1) stays -Inf for n>=1: no station can hold n>=1 jobs.
40 lL = log(L); % -Inf where the demand is zero
41 lmu = log(mu); % +Inf where the rate is infinite, zeroing the term
42 for m=1:M
43 for tm=1:(Nscal+1)
44 lg(m +1,0 +1,tm +1)=0; % log(1): zero jobs
45 end
46 for n=1:Nscal
47 for tm=1:(Nscal-n+1)
48 a = lg(m-1 +1, n +1, 1 +1);
49 b = lL(m) + lg(m +1, n-1 +1, tm+1 +1) - lmu(m,tm);
50 % pairwise log-sum-exp of a and b, stable when either is -Inf
51 if a > b
52 if b == -Inf
53 lg(m +1, n +1, tm +1) = a;
54 else
55 lg(m +1, n +1, tm +1) = a + log1p(exp(b-a));
56 end
57 else
58 if a == -Inf
59 lg(m +1, n +1, tm +1) = b;
60 else
61 lg(m +1, n +1, tm +1) = b + log1p(exp(a-b));
62 end
63 end
64 end
65 end
66 end
67 lG = lg(M +1,Nscal +1,1 +1);
68 G = exp(lG);
69else
70 g = zeros(M+1, Nscal+1, Nscal+2);
71 for n=1:Nscal
72 g(0 +1,n +1, 1 +1)=0;
73 end
74 for m=1:M
75 for tm=1:(Nscal+1)
76 g(m +1,0 +1,tm +1)=1;
77 end
78 for n=1:Nscal
79 for tm=1:(Nscal-n+1)
80 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);
81 end
82 end
83 end
84 G = g(M +1,Nscal +1,1 +1);
85 lG = log(G);
86end
87end