1function [
RD] = solver_mam_passage_time(sn, PH, options)
2% [
RD] = SOLVER_MAM_PASSAGE_TIME(QN, PH, OPTIONS)
4% Copyright (c) 2012-2026, Imperial College London
7%% generate local state spaces
14% Get number of CDF points from options
15if isfield(options, 'config
') && isfield(options.config, 'num_cdf_pts
')
16 n_cdf_pts = options.config.num_cdf_pts;
28if M==2 && all(isinf(N))
29 % open queueing system (one node is the external world)
34 case SchedStrategy.EXT
35 na = cellfun(@(x) length(x{1}),{PH{ist}{:}});
36 A = {PH{ist}{1}{1},PH{ist}{1}{2},PH{ist}{1}{2}};
38 A = mmap_super(A,{PH{ist}{k}{1},PH{ist}{k}{2},PH{ist}{k}{2}});
41 case {SchedStrategy.FCFS, SchedStrategy.HOL, SchedStrategy.FCFSPRPRIO}
44 PH{ist}{k} = map_scale(PH{ist}{k}, map_mean(PH{ist}{k})/sn.nservers(ist));
45 pie{k} = map_pie(PH{ist}{k});
51 % Processor-sharing queue
54 % For PS, service times remain exponential (no scaling needed for distribution)
55 S{k} = PH{ist}{k}{1}; % Service process subgenerator
56 pie{k} = map_pie(PH{ist}{k});
61 line_error(mfilename,'Unsupported scheduling strategy
');
65 if any(sn.classprio ~= sn.classprio(1)) % if priorities are not identical
66 [uK,iK] = unique(sn.classprio);
67 if length(uK) == length(sn.classprio) % if all priorities are different
68 if sn.sched(ist)==SchedStrategy.FCFSPRPRIO
69 [Ret{1:2*K}] = MMAPPH1PRPR({A{[1,3:end]}}, {pie{:}}, {S{:}}, 'stDistrPH
');
70 else % HOL (non-preemptive)
71 [Ret{1:2*K}] = MMAPPH1NPPR({A{[1,3:end]}}, {pie{:}}, {S{:}}, 'stDistrPH
');
74 line_error(mfilename,'SolverMAM
requires either identical priorities or all distinct priorities
');
80 % MAP/M/1-PS queue: use specialized sojourn time distribution algorithm
81 % Check that service processes are exponential (M)
84 line_error(mfilename,'PS queue
requires exponential (Markovian) service times
');
88 % For single-class case, directly compute sojourn time CDF
90 % Extract MAP arrival parameters
91 C_map = A{1}; % MAP C matrix
92 D_map = A{2}; % MAP D matrix
94 % Extract exponential service rate
95 mu = -S{1}(1,1); % Service rate (S is negative generator)
98 % First get approximate mean from steady-state
99 lambda = map_lambda({C_map, D_map});
101 approx_mean = 1 / (mu * (1 - rho)); % Approximate M/M/1-PS mean
103 % Generate x points (use similar range as FCFS case)
104 x_max = approx_mean * 10; % Conservative upper bound
105 x_vals = linspace(0, x_max, n_cdf_pts);
107 % Call MAP/M/1-PS sojourn time CDF function
108 W_bar = map_m1ps_cdfrespt(C_map, D_map, mu, x_vals);
110 % Convert to CDF format (currently W_bar is complementary CDF)
115 RD{idx_q,1} = [F, x_vals(:)];
117 % Multi-class PS: aggregate arrivals into single MAP
118 % Extract individual service rates
121 mu_vec(k) = -S{k}(1,1);
124 % Check if all service rates are equal (required for current implementation)
125 if any(abs(mu_vec - mu_vec(1)) > GlobalConstants.FineTol)
126 line_error(mfilename,'Multi-
class PS currently requires identical service rates');
130 % Compute aggregated MAP parameters
132 D_map_sum = sum(cat(3, A{2:end}), 3); % Sum all
class arrival matrices
134 % Estimate CDF range
using aggregated arrival rate
135 lambda = map_lambda({C_map, D_map_sum});
137 approx_mean = 1 / (mu * (1 - rho));
139 x_max = approx_mean * 10;
140 x_vals = linspace(0, x_max, n_cdf_pts);
142 % Compute sojourn time
for aggregated system
143 W_bar = map_m1ps_cdfrespt(C_map, D_map_sum, mu, x_vals);
146 % Assign same CDF to all
classes (approximation)
149 RD{idx_q,k} = [F, x_vals(:)];
153 % FCFS/HOL queue: use existing MMAPPH1FCFS method
154 [Ret{1:2*K}] = MMAPPH1FCFS({A{[1,3:end]}}, {pie{:}}, {S{:}},
'stDistrPH');
157 alpha{k} = Ret{(k-1)*2+1};
158 D0{k} = Ret{(k-1)*2+2};
159 RDph{k}={D0{k},(-D0{k})*ones(length(alpha{k}),1)*alpha{k}(:)
'};
160 % now estimate the range of the CDF
161 sigma(k) = sqrt(map_var(RDph{k}));
162 mean(k) = map_mean(RDph{k});
164 while map_cdf(RDph{k},mean(k)+n*sigma(k)) < 1-GlobalConstants.FineTol
167 % generate CDF points
168 X = linspace(0,(mean(k)+n*sigma(k)),n_cdf_pts);
169 F = map_cdf(RDph{k},X);
171 RD{idx_q,k} = [F(:),X(:)];
176 line_warning(mfilename,'This model
is not supported by SolverMAM yet. Returning with no result.\n
');