Skip to content

Commit a75e1af

Browse files
Merge pull request #1125 from CombustionToolbox/update/improve_simplex_methods
Update: improve performance `simplexDual`
2 parents ab9f5ea + 04a87ee commit a75e1af

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

+combustiontoolbox/+utils/+optimization/simplexDual.m

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,32 @@
99
% b (float): Right-hand side vector of the equality constraints
1010
%
1111
% Returns:
12-
% x (float): Optimal solution vector
13-
% x_min (float): Minimum value of x
12+
% Tuple containing
13+
%
14+
% * x (float): Optimal solution vector
15+
% * x_min (float): Minimum value of x
1416
%
1517
% Example:
1618
% [x, x_min] = simplexDual(A, b)
1719

1820
% Definitions
19-
[m, n] = size(A);
20-
21+
[~, n] = size(A);
22+
b = b(:);
23+
sumA = sum(A, 2);
24+
2125
% Coefficients for the objective function max t -> min -t
22-
c = [zeros(n, 1); -1];
23-
24-
% Set inequality constraints (x_j - t >= 0)
25-
A_ineq = [-eye(n), ones(n, 1)];
26-
b_ineq = zeros(n, 1);
27-
28-
% Set equality constraints (A * x = b)
29-
A_eq = [A, zeros(m, 1)];
30-
b_eq = b;
31-
26+
c = zeros(n + 1, 1);
27+
c(end) = -1;
28+
29+
% Set equality constraints (A * z + sum(A, 2) * t = b)
30+
A_eq = [A, sumA];
31+
3232
% Solve the linear programming problem using the simplex method
33-
x = combustiontoolbox.utils.optimization.simplex([A_ineq; A_eq], [b_ineq; b_eq], c);
33+
zt = combustiontoolbox.utils.optimization.simplex(A_eq, b, c);
3434

35-
% Remove t
36-
x_min = x(end);
37-
x(end) = [];
35+
% Recover minimum value
36+
x_min = max(zt(end), 0);
3837

39-
% Check
40-
% [x, x_min] = combustiontoolbox.utils.optimization.simplexDualCheck(A_eq, b_eq, c, A_ineq, b_ineq);
41-
end
38+
% Recover solution (x = z + t)
39+
x = zt(1:n) + x_min;
40+
end

0 commit comments

Comments
 (0)