Skip to content

Commit 2f5c6ab

Browse files
authored
Merge pull request #2387 from farid-zare/extremePools
Update extremePools.m
2 parents a6af2d8 + f883bab commit 2f5c6ab

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/analysis/topology/extremeRays/lrs/extremePools.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@
5959
end
6060

6161
try
62-
[rankA, p, q] = getRankLUSOL(N, 1);
63-
N=N(:,q(1:rankA));
62+
% [rankA, p, q] = getRankLUSOL(N, 1);
63+
% N=N(:,q(1:rankA));
64+
[rankN, rowPerm, colPerm] = getRankLUSOL(N, 1);
65+
N = N(rowPerm(1:rankN), :); % <-- Removing only rows instead of columns
6466
disp('extremePools: row reduction with getRankLUSOL worked.')
6567
catch
6668
disp('extremePools: row reduction with getRankLUSOL did not work, check installation of LUSOL. Proceeding without it.')
@@ -160,13 +162,16 @@
160162
modelName = 'model';
161163
end
162164

163-
b = zeros(size(N, 2),1);
164-
165-
csense(1:size(N, 2),1)='E';
165+
% Set up the zero right-hand side for N*x = 0 (all constraints are equalities)
166+
b = zeros(size(N, 1),1);
167+
csense(1:size(N, 1),1)='E';
166168

167169
% Output a file for lrs to convert an H-representation (half-space) of a
168170
% polyhedron to a V-representation (vertex / ray) via vertex enumeration
169-
fileNameOut = lrsWriteHalfspace(N', b, csense, modelName, param);
171+
% Write the half-space (H-representation) to file for LRS
172+
% Here, N is an (n x m) matrix representing the transposed stoichiometry (S^T).
173+
% The LRS tool will enumerate all nonnegative solutions x s.t. N*x = 0.
174+
fileNameOut = lrsWriteHalfspace(N, b, csense, modelName, param);
170175

171176
%run lrs
172177
param.facetEnumeration = 0;%vertex enumeration
@@ -179,7 +184,9 @@
179184
V = Q(:,vertexBool);
180185
P = Q(:,~vertexBool)';%extreme rays
181186

182-
if any(any(P*N ~= 0))
187+
% After LRS enumeration, we check that each extreme pool vector P indeed satisfies P*N' = 0,
188+
% ensuring it lies in the left null space of the original stoichiometric matrix (S).
189+
if any(any(P*N' ~= 0))
183190
warning('extreme pool not in left nullspace of stoichiometric matrix')
184191
end
185192
end
@@ -191,5 +198,3 @@
191198
delete('*.sh');
192199
delete('*.time');
193200
end
194-
195-

0 commit comments

Comments
 (0)