Skip to content

Commit d8da06f

Browse files
authored
Add files via upload
1 parent 2da1143 commit d8da06f

12 files changed

+1199
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
function [A, c, b, Eqin, infeasible] = ...
2+
eliminateDualSingletonInequalityConstraints(A, c, b, Eqin)
3+
% Filename: eliminateDualSingletonInequalityConstraints.m
4+
% Description: the function is an implementation of the
5+
% presolve technique that eliminates dual singleton
6+
% inequality constraints
7+
% Authors: Ploskas, N., & Samaras, N.
8+
%
9+
% Syntax: [A, c, b, Eqin, infeasible] = ...
10+
% eliminateDualSingletonInequalityConstraints(A, c, b, Eqin)
11+
%
12+
% Input:
13+
% -- A: matrix of coefficients of the constraints
14+
% (size m x n)
15+
% -- c: vector of coefficients of the objective function
16+
% (size n x 1)
17+
% -- b: vector of the right-hand side of the constraints
18+
% (size m x 1)
19+
% -- Eqin: vector of the type of the constraints
20+
% (size m x 1)
21+
%
22+
% Output:
23+
% -- A: presolved matrix of coefficients of the constraints
24+
% (size m x n)
25+
% -- c: presolved vector of coefficients of the objective
26+
% function (size n x 1)
27+
% -- b: presolved vector of the right-hand side of the
28+
% constraints (size m x 1)
29+
% -- Eqin: presolved vector of the type of the constraints
30+
% (size m x 1)
31+
% -- infeasible: flag variable showing if the LP is
32+
% infeasible or not
33+
34+
infeasible = 0;
35+
% compute the number of nonzero elements in each column
36+
delcols = sum(spones(A));
37+
% find the columns that have only one nonzero element and set
38+
% all the other columns equal to zero
39+
singleton = (delcols == 1);
40+
% find the number of the columns that have only one nonzero
41+
% element
42+
cardcols = nnz(singleton);
43+
countercols = 0;
44+
counterrows = 0;
45+
if cardcols > 0 % if dual singleton constraints exist
46+
% get the indices of the dual singleton constraints
47+
idscols = int16(find(singleton));
48+
% compute the number of the dual singleton constraints
49+
cardcols = length(idscols);
50+
% for each dual singleton inequality constraint
51+
for j = cardcols:-1:1
52+
jj = idscols(j); % get the index of the constraint
53+
% find the nonzero elements of this column
54+
[row, ~] = find(A(:, jj));
55+
if ~isempty(row) % if there are nonzero elements
56+
if Eqin(row) == -1 % constraint type <=
57+
% eliminate the dual singleton inequality
58+
% constraints (Case 1)
59+
if (A(row, jj) > 0) && (c(jj) > 0)
60+
A(:, jj) = [];
61+
c(jj) = [];
62+
countercols = countercols + 1;
63+
% check if the LP problem is infeasible
64+
% (Case 2)
65+
elseif (A(row, jj) < 0) && (c(jj) < 0)
66+
infeasible = 1;
67+
return;
68+
% eliminate the dual singleton inequality
69+
% constraints (Case 3)
70+
elseif (A(row,jj) > 0) && (c(jj) == 0)
71+
A(:, jj) = [];
72+
c(jj) = [];
73+
countercols = countercols + 1;
74+
% eliminate the dual singleton inequality
75+
% constraints (Case 4)
76+
elseif (A(row, jj) < 0) && (c(jj) == 0)
77+
A(:, jj) = [];
78+
c(jj) = [];
79+
A(row, :) = [];
80+
b(row) = [];
81+
Eqin(row) = [];
82+
countercols = countercols + 1;
83+
counterrows = counterrows + 1;
84+
end
85+
elseif Eqin(row) == 1 % constraint type >=
86+
% check if the LP problem is unbounded
87+
% (Case 5)
88+
if (A(row, jj) > 0) && (c(jj) < 0)
89+
infeasible = 1;
90+
return;
91+
% eliminate the dual singleton inequality
92+
% constraints (Case 6)
93+
elseif (A(row, jj) < 0) && (c(jj) > 0)
94+
A(:, jj) = [];
95+
c(jj) = [];
96+
countercols = countercols + 1;
97+
% eliminate the dual singleton inequality
98+
% constraints (Case 7)
99+
elseif (A(row,jj) > 0) && (c(jj) == 0)
100+
A(:, jj) = [];
101+
c(jj) = [];
102+
A(row, :) = [];
103+
b(row) = [];
104+
Eqin(row) = [];
105+
countercols = countercols + 1;
106+
counterrows = counterrows + 1;
107+
% eliminate the dual singleton inequality
108+
% constraints (Case 8)
109+
elseif (A(row, jj) < 0) && (c(jj) == 0)
110+
A(:, jj) = [];
111+
c(jj) = [];
112+
countercols = countercols + 1;
113+
end
114+
end
115+
end
116+
end
117+
if (countercols > 0) || (counterrows > 0)
118+
fprintf(['ELIMINATE DUAL SINGLETON INEQUALITY ' ...
119+
'CONSTRAINTS: %i constraints and %i columns ' ...
120+
'were eliminated\n'], counterrows, ...
121+
countercols);
122+
end
123+
end
124+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
function [A, b, Eqin] = eliminateImpliedBoundsonRows(A, ...
2+
b, Eqin)
3+
% Filename: eliminateImpliedBoundsonRows.m
4+
% Description: the function is an implementation of the
5+
% presolve technique that eliminates implied bounds on
6+
% rows
7+
% Authors: Ploskas, N., & Samaras, N.
8+
%
9+
% Syntax: [A, b, Eqin] = eliminateImpliedBoundsonRows(A, ...
10+
% b, Eqin)
11+
%
12+
% Input:
13+
% -- A: matrix of coefficients of the constraints
14+
% (size m x n)
15+
% -- b: vector of the right-hand side of the constraints
16+
% (size m x 1)
17+
% -- Eqin: vector of the type of the constraints
18+
% (size m x 1)
19+
%
20+
% Output:
21+
% -- A: presolved matrix of coefficients of the constraints
22+
% (size m x n)
23+
% -- b: presolved vector of the right-hand side of the
24+
% constraints (size m x 1)
25+
% -- Eqin: presolved vector of the type of the constraints
26+
% (size m x 1)
27+
28+
[row, ~] = find(Eqin ~= 0); % find the inequality constraints
29+
% find the number of these constraints
30+
cardrows = length(row);
31+
counterrows = 0;
32+
for i = cardrows:-1:1 % for each of these constraints
33+
ii = row(i); % get the index of the constraint
34+
% if all elements in that constraint are less than or
35+
% equal to zero, the constraint has a right-hand side
36+
% greater than or equal to zero, and the constraint
37+
% type is <=, then eliminate the constraint and update
38+
% matrix A and vectors b and Eqin (Case 1)
39+
if all((A(ii, :) <= 0)) && (b(ii) >= 0)
40+
if Eqin(ii) == -1
41+
A(ii, :) = [];
42+
Eqin(ii) = [];
43+
b(ii) = [];
44+
counterrows = counterrows + 1;
45+
end
46+
% if all elements in that constraint are greater than
47+
% or equal to zero, the constraint has a right-hand
48+
% side less than or equal to zero, and the constraint
49+
% type is >=, then eliminate the constraint and update
50+
% matrix A and vectors b and Eqin (Case 1)
51+
elseif all((A(ii, :) >= 0)) && (b(ii) <= 0)
52+
if Eqin(ii) == 1
53+
A(ii, :) = [];
54+
Eqin(ii) = [];
55+
b(ii) = [];
56+
counterrows = counterrows + 1;
57+
end
58+
end
59+
end
60+
if counterrows > 0
61+
fprintf(['ELIMINATE IMPLIED BOUNDS ON ROWS: %i ' ...
62+
'constraints were eliminated\n'], counterrows);
63+
end
64+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
function [A, c, b, Eqin, c0] = ...
2+
eliminateImpliedFreeSingletonColumns(A, c, b, Eqin, c0)
3+
% Filename: eliminateImpliedFreeSingletonColumns.m
4+
% Description: the function is an implementation of the
5+
% presolve technique that eliminates implied free
6+
% singleton constraints
7+
% Authors: Ploskas, N., & Samaras, N.
8+
%
9+
% Syntax: [A, c, b, Eqin, c0] = ...
10+
% eliminateImpliedFreeSingletonColumns(A, c, b, Eqin, c0)
11+
%
12+
% Input:
13+
% -- A: matrix of coefficients of the constraints
14+
% (size m x n)
15+
% -- c: vector of coefficients of the objective function
16+
% (size n x 1)
17+
% -- b: vector of the right-hand side of the constraints
18+
% (size m x 1)
19+
% -- Eqin: vector of the type of the constraints
20+
% (size m x 1)
21+
% -- c0: constant term of the objective function
22+
%
23+
% Output:
24+
% -- A: presolved matrix of coefficients of the constraints
25+
% (size m x n)
26+
% -- c: presolved vector of coefficients of the objective
27+
% function (size n x 1)
28+
% -- b: presolved vector of the right-hand side of the
29+
% constraints (size m x 1)
30+
% -- Eqin: presolved vector of the type of the constraints
31+
% (size m x 1)
32+
% -- c0: updated constant term of the objective function
33+
34+
% compute the number of nonzero elements in each column
35+
delcols = sum(spones(A));
36+
% find the columns that have only one nonzero element and
37+
% set all the other columns equal to zero
38+
singleton = (delcols == 1);
39+
% find the number of the columns that have only one nonzero
40+
% element
41+
cardcols = nnz(singleton);
42+
idscols = find(singleton);
43+
countercols = 0;
44+
for j = cardcols:-1:1 % for each dual singleton constraint
45+
jj = idscols(j); % get the index of the constraint
46+
% find the nonzero elements of this column
47+
[row, ~] = find(A(:, jj));
48+
if ~isempty(row) % if there are nonzero elements
49+
if Eqin(row) == 0 % constraint type =
50+
% if the element is greater than zero
51+
if A(row, jj) > 0
52+
% find the number of columns
53+
n0 = size(A, 2);
54+
% compute the indices of all other columns
55+
set = setdiff(1:n0, jj);
56+
% if all the elements of the row except
57+
% the one in the specific column are less
58+
% than or equal to zero and the right-hand
59+
% side greater than or equal to zero,
60+
% then update matrix A, vectors c, b, and
61+
% Eqin, and variable c0
62+
if all(A(row, set) <= 0) && b(row) >= 0
63+
if c(jj) ~= 0
64+
c0 = c0 + c(jj) * (b(row) / A(row, jj));
65+
c = c - (c(jj) / A(row, jj)) * A(row, :)';
66+
end
67+
c(jj) = [];
68+
A(:, jj) = [];
69+
A(row, :) = [];
70+
b(row) = [];
71+
Eqin(row) = [];
72+
countercols = countercols + 1;
73+
end
74+
elseif A(row, jj) < 0 % if the element is less
75+
% than zero
76+
n0 = size(A, 2); % find the number of columns
77+
% compute the indices of all other columns
78+
set = setdiff(1:n0, jj);
79+
% if all the elements of the row except the
80+
% one in the specific column are greater than
81+
% or equal to zero and the right-hand side
82+
% less than or equal to zero, then update
83+
% matrix A, vectors c, b, and Eqin, and
84+
% variable c0
85+
if all(A(row, set) >= 0) && b(row) <= 0
86+
if c(jj) ~= 0
87+
c0 = c0 + c(jj) * (b(row) / A(row, jj));
88+
c = c - (c(jj) / A(row,jj)) * A(row, :)';
89+
end
90+
c(jj) = [];
91+
A(:, jj) = [];
92+
A(row, :) = [];
93+
b(row) = [];
94+
Eqin(row) = [];
95+
countercols = countercols + 1;
96+
end
97+
end
98+
elseif Eqin(row) == 1 % constraint type <=
99+
if A(row, jj) > 0 % if the element is greater
100+
% than zero
101+
n0 = size(A, 2); % find the number of columns
102+
% compute the indices of all other columns
103+
set = setdiff(1:n0, jj);
104+
% if all the elements of the row except
105+
% the one in the specific column are less
106+
% than or equal to zero and the right-hand
107+
% side greater than or equal to -1, then
108+
% update matrix A, vectors c, b, and Eqin, and
109+
% variable c0
110+
if all(A(row, set) <= 0) && b(row) >= -1
111+
if c(jj) ~= 0
112+
c0 = c0 + c(jj) * (b(row) ...
113+
/ A(row, jj));
114+
c = c - (c(jj) / A(row, jj)) ...
115+
* A(row, :)';
116+
end
117+
c(jj) = [];
118+
A(:, jj) = [];
119+
A(row, :) = [];
120+
b(row) = [];
121+
Eqin(row) = [];
122+
countercols = countercols + 1;
123+
end
124+
end
125+
elseif Eqin(row) == -1 % constraint type >=
126+
if A(row, jj) < 0 % if the element is less
127+
% than zero
128+
n0 = size(A, 2); % find the number of columns
129+
% compute the indices of all other columns
130+
set = setdiff(1:n0, jj);
131+
% if all the elements of the row except
132+
% the one in the specific column are greater
133+
% than or equal to zero and the right-hand
134+
% side less than or equal to 1, then update
135+
% matrix A, vectors c, b, and Eqin, and
136+
% variable c0
137+
if all(A(row, set) >= 0) && b(row) <= 1
138+
if c(jj) ~= 0
139+
c0 = c0 + c(jj) * (b(row) ...
140+
/ A(row, jj));
141+
c = c - (c(jj) / A(row, jj)) ...
142+
* A(row, :)';
143+
end
144+
c(jj) = [];
145+
A(:, jj) = [];
146+
A(row, :) = [];
147+
b(row) = [];
148+
Eqin(row) = [];
149+
countercols = countercols + 1;
150+
end
151+
end
152+
end
153+
end
154+
end
155+
if countercols > 0
156+
fprintf(['ELIMINATE IMPLIED FREE SINGLETON COLUMNS: ' ...
157+
'%i rows and %i columns were eliminated\n'], ...
158+
countercols, countercols);
159+
end
160+
end

0 commit comments

Comments
 (0)