56 lines
No EOL
2 KiB
Matlab
56 lines
No EOL
2 KiB
Matlab
function [A_aug,h,c_aug] = standardize(type,A,h,c,m,sign)
|
|
% Input arguments:
|
|
% type = 'max' for maximization, 'min' for minimization
|
|
% A = matrix holding the constraints coefficients
|
|
% h = coefficients of the constraints inequalities (rhs vector)
|
|
% c = coefficients of the objective function
|
|
% m = size(A, 1)
|
|
% sign = vector holding information about the constraints if the system
|
|
% needs to be standardized (-1: less or equal, 0: equal, 1:vgreater or equal)
|
|
% return arguments are:
|
|
% (1) A_aug = augmented matrix A, containing also the surplus and slack variables
|
|
% (2) c_aug = augmented coefficients vector c (check compatibility of dimensions with A)
|
|
% (3) h, right hand side vector (remember to flip the signs when changing the inequalities)
|
|
|
|
aug_matrix = eye(m); % matrix corresponding to the slack/surplus variables
|
|
|
|
if strcmp(type, 'max')
|
|
for i = 1:m
|
|
if sign(i) == 1
|
|
% Using a surplus instead of a slack variable
|
|
aug_matrix(i,:) = -aug_matrix(i,:);
|
|
end
|
|
end
|
|
elseif strcmp(type, 'min')
|
|
for i = 1:m
|
|
if sign(i) == -1
|
|
% Using a slack instead of a surplus variable
|
|
aug_matrix(i,:) = -aug_matrix(i,:);
|
|
end
|
|
end
|
|
else
|
|
error('Incorrect type specified. Choose either a maximisation (max) or minimisation (min) problem.')
|
|
end
|
|
|
|
% Correction on the sign of h for auxiliary problem (we want to
|
|
% ensure that h>=0, but we need to flip all the signs)
|
|
for i = 1:m
|
|
if h(i) < 0
|
|
A(i,:) = -A(i,:);
|
|
h(i,:) = -h(i,:);
|
|
aug_matrix(i,:) = -aug_matrix(i,:);
|
|
end
|
|
end
|
|
|
|
c_aug = [c, zeros(1,m)];
|
|
if strcmp(type,'max')
|
|
% Extend matrix A by adding the slack variables
|
|
A_aug = [A (+1 * full(aug_matrix == +1))];
|
|
elseif strcmp(type,'min')
|
|
% Extend matrix A by adding the surplus variables
|
|
A_aug = [A (-1 * full(aug_matrix == -1))];
|
|
else
|
|
error('Incorrect type specified. Choose either a maximisation (max) or minimisation (min) problem.')
|
|
end
|
|
|
|
end |