2 % @brief Prints comprehensive information about a NetworkStruct
object
4 % @author LINE Development Team
8 % @brief Prints comprehensive information about a NetworkStruct
object
11 % This function displays all fields, matrices, lists, and maps in a formatted
12 % manner useful
for debugging and inspection of network structures.
21 % <tr><th>Name<th>Description
22 % <tr><td>sn<td>Network structure to inspect
27% Suppress warnings about
struct on objects
28warning(
'off',
'MATLAB:structOnObject');
31fprintf(
'nstations: %d\n', sn.nstations);
32fprintf(
'nstateful: %d\n', sn.nstateful);
33fprintf(
'nnodes: %d\n', sn.nnodes);
34fprintf(
'nclasses: %d\n', sn.nclasses);
35fprintf(
'nclosedjobs: %d\n', sn.nclosedjobs);
36fprintf(
'nchains: %d\n', sn.nchains);
39printMatrix(
'refstat', sn.refstat);
40printMatrix(
'njobs', sn.njobs);
41printMatrix(
'nservers', sn.nservers);
42printMatrix(
'connmatrix', sn.connmatrix);
43printMatrix(
'scv', sn.scv);
44printMatrix(
'isstation', sn.isstation);
45printMatrix(
'isstateful', sn.isstateful);
46printMatrix(
'isstatedep', sn.isstatedep);
47printMatrix(
'nodeToStateful', sn.nodeToStateful);
48printMatrix(
'nodeToStation', sn.nodeToStation);
49printMatrix(
'stationToNode', sn.stationToNode);
50printMatrix(
'stationToStateful', sn.stationToStateful);
51printMatrix(
'statefulToStation', sn.statefulToStation);
52printMatrix(
'statefulToNode', sn.statefulToNode);
53printMatrix(
'rates', sn.rates);
54printMatrix(
'classprio', sn.classprio);
55printMatrix(
'phases', sn.phases);
56printMatrix(
'phasessz', sn.phasessz);
57printMatrix(
'phaseshift', sn.phaseshift);
58printMatrix(
'schedparam', sn.schedparam);
59printMatrix(
'chains', sn.chains);
60printMatrix(
'rt', sn.rt);
61printMatrix(
'nvars', sn.nvars);
62printMatrix(
'rtnodes', sn.rtnodes);
63printMatrix(
'csmask', sn.csmask);
64printMatrix(
'isslc', sn.isslc);
65printMatrix(
'cap', sn.cap);
66printMatrix(
'classcap', sn.classcap);
67printMatrix(
'refclass', sn.refclass);
68printMatrix(
'lldscaling', sn.lldscaling);
69printMatrix(
'fj', sn.fj);
71% List fields with content
72printNodeTypeList(
'nodetype', sn.nodetype);
73if isfield(sn,
'classnames')
74 if iscell(sn.classnames)
75 printList('classnames', sn.classnames);
77 % Handle single
string classname
78 fprintf('classnames: ["%s"]\n', sn.classnames);
81if isfield(sn, 'nodenames')
82 printList('nodenames', sn.nodenames);
85% Map fields with detailed contents
86printMapIfExists(sn, 'rtorig');
87%printMapIfExists(sn, 'lst');
88printMapIfExists(sn, 'state');
89printMapIfExists(sn, 'stateprior');
90printMapIfExists(sn, 'space');
91printMapIfExists(sn, 'routing');
92printMapIfExists(sn, 'procid');
93printMapIfExists(sn, 'mu');
94printMapIfExists(sn, 'phi');
95printMapIfExists(sn, 'proc');
96printMapIfExists(sn, 'pie');
97printMapIfExists(sn, 'sched');
98printMapIfExists(sn, 'inchain');
99printMapIfExists(sn, '
visits');
101printMapIfExists(sn, 'droprule');
102printMapIfExists(sn, 'nodeparam');
103% Special handling for sync field to avoid duplicate printing
104if isfield(sn, 'sync')
108 % sync
is a cell array of sync objects
110 for i = 1:length(value)
114 fprintf('%d:
', i-1); % 0-based index
117 if isstruct(syncObj) && isfield(syncObj, 'active
') && isfield(syncObj, 'passive
')
119 % Print active events with indices
120 fprintf('"active": {
');
121 if iscell(syncObj.active)
122 for j = 1:length(syncObj.active)
126 fprintf('%d:
', j-1); % 0-based index
127 printValue(syncObj.active{j});
131 printValue(syncObj.active);
135 % Print passive events with indices
136 fprintf(',
"passive": {
');
137 if iscell(syncObj.passive)
138 for j = 1:length(syncObj.passive)
142 fprintf('%d:
', j-1); % 0-based index
143 printValue(syncObj.passive{j});
147 printValue(syncObj.passive);
156 elseif isstruct(value)
157 % Check if it's a
map of sync objects
158 fields = fieldnames(value);
161 for i = 1:length(fields)
166 % Handle numeric keys like x0, x1
167 if regexp(key,
'^x\d+$')
168 fprintf('%s', key(2:end));
170 fprintf('"%s"', key);
174 syncObj = value.(key);
175 if isstruct(syncObj) && isfield(syncObj, 'active') && isfield(syncObj, 'passive')
177 % Print active events with indices
178 fprintf('"active": {
');
179 if iscell(syncObj.active)
180 for j = 1:length(syncObj.active)
184 fprintf('%d:
', j-1); % 0-based index
185 printValue(syncObj.active{j});
189 printValue(syncObj.active);
193 % Print passive events with indices
194 fprintf(',
"passive": {
');
195 if iscell(syncObj.passive)
196 for j = 1:length(syncObj.passive)
200 fprintf('%d:
', j-1); % 0-based index
201 printValue(syncObj.passive{j});
205 printValue(syncObj.passive);
222 % Field doesn't exist, skip
224printMapIfExists(sn,
'gsync');
225printMapIfExists(sn,
'cdscaling');
226printMapIfExists(sn,
'jdscaling');
229warning(
'on',
'MATLAB:structOnObject');
233function matStr = printMatrixCompact(matrix)
234% Helper function to print matrix in compact format
for maps
241[numRows, numCols] = size(matrix);
250 value = matrix(i, j);
251 % Check
if matrix contains only integers or
if individual value
is integer
252 if (isnumeric(matrix) && all(matrix(:) == floor(matrix(:))) && all(~isinf(matrix(:)))) || ...
253 (value == floor(value) && ~isinf(value))
254 sb = [sb num2str(round(value))];
256 sb = [sb num2str(value)];
264function printNodeTypeList(name, nodeTypes)
265% Helper function to print nodetype array with proper formatting
266fprintf(
'%s: ', name);
271 for i = 1:length(nodeTypes)
275 fprintf(
'%s', NodeType.toText(nodeTypes(i)));
281function printList(name, list)
282% Helper function to print lists with proper formatting
283fprintf(
'%s: ', name);
288 for i = 1:length(list)
292 if ischar(list{i}) || isstring(list{i})
293 fprintf(
'"%s"',
char(list{i}));
295 fprintf(
'%s', mat2str(list{i}));
299elseif isnumeric(list)
300 % Handle numeric arrays
301 fprintf(
'%s\n', printMatrixCompact(list));
304 fprintf(
'%s\n', mat2str(list));
308function printMatrix(name, matrix)
309% Helper function to print matrix with all values
311 fprintf(
'%s: []\n', name);
312elseif isnumeric(matrix) && all(isnan(matrix(:)))
313 fprintf(
'%s: null\n', name);
315 fprintf(
'%s: %s\n', name, printMatrixCompact(matrix));
319function printMapIfExists(sn, fieldName)
320% Helper function to print fields only
if they exist
321if isfield(sn, fieldName)
322 value = sn.(fieldName);
324 printMapContents(fieldName, value);
326 printCellContents(fieldName, value);
328 % For other types, use printMatrix
329 printMatrix(fieldName, value);
334function printCellContents(name, cellArray)
335% Helper function to print cell array contents
336fprintf(
'%s: ', name);
340 % Check
if this is a single-element cell array containing a matrix
341 if numel(cellArray) == 1 && isnumeric(cellArray{1})
342 % Just print the matrix directly without extra brackets
343 fprintf(
'%s\n', printMatrixCompact(cellArray{1}));
347 % Check
if this is a
map-like cell array
348 if numel(cellArray) > 0 && isstruct(cellArray{1})
350 printMapContents(name, cellArray{1});
354 % Special handling
for certain fields that are
map-like
355 if strcmp(name, 'state') || strcmp(name, 'stateprior') || strcmp(name, 'space') || ...
356 strcmp(name, 'mu') || strcmp(name, 'phi') || strcmp(name, 'pie')
357 % These fields use station names as keys
359 % Assume we have access to station names through evalin
361 nodenames = evalin('caller
', 'sn.nodenames
');
362 for i = 1:numel(cellArray)
366 if i <= length(nodenames)
367 fprintf('"%s":
', nodenames{i});
369 printValue(cellArray{i});
372 % Fall back to simple array printing
373 for i = 1:numel(cellArray)
377 printValue(cellArray{i});
382 % Regular cell array - use [] for arrays
384 for i = 1:numel(cellArray)
388 printValue(cellArray{i});
395function printMapContents(name, mapStruct)
396% Helper function to print map contents with detailed structure
397if isempty(mapStruct) || ~exist('mapStruct
', 'var
')
399 fprintf('%s: null\n
', name);
406if ~isstruct(mapStruct)
408 fprintf('%s: null\n
', name);
415fields = fieldnames(mapStruct);
418 fprintf('%s: {}\n
', name);
426 fprintf('%s: {
', name);
431for i = 1:length(fields)
437 % Print key - handle different key types like the Kotlin version
439 % Check if key is numeric (like x0, x1, etc.)
440 if regexp(key, '^x\d+$')
441 % Extract the numeric part
442 fprintf('%s', key(2:end));
444 fprintf(
'"%s"', key);
446 fprintf(
'"%s"',
char(
string(key)));
452 value = mapStruct.(key);
458function printValue(value)
459% Helper function to print individual values with appropriate formatting
462elseif isa(value,
'jline.lang.Event') || (isjava(value) && contains(
class(value),
'Event'))
463 % Handle Java Event objects
467 % Try to print each field
469 nodeVal = value.getNode();
470 fprintf(
'"node": %d', nodeVal);
477 eventVal = value.getEvent();
481 fprintf('"event":
');
483 fprintf('%d
', eventVal.getId());
485 fprintf('"%s"', char(eventVal.toString()));
493 classVal = value.getJobClass();
497 fprintf(
'"class": %d', classVal);
502 probVal = value.getProb();
510 fprintf(
'%g', probVal);
518 stateVal = value.getState();
522 fprintf(
'"state": ');
523 if isempty(stateVal) || (isa(stateVal,
'jline.util.matrix.Matrix') && stateVal.isEmpty())
526 printValue(stateVal);
550 jobVal = value.getJob();
558 fprintf(
'%g', jobVal);
565 % If nothing was printed, show it
's an Event
571elseif isstruct(value)
572 fields = fieldnames(value);
574 % Check if this might be a Java object that appears as empty struct
575 className = class(value);
576 if contains(className, 'Event
')
577 fprintf('{<Event
object - fields not accessible>}');
583 for i = 1:length(fields)
587 fprintf(
'"%s": ', fields{i});
588 printValue(value.(fields{i}));
592elseif isnumeric(value)
594 fprintf(
'%s', printMatrixCompact(value));
596 if value == floor(value) && ~isinf(value)
597 fprintf(
'%d', round(value));
599 fprintf(
'%g', value);
602elseif ischar(value) || isstring(value)
603 fprintf(
'"%s"',
char(value));
604elseif islogical(value)
611 % Check
if this is a nested cell array (like proc field)
612 if numel(value) > 0 && iscell(value{1})
613 % Handle nested cell array as indexed
map
615 for i = 1:numel(value)
619 fprintf(
'[%d]: ', i-1); % Use 0-based indexing for consistency with Java
620 printValue(value{i});
626 for i = 1:length(value)
630 printValue(value{i});
634elseif isa(value,
'function_handle')
635 % Display function handles similar to Java lambda notation
636 funcStr = func2str(value);
637 if contains(funcStr,
'@')
638 funcStr = strrep(funcStr, '@', '');
640 fprintf('%s', funcStr);
642 % Handle objects and other types
644 % Check if it's a Sync
object
645 if isa(value, 'Sync')
647 fprintf('"active":
');
648 printValue(value.active);
649 fprintf(',
"passive":
');
650 printValue(value.passive);
653 str = char(string(value));
654 % Check if this is a sync string that needs special handling
655 if contains(str, 'sync:
')
656 % This is likely the sync field being printed as a string
657 % Extract the content after "sync:"
658 syncContent = strtrim(extractAfter(str, 'sync:
'));
659 fprintf('%s
', syncContent);
660 elseif contains(str, 'x
') && contains(str, ' ')
661 % Clean up MATLAB object notation (e.g., 1x1 ClosedClass)
662 parts = split(str, ' ');
663 if length(parts) >= 2
664 fprintf('%s
', parts{end});
673 % If conversion fails, just display the class name
674 fprintf('<%s>
', class(value));