LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
getProbMarg.m
1function [Pmarg, logPmarg] = getProbMarg(self, ist, jobclass, state_m)
2% [PMARG, LOGPMARG] = GETPROBMARG(IST, JOBCLASS, STATE_M)
3%
4% Probability distribution for queue length of a SINGLE class at a station.
5% Returns P(n jobs of class r) for n=0,1,...,N(r).
6%
7% Compare with getProbAggr: returns probability of a specific per-class
8% distribution, e.g., P(2 class-1, 1 class-2) as a scalar.
9%
10% Input:
11% ist - Station index
12% jobclass - Class index
13% state_m - (optional) Specific states to query, or [] for all
14%
15% Output:
16% Pmarg - Vector where Pmarg(n+1) = P(n jobs of this class)
17% logPmarg - Log probabilities for numerical stability
18
19if nargin < 3
20 line_error(mfilename,'getProbMarg requires station and job class parameters.');
21end
22if nargin < 4
23 state_m = [];
24end
25
26sn = self.getStruct;
27if ist > sn.nstations
28 line_error(mfilename,'Station number exceeds the number of stations in the model.');
29end
30if jobclass > sn.nclasses
31 line_error(mfilename,'Job class index exceeds the number of classes in the model.');
32end
33
34if isempty(self.result)
35 self.run;
36end
37
38N = sn.njobs;
39if all(isfinite(N))
40 switch self.options.method
41 case 'exact'
42 % Use MVALDMX to get exact marginalized probabilities
43 if ~all(sn.nservers == 1)
44 line_error(mfilename,'MVALDMX exact marginalized probabilities require single-server stations.');
45 end
46
47 lambda = sn.lambda;
48 D = sn.demands;
49 Z = diag(sn.think);
50 mu = sn.mu;
51 S = ones(sn.nstations, 1);
52
53 try
54 [~, ~, ~, ~, ~, Pc] = pfqn_mvaldmx(lambda, D, N, Z, mu, S);
55
56 % Extract marginal probabilities for the specific station and class
57 % Use the station probabilities from MVALDMX and marginalize for the specific class
58 Q = self.result.Avg.Q;
59 qVal = Q(ist, jobclass);
60 nVal = N(jobclass);
61
62 % Create probability vector for this class at this station using binomial approximation
63 Pmarg = zeros(1, nVal + 1);
64 logPmarg = zeros(1, nVal + 1);
65
66 for k = 0:nVal
67 % Binomial probability with mean qVal
68 logPk = nchoosekln(nVal, k) + k * log(qVal / nVal) + (nVal - k) * log(1 - qVal / nVal);
69 Pmarg(k + 1) = exp(logPk);
70 logPmarg(k + 1) = logPk;
71 end
72
73 % Filter based on state_m if provided
74 if ~isempty(state_m)
75 if max(state_m) > length(Pmarg) - 1
76 line_error(mfilename,'Requested state exceeds maximum population for this class.');
77 end
78 Pmarg = Pmarg(state_m + 1); % +1 for MATLAB indexing
79 logPmarg = logPmarg(state_m + 1);
80 end
81
82 catch ME
83 line_error(mfilename,'Failed to compute marginalized probabilities using MVALDMX: %s', ME.message);
84 end
85
86 otherwise
87 % Use binomial approximation similar to getProbAggr but for single class
88 Q = self.result.Avg.Q;
89 qVal = Q(ist, jobclass);
90 nVal = N(jobclass);
91
92 % Create probability vector for this class at this station
93 Pmarg = zeros(1, nVal + 1);
94 logPmarg = zeros(1, nVal + 1);
95
96 for k = 0:nVal
97 % Binomial probability with mean qVal
98 % Rainer Schmidt, "An approximate MVA ...", PEVA 29:245-254, 1997
99 logPk = nchoosekln(nVal, k) + k * log(qVal / nVal) + (nVal - k) * log(1 - qVal / nVal);
100 Pmarg(k + 1) = real(exp(logPk));
101 logPmarg(k + 1) = logPk;
102 end
103
104 % Filter based on state_m if provided
105 if ~isempty(state_m)
106 if max(state_m) > length(Pmarg) - 1
107 line_error(mfilename,'Requested state exceeds maximum population for this class.');
108 end
109 Pmarg = Pmarg(state_m + 1); % +1 for MATLAB indexing
110 logPmarg = logPmarg(state_m + 1);
111 end
112 end
113else
114 line_error(mfilename,'getProbMarg not yet implemented for models with open classes.');
115end
116end