LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_mam_traffic_mmap.m
1function ARV = solver_mam_traffic_mmap(sn, DEP, config, fjSyncMap)
2% ARV = SOLVER_MAM_TRAFFIC_MMAP(SN, DEP, CONFIG, FJSYNCMAP)
3% FJ-aware traffic solver extending solver_mam_traffic with mmap_max
4% synchronization at join points.
5%
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
8%
9% Copyright (c) 2012-2026, Imperial College London
10% All rights reserved.
11
12I = sn.nnodes;
13R = sn.nclasses;
14
15if ~isfield(config, 'fj_sync_q_len')
16 config.fj_sync_q_len = 2;
17end
18
19% In this function we use indexing over all non-ClassSwitch nodes
20non_cs_classes = [];
21isNCS = zeros(1,I);
22nodeToNCS = zeros(1,I);
23NCStoNode = [];
24for ind=1:I
25 if sn.nodetype(ind) ~= NodeType.ClassSwitch
26 non_cs_classes(end+1:end+R)= ((ind-1)*R+1):(ind*R);
27 isNCS(ind) = true;
28 nodeToNCS(ind) = sum(isNCS);
29 NCStoNode(end+1) = ind;
30 else
31 isNCS(ind) = false;
32 end
33end
34
35% Hide the nodes that are class switches
36rtncs = dtmc_stochcomp(sn.rtnodes, non_cs_classes);
37Inc = I - sum(sn.nodetype == NodeType.ClassSwitch);
38
39% DEP is indexed by node (ind, r) - convert to MMAP format
40MMAP = cell(I, R);
41for ind=1:I
42 for r=1:R
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
46 else
47 MMAP{ind,r}{3} = MMAP{ind,r}{2};
48 end
49 end
50end
51
52ARV = cell(Inc,1);
53DEP_NCS = cell(Inc,R);
54LINKS = cell(Inc,Inc);
55
56% Build the nodeSync matrix in NCS indexing
57nodeSyncNCS = zeros(Inc, Inc);
58for ind=1:I
59 if isNCS(ind)
60 inc = nodeToNCS(ind);
61 for jnd=1:I
62 if isNCS(jnd)
63 jnc = nodeToNCS(jnd);
64 if fjSyncMap.nodeSync(ind, jnd) > 0
65 nodeSyncNCS(inc, jnc) = fjSyncMap.nodeSync(ind, jnd);
66 end
67 end
68 end
69 end
70end
71
72% First determine all outgoing flows from all nodes
73for ind=1:I
74 if isNCS(ind)
75 inc = nodeToNCS(ind);
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)
79 if R>1
80 % Order-preserving bounded class-by-class superposition;
81 % see _kb/06-solver-catalog.md for rationale
82 DEP_NCS{inc} = MMAP{ind,1};
83 for rr=2:R
84 DEP_NCS{inc} = mmap_super(DEP_NCS{inc}, MMAP{ind,rr});
85 if length(DEP_NCS{inc}{1}) > config.space_max
86 DEP_NCS{inc} = mmap_compress(DEP_NCS{inc}, config);
87 end
88 end
89 else
90 DEP_NCS{inc} = MMAP{ind,1};
91 end
92 Psplit = zeros(R,Inc*R);
93 for r=1:R
94 for jnd = 1:I
95 if isNCS(jnd)
96 jnc = nodeToNCS(jnd);
97 for s=1:R
98 Psplit(r,(jnc-1)*R+s) = rtncs((inc-1)*R+r, (jnc-1)*R+s);
99 end
100 end
101 end
102 end
103
104 [Fsplit{1:Inc}] = npfqn_traffic_split_cs(DEP_NCS{inc}, Psplit, config);
105 for jnc=1:Inc
106 LINKS{inc,jnc} = Fsplit{jnc};
107 LINKS{inc,jnc} = mmap_normalize(LINKS{inc,jnc});
108 end
109 end
110 end
111end
112
113% Then determine all incoming flows, with FJ synchronization
114for ind=1:I
115 if isNCS(ind) && sn.nodetype(ind) ~= NodeType.Source
116 inc = nodeToNCS(ind);
117
118 % Partition incoming links into sync groups and independent flows
119 syncGroupsAtNode = unique(nodeSyncNCS(inc, :));
120 syncGroupsAtNode = syncGroupsAtNode(syncGroupsAtNode > 0);
121
122 independentFlows = {};
123 syncFlows = struct();
124
125 for jnc=1:Inc
126 if isempty(LINKS{jnc,inc}) || sum(mmap_lambda(LINKS{jnc,inc})) <= GlobalConstants.FineTol
127 continue;
128 end
129 gid = nodeSyncNCS(inc, jnc);
130 if gid == 0
131 % Independent flow
132 independentFlows{end+1} = LINKS{jnc,inc};
133 else
134 % Synchronized flow — group by sync group ID
135 fname = ['g' num2str(gid)];
136 if ~isfield(syncFlows, fname)
137 syncFlows.(fname) = {};
138 end
139 syncFlows.(fname){end+1} = LINKS{jnc,inc};
140 end
141 end
142
143 % Process synchronized flows: apply mmap_max iteratively within each group
144 syncResults = {};
145 for g = 1:length(syncGroupsAtNode)
146 gid = syncGroupsAtNode(g);
147 fname = ['g' num2str(gid)];
148 if ~isfield(syncFlows, fname)
149 continue;
150 end
151 groupFlows = syncFlows.(fname);
152 if isempty(groupFlows)
153 continue;
154 end
155
156 % Start with first flow, iteratively apply mmap_max with remaining
157 syncedFlow = groupFlows{1};
158 for f = 2:length(groupFlows)
159 syncedFlow = mmap_max(syncedFlow, groupFlows{f}, config.fj_sync_q_len);
160 % Normalize mmap_max output before use; see _kb/06-solver-catalog.md for rationale
161 syncedFlow = mmap_normalize(syncedFlow);
162
163 % Compress after each mmap_max step if state space is too large
164 if length(syncedFlow{1}) > config.space_max
165 syncedFlow = mmap_compress(syncedFlow, struct('method', config.compress));
166 end
167 end
168 syncResults{end+1} = syncedFlow;
169 end
170
171 % Merge synced flows with independent flows
172 allFlows = [syncResults, independentFlows];
173
174 if length(allFlows) > 1
175 ARV{ind} = npfqn_traffic_merge(allFlows, config);
176 elseif length(allFlows) == 1
177 ARV{ind} = allFlows{1};
178 else
179 % No flows — take a zero-rate link
180 for jnc=1:Inc
181 if ~isempty(LINKS{jnc,inc})
182 ARV{ind} = LINKS{jnc,inc};
183 break;
184 end
185 end
186 if isempty(ARV{ind})
187 ARV{ind} = {[0],[0],[0]};
188 end
189 end
190 else
191 ARV{ind} = [];
192 end
193end
194end
Definition fjtag.m:161