LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
getProbAggr.m
1function [Pnir,logPnir] = getProbAggr(self, ist)
2% [PNIR,LOGPNIR] = GETPROBAGGR(IST)
3%
4% Probability of a SPECIFIC per-class job distribution at a station.
5% Returns P(n1 jobs of class 1, n2 jobs of class 2, ...) for current state.
6%
7% Compare with getProbMarg: returns queue-length distribution for a
8% single class, i.e., P(n jobs of class r) for n=0,1,...,N(r).
9%
10% Input:
11% ist - Station index
12%
13% Output:
14% Pnir - Scalar probability in [0,1]
15% logPnir - Log probability for numerical stability
16
17if nargin<2 %~exist('ist','var')
18 line_error(mfilename,'getProbAggr requires to pass a parameter the station of interest.');
19end
20sn = self.getStruct;
21if ist > sn.nstations
22 line_error(mfilename,'Station number exceeds the number of stations in the model.');
23end
24if isempty(self.result)
25 self.run;
26end
27Q = self.result.Avg.Q;
28N = sn.njobs;
29if all(isfinite(N))
30 switch self.options.method
31 case 'exact'
32 line_error(mfilename,'Exact marginal state probabilities not available yet in SolverMVA.');
33 otherwise
34 state = sn.state{sn.stationToStateful(ist)};
35 [~, nir, ~, ~] = State.toMarginal(sn, ist, state);
36 % Binomial approximation with mean fitted to queue-lengths.
37 % Rainer Schmidt, "An approximate MVA ...", PEVA 29:245-254, 1997.
38 logPnir = 0;
39 for r=1:size(nir,2)
40 logPnir = logPnir + nchoosekln(N(r),nir(r));
41 logPnir = logPnir + nir(r)*log(Q(ist,r)/N(r));
42 logPnir = logPnir + (N(r)-nir(r))*log(1-Q(ist,r)/N(r));
43 end
44 Pnir = real(exp(logPnir));
45 end
46else
47 % Mixed or open model: use product-form distribution
48 U = self.result.Avg.U;
49 state = sn.state{sn.stationToStateful(ist)};
50 [~, nir, ~, ~] = State.toMarginal(sn, ist, state);
51 openClasses = find(isinf(N));
52 closedClasses = find(isfinite(N));
53 logPnir = 0;
54
55 % Product-form probability for open classes
56 if ~isempty(openClasses)
57 if sn.sched(ist) == SchedStrategy.INF
58 % Delay (infinite server): independent Poisson per class
59 for r = openClasses
60 if Q(ist,r) > 0
61 logPnir = logPnir + nir(r)*log(Q(ist,r)) - Q(ist,r) - gammaln(nir(r)+1);
62 elseif nir(r) > 0
63 logPnir = -Inf;
64 end
65 end
66 elseif sn.sched(ist) ~= SchedStrategy.EXT
67 % Queue station: multinomial-geometric product form
68 % P(n_1,...,n_R) = (1-rho) * n!/prod(n_r!) * prod(rho_r^n_r)
69 rho_total = sum(U(ist, openClasses));
70 n_total = sum(nir(openClasses));
71 if rho_total < 1
72 logPnir = logPnir + log(1 - rho_total) + gammaln(n_total + 1);
73 for r = openClasses
74 rho_r = U(ist, r);
75 if nir(r) > 0
76 if rho_r > 0
77 logPnir = logPnir + nir(r)*log(rho_r) - gammaln(nir(r)+1);
78 else
79 logPnir = -Inf;
80 end
81 end
82 end
83 else
84 logPnir = -Inf;
85 end
86 end
87 end
88
89 % Binomial approximation for closed classes
90 % Rainer Schmidt, "An approximate MVA ...", PEVA 29:245-254, 1997.
91 for r = closedClasses
92 logPnir = logPnir + nchoosekln(N(r),nir(r));
93 logPnir = logPnir + nir(r)*log(Q(ist,r)/N(r));
94 logPnir = logPnir + (N(r)-nir(r))*log(1-Q(ist,r)/N(r));
95 end
96
97 Pnir = real(exp(logPnir));
98end
99end