LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_unique.m
1%{
2%{
3 % @file pfqn_unique.m
4 % @brief Consolidate replicated stations into unique stations with multiplicity.
5%}
6%}
7
8%{
9%{
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.
20%}
21%}
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
24%
25% [L_UNIQUE, MU_UNIQUE, GAMMA_UNIQUE, MI, MAPPING] = PFQN_UNIQUE(L, MU, GAMMA)
26%
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.
30%
31% Input:
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)
35%
36% Output:
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
42
43[M, R] = size(L);
44tol = GlobalConstants.Zero();
45if isempty(tol)
46 tol = 1e-14; % Default value matching ZERO_THRESHOLD in lineStart.m
47end
48
49% Handle empty optional parameters
50if nargin < 2
51 mu = [];
52end
53if nargin < 3
54 gamma = [];
55end
56
57% Build fingerprint matrix for comparison
58fingerprint = L;
59if ~isempty(mu)
60 fingerprint = [fingerprint, mu];
61end
62if ~isempty(gamma)
63 fingerprint = [fingerprint, gamma];
64end
65
66% Find unique rows using tolerance-based comparison
67mapping = zeros(1, M);
68unique_idx = []; % indices of unique stations
69mi_list = []; % multiplicities
70
71for i = 1:M
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;
77 count = 1;
78
79 % Find all stations identical to this one
80 for j = (i+1):M
81 if mapping(j) == 0 % not yet assigned
82 if norm(fingerprint(i,:) - fingerprint(j,:), inf) < tol
83 mapping(j) = group_idx;
84 count = count + 1;
85 end
86 end
87 end
88 mi_list(end+1) = count; %#ok<AGROW>
89 end
90end
91
92% Extract unique rows
93mi = mi_list;
94L_unique = L(unique_idx, :);
95if ~isempty(mu)
96 mu_unique = mu(unique_idx, :);
97else
98 mu_unique = [];
99end
100if ~isempty(gamma)
101 gamma_unique = gamma(unique_idx, :);
102else
103 gamma_unique = [];
104end
105end