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