LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_joint.m
1%{
2%{
3 % @file pfqn_joint.m
4 % @brief Compute joint queue-length probability distribution.
5%}
6%}
7
8%{
9%{
10 % @brief Compute joint queue-length probability distribution.
11 % @fn pfqn_joint(n, L, N, Z, lGN)
12 % @param n Queue-length state vector (total or per-class).
13 % @param L Service demand matrix.
14 % @param N Population vector.
15 % @param Z Think time vector (optional).
16 % @param lGN Log normalizing constant at N (optional, computed if not provided).
17 % @return pjoint Joint probability of state n.
18%}
19%}
20function pjoint = pfqn_joint(n,L,N,Z,lGN)
21% pjoint = pfqn_joint(n,L,N,Z,lGN)
22%
23% Compute the joint queue-length probability for vector n=(n_1,...,n_M) or
24% (n_{11},...n_{M,R}), with M the number of queues, and R the number of
25% classes. If there is a think time Z, then n is just the queue population.
26% Optionally, the logarithm of the normalizing constant G at N can be passed
27% as an input to reduce the computational cost.
28%
29% Examples:
30% * Total queue-lengths
31% pjoint=[];
32% for n=0:4 % queue 1
33% for z=0:4-n % think time
34% pjoint(end+1) = pfqn_joint([n;4-n-z],[10,2;5,4],[2,2],[91,92]);
35% end
36% end
37% sum(pjoint)
38%
39% * Per-class queue-lengths
40% pjoint=[];
41% for n1=0:4 % queue 1, class 1
42% for n2=0:3 % queue 1, class 2
43% for z1=0:4-n1 % think time, class 1
44% for z2=0:3-n2 % think time, class 2
45% pjoint(end+1) = pfqn_joint([n1,n2;4-n1-z1,3-n2-z2],[10,2;5,4],[4,3],[91,92]);
46% end
47% end
48% end
49% end
50% sum(pjoint)
51
52[M,R] = size(L);
53if nargin<4
54 Z= zeros(1,R);
55end
56if nargin<5
57 [~,lGn] = pfqn_ca(L,N,Z);
58end
59if size(n,2)==1
60 % Joint probability of total queue lengths
61 if sum(Z)>0
62 n0 = sum(N) - sum(n);
63 Fjoint = Fper([L;Z],N,[n(:);n0]);
64 pjoint = exp(log(Fjoint)-lGn-factln(sum(n0)));
65 else
66 Fjoint = Fper(L,N,[n(:)]);
67 pjoint = exp(log(Fjoint)-lGn);
68 end
69elseif size(n,2)==R
70 n0 = N - sum(n,1);
71 % joint probability of total per-class queue-lengths
72 if sum(Z)>0
73 Fjoint = sum(n0.*log(Z))-sum(factln(n0));
74 else
75 Fjoint = 0;
76 end
77 for i=1:M
78 Fjoint = Fjoint + multinomialln(n(i,:)) + sum(n(i,:).*log(L(i,:)));
79 end
80 pjoint = exp(Fjoint-lGn);
81else
82 line_error(mfilename,'Invalid argument to pfqn_joint');
83end
84end
85
86function [F,A] = Fper(L,N,m)
87[M,R]=size(L);
88Ak = [];
89for r=1:R
90 Ak = [Ak, repmat(L(:,r),1,N(r))];
91end
92A = [];
93for i=1:M
94 if m(i)>0
95 A((end+1):(end+m(i)),:) = repmat(Ak(i,:),m(i),1);
96 end
97end
98F=perm(A)/prod(factorial(N));
99end