LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sn_get_node_tput_from_tput.m
1%{ @file sn_get_node_tput_from_tput.m
2 % @brief Computes average throughputs at nodes from station throughputs
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Computes average throughputs at nodes from station throughputs
9 %
10 % @details
11 % This function calculates the average throughput at each node in steady-state
12 % from the station throughputs and node-level routing matrix.
13 %
14 % @par Syntax:
15 % @code
16 % TNn = sn_get_node_tput_from_tput(sn, TN, TH)
17 % TNn = sn_get_node_tput_from_tput(sn, TN, TH, ANn)
18 % @endcode
19 %
20 % @par Parameters:
21 % <table>
22 % <tr><th>Name<th>Description
23 % <tr><td>sn<td>Network structure
24 % <tr><td>TN<td>Average throughputs at stations
25 % <tr><td>TH<td>Throughput handles
26 % <tr><td>ANn<td>(Optional) Average arrival rates at nodes; computed if missing
27 % </table>
28 %
29 % @par Returns:
30 % <table>
31 % <tr><th>Name<th>Description
32 % <tr><td>TNn<td>Average throughputs at nodes
33 % </table>
34%}
35function TNn=sn_get_node_tput_from_tput(sn, TN, TH, ANn)
36
37I = sn.nnodes;
38C = sn.nchains;
39R = sn.nclasses;
40if nargin<4
41 ANn = sn_get_node_arvr_from_tput(sn, TN, TH);
42end
43
44TNn = zeros(I,R);
45if ~isempty(TH) && ~isempty(TN)
46 for ind=1:I
47 for c = 1:C
48 inchain = sn.inchain{c};
49 refstat = sn.refstat(c);
50 for r = inchain
51 if sn.nodetype(ind) ~= NodeType.Source
52 switch sn.nodetype(ind)
53 case NodeType.Cache
54 % For cache nodes, use actual hit/miss ratios if available
55 % instead of nodevisits which don't account for cache behavior
56 hitclass = sn.nodeparam{ind}.hitclass;
57 missclass = sn.nodeparam{ind}.missclass;
58 totalTput = sum(TN(refstat,inchain));
59
60 % Check if actual hit/miss probabilities are available in nodeparam
61 if isfield(sn.nodeparam{ind}, 'actualhitprob') && ~isempty(sn.nodeparam{ind}.actualhitprob)
62 % Use actual hit/miss probabilities from solver result
63 actualHitProb = sn.nodeparam{ind}.actualhitprob;
64 actualMissProb = sn.nodeparam{ind}.actualmissprob;
65
66 % Find which original class this hit/miss class belongs to
67 for origClass = 1:length(hitclass)
68 if hitclass(origClass) == r
69 % This is a hit class - use hit probability
70 TNn(ind, r) = totalTput * actualHitProb(origClass);
71 elseif missclass(origClass) == r
72 % This is a miss class - use miss probability
73 TNn(ind, r) = totalTput * actualMissProb(origClass);
74 end
75 end
76 else
77 % Fallback to nodevisits-based calculation
78 if any(find(r==hitclass)) || any(find(r==missclass))
79 TNn(ind, r) = (sn.nodevisits{c}(ind,r) / sum(sn.visits{c}(sn.stationToStateful(refstat),inchain))) * totalTput;
80 end
81 end
82 end
83 end
84 end
85 end
86 end
87
88 % First, copy station throughputs directly to station nodes
89 M = sn.nstations;
90 for ist=1:M
91 ind = sn.stationToNode(ist);
92 TNn(ind,:) = TN(ist,:);
93 end
94
95 for ind=1:I
96 for c = 1:C
97 inchain = sn.inchain{c};
98 for r = inchain
99 anystateful = find(sn.visits{c}(:,r));
100 if ~isempty(anystateful)
101 if sn.nodetype(ind) ~= NodeType.Sink && sn.nodetype(ind) ~= NodeType.Join
102 for s = inchain
103 for jnd=1:I
104 switch sn.nodetype(ind)
105 case NodeType.Source
106 ist = sn.nodeToStation(ind);
107 TNn(ind, s) = TN(ist,s);
108 case NodeType.Cache
109 if ind~=jnd
110 TNn(ind, s) = TNn(ind, s) + ANn(ind, r) * sn.rtnodes((ind-1)*R+r, (jnd-1)*R+s);
111 end
112 otherwise
113 % For station nodes, throughput is already set from TN
114 % Only compute for non-station nodes (like ClassSwitch, Router)
115 % Note: nodeToStation returns NaN for non-station nodes, so use ~(>0) check
116 if ~(sn.nodeToStation(ind) > 0)
117 TNn(ind, s) = TNn(ind, s) + ANn(ind, r) * sn.rtnodes((ind-1)*R+r, (jnd-1)*R+s);
118 end
119 end
120 end
121 end
122 elseif sn.nodetype(ind) == NodeType.Join
123 for s = inchain
124 for jnd=1:I
125 if sn.nodetype(ind) ~= NodeType.Source
126 TNn(ind, s) = TNn(ind, s) + ANn(ind, r) * sn.rtnodes((ind-1)*R+r, (jnd-1)*R+s);
127 else
128 ist = sn.nodeToStation(ind);
129 TNn(ind, s) = TN(ist,s);
130 end
131 end
132 end
133 end
134 end
135 end
136 end
137 end
138 TNn(isnan(TNn)) = 0;
139else
140 TNn = [];
141end
142
143end
Definition mmt.m:92