1function ARV = solver_mam_traffic_fj(sn, DEP, config, fjSyncMap)
2% ARV = SOLVER_MAM_TRAFFIC_FJ(SN, DEP, CONFIG, FJSYNCMAP)
3% FJ-aware traffic solver extending solver_mam_traffic with mmap_max
4% synchronization at join points.
6% DEP{i,r}
is the departure process of
class r from i in (D0,D1) format
7% fjSyncMap
is built by sn_build_fj_sync_map
9% Copyright (c) 2012-2026, Imperial College London
15if ~isfield(config,
'fj_sync_q_len')
16 config.fj_sync_q_len = 2;
19% In this function we use indexing over all non-ClassSwitch
nodes
22nodeToNCS = zeros(1,I);
25 if sn.nodetype(ind) ~= NodeType.ClassSwitch
26 non_cs_classes(end+1:end+R)= ((ind-1)*R+1):(ind*R);
28 nodeToNCS(ind) = sum(isNCS);
29 NCStoNode(end+1) = ind;
35% Hide the
nodes that are class switches
36rtncs = dtmc_stochcomp(sn.rtnodes, non_cs_classes);
37Inc = I - sum(sn.nodetype == NodeType.ClassSwitch);
39% DEP
is indexed by node (ind, r) - convert to
MMAP format
43 MMAP{ind,r} = DEP{ind,r};
44 if isempty(
MMAP{ind,r}) || any(any(isnan(
MMAP{ind,r}{1})))
45 MMAP{ind,r} = {[0],[0],[0]}; % no arrivals from
this class
56% Build the nodeSync matrix in NCS indexing
57nodeSyncNCS = zeros(Inc, Inc);
64 if fjSyncMap.nodeSync(ind, jnd) > 0
65 nodeSyncNCS(inc, jnc) = fjSyncMap.nodeSync(ind, jnd);
72% First determine all outgoing flows from all
nodes
76 switch sn.nodetype(ind)
77 case {NodeType.Source, NodeType.Delay, NodeType.Queue, NodeType.Fork, NodeType.Join}
78 % obtain departure maps (
MMAP is now node-indexed)
80 DEP_NCS{inc} = mmap_super({
MMAP{ind,1:R}});
82 DEP_NCS{inc} =
MMAP{ind,1};
84 Psplit = zeros(R,Inc*R);
90 Psplit(r,(jnc-1)*R+s) = rtncs((inc-1)*R+r, (jnc-1)*R+s);
96 [Fsplit{1:Inc}] = npfqn_traffic_split_cs(DEP_NCS{inc}, Psplit, config);
98 LINKS{inc,jnc} = Fsplit{jnc};
99 LINKS{inc,jnc} = mmap_normalize(LINKS{inc,jnc});
105% Then determine all incoming flows, with FJ synchronization
107 if isNCS(ind) && sn.nodetype(ind) ~= NodeType.Source
108 inc = nodeToNCS(ind);
110 % Partition incoming links into sync groups and independent flows
111 syncGroupsAtNode = unique(nodeSyncNCS(inc, :));
112 syncGroupsAtNode = syncGroupsAtNode(syncGroupsAtNode > 0);
114 independentFlows = {};
115 syncFlows =
struct();
118 if isempty(LINKS{jnc,inc}) || sum(mmap_lambda(LINKS{jnc,inc})) <= GlobalConstants.FineTol
121 gid = nodeSyncNCS(inc, jnc);
124 independentFlows{end+1} = LINKS{jnc,inc};
126 % Synchronized flow — group by sync group ID
127 fname = [
'g' num2str(gid)];
128 if ~isfield(syncFlows, fname)
129 syncFlows.(fname) = {};
131 syncFlows.(fname){end+1} = LINKS{jnc,inc};
135 % Process
synchronized flows: apply mmap_max iteratively within each group
137 for g = 1:length(syncGroupsAtNode)
138 gid = syncGroupsAtNode(g);
139 fname = [
'g' num2str(gid)];
140 if ~isfield(syncFlows, fname)
143 groupFlows = syncFlows.(fname);
144 if isempty(groupFlows)
148 % Start with first flow, iteratively apply mmap_max with remaining
149 syncedFlow = groupFlows{1};
150 for f = 2:length(groupFlows)
151 syncedFlow = mmap_max(syncedFlow, groupFlows{f}, config.fj_sync_q_len);
153 % Compress after each mmap_max step
if state space
is too large
154 if length(syncedFlow{1}) > config.space_max
155 syncedFlow = mmap_compress(syncedFlow,
struct(
'method', config.compress));
158 syncResults{end+1} = syncedFlow;
161 % Merge synced flows with independent flows
162 allFlows = [syncResults, independentFlows];
164 if length(allFlows) > 1
165 ARV{ind} = npfqn_traffic_merge(allFlows, config);
166 elseif length(allFlows) == 1
167 ARV{ind} = allFlows{1};
169 % No flows — take a zero-rate link
171 if ~isempty(LINKS{jnc,inc})
172 ARV{ind} = LINKS{jnc,inc};
177 ARV{ind} = {[0],[0],[0]};