1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the class library */
/* SoPlex --- the Sequential object-oriented simPlex. */
/* */
/* Copyright 1996-2022 Zuse Institute Berlin */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* */
/* You should have received a copy of the Apache-2.0 license */
/* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file lprowbase.h
* @brief (In)equality for LPs.
*/
#ifndef _LPROWBASE_H_
#define _LPROWBASE_H_
#include <assert.h>
#include "soplex/spxdefines.h"
#include "soplex/basevectors.h"
namespace soplex
{
/**@brief (In)equality for LPs.
* @ingroup Algo
*
* Class LPRowBase provides constraints for linear programs in the form \f[ l \le a^Tx \le r, \f] where \em a is a
* DSVector. \em l is referred to as %left hand side, \em r as %right hand side and \em a as \em row \em vector or the
* constraint vector. \em l and \em r may also take values \f$\pm\f$ #R(infinity). This static member is predefined, but
* may be overridden to meet the needs of the LP solver to be used.
*
* LPRowBases allow to specify regular inequalities of the form \f[ a^Tx \sim \alpha, \f] where \f$\sim\f$ can take any
* value of \f$\le, =, \ge\f$, by setting rhs and lhs to the same value or setting one of them to \f$\infty\f$.
*
* Since constraints in the regular form occur often, LPRowBases offers methods type() and value() for retreiving
* \f$\sim\f$ and \f$\alpha\f$ of an LPRowBase in this form, respectively. Also, a constructor for LPRowBases given in
* regular form is provided.
*/
template < class R >
class LPRowBase
{
template < class S > friend class LPRowBase;
private:
// ------------------------------------------------------------------------------------------------------------------
/**@name Data */
///@{
R left; ///< left-hand side of the constraint
R right; ///< right-hand side of the constraint
R object; ///< objective coefficient of corresponding slack variable s = vec times primal
DSVectorBase<R> vec; ///< the row vector
///@}
public:
// ------------------------------------------------------------------------------------------------------------------
/**@name Types */
///@{
/// (In)Equality type of an LP row.
/** #LPRowBase%s may be of one of the following Types. This datatype may be used for constructing new #LPRowBase%s in the
* regular form.
*/
enum Type
{
LESS_EQUAL, ///< \f$a^Tx \le \alpha\f$.
EQUAL, ///< \f$a^Tx = \alpha\f$.
GREATER_EQUAL, ///< \f$a^Tx \ge \alpha\f$.
RANGE ///< \f$\lambda \le a^Tx \le \rho\f$.
};
///@}
// ------------------------------------------------------------------------------------------------------------------
/**@name Construction / destruction */
///@{
/// Constructs LPRowBase with a vector ready to hold \p defDim nonzeros.
explicit LPRowBase<R>(int defDim = 0)
: left(0), right(R(infinity)), object(0), vec(defDim)
{
assert(isConsistent());
}
/// Assignment operator.
LPRowBase<R>& operator=(const LPRowBase<R>& row)
{
if(this != &row)
{
left = row.left;
right = row.right;
object = row.object;
vec = row.vec;
}
assert(isConsistent());
}
/// Copy constructor.
LPRowBase<R>(const LPRowBase<R>& row)
: left(row.left), right(row.right), object(row.object), vec(row.vec)
{
assert(isConsistent());
}
/// Copy constructor.
template < class S >
LPRowBase<R>(const LPRowBase<S>& row)
: left(row.left), right(row.right), object(row.object), vec(row.vec)
{
assert(isConsistent());
}
/// Constructs LPRowBase with the given left-hand side, right-hand side and rowVector.
LPRowBase<R>(const R& p_lhs, const SVectorBase<R>& p_rowVector, const R& p_rhs, const R& p_obj = 0)
: left(p_lhs), right(p_rhs), object(p_obj), vec(p_rowVector)
{
assert(isConsistent());
}
/// Constructs LPRowBase from passed \p rowVector, \p type and \p value.
LPRowBase<R>(const SVectorBase<R>& p_rowVector, Type p_type, const R& p_value, const R& p_obj = 0)
: object(p_obj), vec(p_rowVector)
{
switch(p_type)
{
case LESS_EQUAL:
left = R(-infinity);
right = p_value;
break;
case EQUAL:
left = p_value;
right = p_value;
break;
case GREATER_EQUAL:
left = p_value;
right = R(infinity);
break;
default:
throw SPxInternalCodeException("XLPROW03 This should never happen.");
}
assert(isConsistent());
}
/// Destructor.
~LPRowBase()
{}
///@}
// ------------------------------------------------------------------------------------------------------------------
/**@name Access / modification */
///@{
/// Gets type of row.
Type type() const
{
if(rhs() >= R(infinity))
return GREATER_EQUAL;
if(lhs() <= R(-infinity))
return LESS_EQUAL;
if(lhs() == rhs())
return EQUAL;
return RANGE;
}
/// Sets type of (in)equality.
void setType(Type p_type)
{
switch(p_type)
{
case LESS_EQUAL:
left = R(-infinity);
break;
case EQUAL:
if(lhs() > R(-infinity))
right = lhs();
else
left = rhs();
break;
case GREATER_EQUAL:
right = R(infinity);
break;
case RANGE:
MSG_ERROR(std::cerr << "ELPROW01 RANGE not supported in LPRow::setType()"
<< std::endl;)
throw SPxInternalCodeException("XLPROW01 This should never happen.");
default:
throw SPxInternalCodeException("XLPROW02 This should never happen.");
}
}
/// Right hand side value of (in)equality.
/** This method returns \f$\alpha\f$ for a LPRowBase in regular form. However, value() may only be called for
* LPRowBase%s with type() != \c RANGE.
*/
R value() const
{
assert(type() != RANGE);
return (rhs() < R(infinity)) ? rhs() : lhs();
}
/// Left-hand side value.
R lhs() const
{
return left;
}
/// Sets left-hand side value.
void setLhs(const R& p_left)
{
left = p_left;
}
/// Right-hand side value.
R rhs() const
{
return right;
}
/// Sets right-hand side value.
void setRhs(const R& p_right)
{
right = p_right;
}
/// Objective coefficient value.
R obj() const
{
return object;
}
/// Sets objective coefficient value.
void setObj(const R& p_obj)
{
object = p_obj;
}
/// Constraint row vector.
const SVectorBase<R>& rowVector() const
{
return vec;
}
/// access constraint row vector.
void setRowVector(const DSVectorBase<R>& p_vec)
{
vec = p_vec;
}
///@}
// ------------------------------------------------------------------------------------------------------------------
/**@name Consistency check */
///@{
/// Checks consistency.
bool isConsistent() const
{
#ifdef ENABLE_CONSISTENCY_CHECKS
return vec.isConsistent();
#else
return true;
#endif
}
///@}
};
} // namespace soplex
#endif // _LPROWBASE_H_