LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
fes_build_isolated.m
1%{ @file fes_build_isolated.m
2 % @brief Builds isolated subnetwork data from a station subset for FES computation
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Builds isolated subnetwork data from a station subset
9 %
10 % @details
11 % Extracts the data needed to analyze an isolated subnetwork containing
12 % only the specified stations. This data is used with pfqn_mva to compute
13 % throughputs for the Flow-Equivalent Server (FES) service rates.
14 %
15 % @par Syntax:
16 % @code
17 % [L, mi, visits, isDelay] = fes_build_isolated(sn, subsetIndices, stochCompS)
18 % @endcode
19 %
20 % @par Parameters:
21 % <table>
22 % <tr><th>Name<th>Description
23 % <tr><td>sn<td>Network structure (from model.getStruct())
24 % <tr><td>subsetIndices<td>Array of station indices to include (1-based)
25 % <tr><td>stochCompS<td>Stochastic complement routing matrix for subset (K*M_sub x K*M_sub)
26 % </table>
27 %
28 % @par Returns:
29 % <table>
30 % <tr><th>Name<th>Description
31 % <tr><td>L<td>Service demands matrix (M_sub x K), L(i,k) = visits(i,k) / rate(i,k)
32 % <tr><td>mi<td>Number of servers per station (1 x M_sub), Inf for Delay nodes
33 % <tr><td>visits<td>Visit ratios matrix (M_sub x K) from stochastic complement
34 % <tr><td>isDelay<td>Boolean array (1 x M_sub), true if station is a Delay node
35 % </table>
36%}
37function [L, mi, visits, isDelay] = fes_build_isolated(sn, subsetIndices, stochCompS)
38
39K = sn.nclasses;
40M_sub = length(subsetIndices);
41
42% Initialize outputs
43L = zeros(M_sub, K); % Service demands
44mi = zeros(1, M_sub); % Number of servers
45isDelay = false(1, M_sub); % Delay node flags
46
47% Extract station properties from sn
48for i = 1:M_sub
49 origIdx = subsetIndices(i);
50 nodeIdx = sn.stationToNode(origIdx);
51 nodeType = sn.nodetype(nodeIdx);
52
53 % Check if this is a Delay node
54 if nodeType == NodeType.Delay
55 isDelay(i) = true;
56 mi(i) = Inf; % Infinite servers for Delay
57 else
58 isDelay(i) = false;
59 % Get number of servers from nservers field
60 mi(i) = sn.nservers(origIdx);
61 if isnan(mi(i)) || mi(i) < 1
62 mi(i) = 1;
63 end
64 end
65end
66
67% Compute visit ratios from stochastic complement routing matrix
68% stochCompS is indexed by (station-1)*K + class
69% Solve pi * S = pi for stationary distribution (by class)
70visits = zeros(M_sub, K);
71
72for k = 1:K
73 % Extract routing sub-matrix for class k within subset
74 % The stochCompS is organized as blocks: station i, class k -> station j, class k
75 P_k = zeros(M_sub, M_sub);
76
77 for i = 1:M_sub
78 rowIdx = (i-1)*K + k;
79 for j = 1:M_sub
80 colIdx = (j-1)*K + k;
81 if rowIdx <= size(stochCompS, 1) && colIdx <= size(stochCompS, 2)
82 P_k(i, j) = stochCompS(rowIdx, colIdx);
83 end
84 end
85 end
86
87 % Normalize rows if needed
88 for i = 1:M_sub
89 rowSum = sum(P_k(i, :));
90 if rowSum > GlobalConstants.FineTol && abs(rowSum - 1) > GlobalConstants.FineTol
91 P_k(i, :) = P_k(i, :) / rowSum;
92 elseif rowSum < GlobalConstants.FineTol
93 % If no routing defined, route to self
94 P_k(i, i) = 1.0;
95 end
96 end
97
98 % Compute visit ratios by solving pi * P = pi
99 % This is the stationary distribution of the embedded DTMC
100 % Use (I - P' + e*e'/M)' * pi' = e'/M where e is ones vector
101 I = eye(M_sub);
102 e = ones(M_sub, 1);
103
104 % Solve for stationary distribution
105 A = I - P_k' + (e * e') / M_sub;
106
107 if rank(A) == M_sub
108 pi_k = (A' \ (e / M_sub))';
109 else
110 % If singular, use uniform distribution
111 pi_k = ones(1, M_sub) / M_sub;
112 end
113
114 % Ensure non-negative and normalize
115 pi_k = max(pi_k, 0);
116 if sum(pi_k) > 0
117 pi_k = pi_k / sum(pi_k);
118 else
119 pi_k = ones(1, M_sub) / M_sub;
120 end
121
122 visits(:, k) = pi_k(:);
123end
124
125% Compute service demands: L(i,k) = visits(i,k) * service_time(i,k)
126for i = 1:M_sub
127 origIdx = subsetIndices(i);
128
129 for k = 1:K
130 % Get service rate from sn
131 rate = sn.rates(origIdx, k);
132
133 if isnan(rate) || rate <= 0 || isinf(rate)
134 % Disabled or invalid service
135 L(i, k) = 0;
136 else
137 % Service demand = visits * service time
138 % For MVA, we normalize visits relative to first station
139 serviceTime = 1 / rate;
140 L(i, k) = visits(i, k) * serviceTime;
141 end
142 end
143end
144
145% Normalize demands so that total visit to first station is 1
146% This is the standard MVA convention
147for k = 1:K
148 if visits(1, k) > 0
149 L(:, k) = L(:, k) / visits(1, k);
150 end
151end
152
153end
Definition mmt.m:92