1function [ph, phases] = refreshProcessRepresentations(self)
2% [PH, PHASES] = REFRESHPROCESSREPRESENTATIONS()
4% Copyright (c) 2012-2026, Imperial College London
8M = getNumberOfStations(self);
9K = getNumberOfClasses(self);
12 ph{ist,1} = cell(1,K);
15stations = self.stations;
17 if ist == self.getIndexSourceStation
18 ph_i = stations{ist}.getSourceRates();
20 switch class(stations{ist})
28 ph_i = Coxian(mu_i,phi_i).getProcess;
35 ph_i{r} = Coxian(mu_i{r},phi_i{r}).getProcess;
38 ph_i = stations{ist}.getServiceRates();
43 if isempty(ph{ist}{r}) % fluid fails otherwise
45 elseif ~isMAP(ph{ist}{r})
46 % Non-Markovian distribution: convert to MAP representation
47 ph{ist}{r} = convertToMAP(stations{ist}, r, ph{ist}{r});
48 phases(ist,r) = length(ph{ist}{r}{1});
49 elseif any(isnan(ph{ist}{r}{1}(:))) || any(isnan(ph{ist}{r}{2}(:))) % disabled
52 phases(ist,r) = length(ph{ist}{r}{1});
56if ~isempty(self.sn) %&& isprop(self.sn,
'mu')
63 %.proc{i}{r} = map_normalize(map_ir);
64 proc{ist}{r} = map_ir;
65 pie{ist}{r} = map_pie(map_ir);
73 self.sn.phases = phases;
74 self.sn.phasessz = max(self.sn.phases,ones(size(self.sn.phases)));
75 self.sn.phasessz(self.sn.nodeToStation(self.sn.nodetype == NodeType.Join),:)=phases(self.sn.nodeToStation(self.sn.nodetype == NodeType.Join),:);
76 self.sn.phaseshift = [zeros(size(phases,1),1),cumsum(self.sn.phasessz,2)];
80function result = isMAP(proc)
81% ISMAP Check
if a process representation
is a valid MAP {D0, D1}
83% A valid MAP has exactly 2 cell elements, both of which are square matrices
86if ~iscell(proc) || length(proc) ~= 2
91if ~isnumeric(D0) || ~isnumeric(D1)
94if ~ismatrix(D0) || ~ismatrix(D1)
99if m0 ~= n0 || m1 ~= n1 || m0 ~= m1
105function MAP = convertToMAP(station, classIdx, proc)
106% CONVERTTOMAP Convert non-Markovian distribution parameters to MAP
108% For non-Markovian distributions, the process representation contains
109% distribution parameters rather than {D0, D1} matrices. This function
110% converts them to an Erlang approximation.
112% Get the distribution
object from the station
113if isa(station,
'Source')
114 dist = station.input.sourceClasses{classIdx}{end};
116 dist = station.server.serviceProcess{classIdx}{end};
119% Get mean
for Erlang approximation
120targetMean = dist.getMean();
122% Determine number of phases based on SCV
123% For Det (SCV=0), use high number of phases;
for others, match SCV
125if scv < GlobalConstants.CoarseTol
126 % Deterministic or near-deterministic: use 20 phases
129 % Match SCV:
for Erlang, SCV = 1/n, so n = 1/SCV
130 nPhases = max(1, ceil(1/scv));
131 nPhases = min(nPhases, 100); % Cap at 100 phases
134% Create Erlang MAP approximation
135MAP = map_erlang(targetMean, nPhases);