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 % Delayed hits (retrieval system) depart as the hit
66 % class, so the hit-class throughput is (true hit +
67 % delayed hit) * total arrival. Zero for plain caches.
68 if isfield(sn.nodeparam{ind}, 'actualdelayedhitprob') && ~isempty(sn.nodeparam{ind}.actualdelayedhitprob)
69 actualDelayedHitProb = sn.nodeparam{ind}.actualdelayedhitprob;
70 else
71 actualDelayedHitProb = zeros(size(actualHitProb));
72 end
73
74 % Accumulate the flows of ALL read classes that
75 % share this hit/miss class, each weighted by its
76 % own arrival throughput TN(refstat,origClass);
77 % assigning totalTput*prob per read class would
78 % overwrite the row (last read class wins) and use
79 % the chain total instead of the class's own rate.
80 for origClass = 1:length(hitclass)
81 % Skip classes whose hit/miss probability is NaN:
82 % retrieval classes may declare the same miss class
83 % as the read class but carry no probability, and
84 % would otherwise overwrite the read-class miss
85 % throughput with NaN (dropping the miss-rate row).
86 % actualHitProb/actualMissProb are indexed by
87 % the originating (read) class; only read classes
88 % carry a value, so they may be shorter than
89 % hitclass (e.g. when results come back from the
90 % JAR backend). Guard the index access.
91 % Arrival rate of the read class INTO the cache
92 % (robust to upstream class switching, where the
93 % read class has no throughput at the reference
94 % station).
95 if ~isempty(ANn)
96 arvTput = ANn(ind, origClass);
97 elseif any(origClass == inchain)
98 arvTput = TN(refstat, origClass);
99 else
100 arvTput = 0; % read class outside this chain
101 end
102 if hitclass(origClass) == r && origClass <= length(actualHitProb) && ~isnan(actualHitProb(origClass))
103 % This is a hit class - use hit probability
104 % (true hits plus delayed hits)
105 dh = 0;
106 if origClass <= length(actualDelayedHitProb) && ~isnan(actualDelayedHitProb(origClass))
107 dh = actualDelayedHitProb(origClass);
108 end
109 TNn(ind, r) = TNn(ind, r) + arvTput * (actualHitProb(origClass) + dh);
110 elseif missclass(origClass) == r && origClass <= length(actualMissProb) && ~isnan(actualMissProb(origClass))
111 % This is a miss class - use miss probability
112 TNn(ind, r) = TNn(ind, r) + arvTput * actualMissProb(origClass);
113 end
114 end
115 else
116 % Fallback to nodevisits-based calculation
117 if any(find(r==hitclass)) || any(find(r==missclass))
118 TNn(ind, r) = (sn.nodevisits{c}(ind,r) / sum(sn.visits{c}(sn.stationToStateful(refstat),inchain))) * totalTput;
119 end
120 end
121 end
122 end
123 end
124 end
125 end
126
127 % First, copy station throughputs directly to station nodes
128 M = sn.nstations;
129 for ist=1:M
130 ind = sn.stationToNode(ist);
131 TNn(ind,:) = TN(ist,:);
132 end
133
134 for ind=1:I
135 for c = 1:C
136 inchain = sn.inchain{c};
137 for r = inchain
138 anystateful = find(sn.visits{c}(:,r));
139 if ~isempty(anystateful)
140 if sn.nodetype(ind) ~= NodeType.Sink && sn.nodetype(ind) ~= NodeType.Join
141 for s = inchain
142 for jnd=1:I
143 switch sn.nodetype(ind)
144 case NodeType.Source
145 ist = sn.nodeToStation(ind);
146 TNn(ind, s) = TN(ist,s);
147 case NodeType.Cache
148 if ind~=jnd
149 TNn(ind, s) = TNn(ind, s) + ANn(ind, r) * sn.rtnodes((ind-1)*R+r, (jnd-1)*R+s);
150 end
151 otherwise
152 % For station nodes, throughput is already set from TN
153 % Only compute for non-station nodes (like ClassSwitch, Router)
154 % Note: nodeToStation returns NaN for non-station nodes, so use ~(>0) check
155 if ~(sn.nodeToStation(ind) > 0)
156 TNn(ind, s) = TNn(ind, s) + ANn(ind, r) * sn.rtnodes((ind-1)*R+r, (jnd-1)*R+s);
157 end
158 end
159 end
160 end
161 elseif sn.nodetype(ind) == NodeType.Join
162 for s = inchain
163 for jnd=1:I
164 if sn.nodetype(ind) ~= NodeType.Source
165 TNn(ind, s) = TNn(ind, s) + ANn(ind, r) * sn.rtnodes((ind-1)*R+r, (jnd-1)*R+s);
166 else
167 ist = sn.nodeToStation(ind);
168 TNn(ind, s) = TN(ist,s);
169 end
170 end
171 end
172 end
173 end
174 end
175 end
176 end
177 TNn(isnan(TNn)) = 0;
178else
179 TNn = [];
180end
181
182end
Definition fjtag.m:157
Definition Station.m:245