4 % @brief Consolidate replicated stations into unique stations with multiplicity.
10 % @brief Consolidate replicated stations into unique stations with multiplicity.
11 % @fn pfqn_unique(L, mu, gamma)
12 % @param L Service demand matrix (M x R).
13 % @param mu Load-dependent rate matrix (M x Ntot), optional.
14 % @param gamma Class-dependent service rate matrix (M x R), optional.
15 % @
return L_unique Reduced demand matrix (M
' x R) with M' <= M unique stations.
16 % @
return mu_unique Reduced load-dependent rates (M
' x Ntot), empty if mu was empty.
17 % @return gamma_unique Reduced class-dependent rates (M' x R), empty
if gamma was empty.
18 % @
return mi Multiplicity vector (1 x M
'), mi(j) = count of stations mapping to unique station j.
19 % @return mapping Mapping vector (1 x M), mapping(i) = unique station index for original station i.
22function [L_unique, mu_unique, gamma_unique, mi, mapping] = pfqn_unique(L, mu, gamma)
23% PFQN_UNIQUE Consolidate replicated stations into unique stations with multiplicity
25% [L_UNIQUE, MU_UNIQUE, GAMMA_UNIQUE, MI, MAPPING] = PFQN_UNIQUE(L, MU, GAMMA)
27% Identifies stations with identical demand rows L(i,:) and (if present)
28% identical load-dependent rates mu(i,:) or class-dependent rates gamma(i,:).
29% Returns reduced matrices with only unique stations plus a multiplicity vector.
32% L - M x R demand matrix
33% mu - M x Ntot load-dependent rate matrix (optional, pass [] if not used)
34% gamma - M x R class-dependent service rate matrix (optional, pass [] if not used)
37% L_unique - M' x R demand matrix with M
' <= M unique stations
38% mu_unique - M' x Ntot reduced load-dependent rates (empty
if mu was empty)
39% gamma_unique - M
' x R reduced class-dependent rates (empty if gamma was empty)
40% mi - 1 x M' multiplicity vector
41% mapping - 1 x M vector mapping original station i to unique station index
44tol = GlobalConstants.Zero();
46 tol = 1e-14; % Default value matching ZERO_THRESHOLD in lineStart.m
49% Handle empty optional parameters
57% Build fingerprint matrix
for comparison
60 fingerprint = [fingerprint, mu];
63 fingerprint = [fingerprint, gamma];
66% Find unique rows
using tolerance-based comparison
68unique_idx = []; % indices of unique stations
69mi_list = []; % multiplicities
72 if mapping(i) == 0 % not yet assigned
73 % This
is a
new unique station
74 unique_idx(end+1) = i; %#ok<AGROW>
75 group_idx = length(unique_idx);
76 mapping(i) = group_idx;
79 % Find all stations identical to
this one
81 if mapping(j) == 0 % not yet assigned
82 if norm(fingerprint(i,:) - fingerprint(j,:), inf) < tol
83 mapping(j) = group_idx;
88 mi_list(end+1) = count; %#ok<AGROW>
94L_unique = L(unique_idx, :);
96 mu_unique = mu(unique_idx, :);
101 gamma_unique = gamma(unique_idx, :);