52 template <
typename SCALAR >
62 template <
typename T >
74 template <
typename T >
86 template <
typename SCALAR >
99 "LpExpr::setSide ( const LpCol & from "
100 ") : too many <= ; no free side");
106 template <
typename GUM_SCALAR >
113 template <
typename GUM_SCALAR >
118 for (
unsigned int i = 0, end = from.
_rows_.size(); i < end; i++)
124 template <
typename GUM_SCALAR >
132 template <
typename GUM_SCALAR >
134 for (
const auto row:
_rows_)
140 template <
typename GUM_SCALAR >
144 for (
const auto& row:
_rows_)
152 for (
unsigned int i = 0, end = from.
_rows_.size(); i < end; i++)
162 template <
typename GUM_SCALAR >
174 template <
typename T >
180 template <
typename GUM_SCALAR >
189 template <
typename GUM_SCALAR >
193 "LpInterface::addCols ( cols ) : cols "
194 "needs must be equal or greater than 1 : "
197 for (
unsigned int i = 0; i < cols; i++) {
204 template <
typename GUM_SCALAR >
208 "addRow ( const LpExpr & expr ) : expr : " << expr.
toString()
209 <<
"is not an inequality.");
214 LpExpr lexpr(expr,
true,
true,
false);
215 LpExpr rexpr(expr,
false,
true,
true);
224 template <
typename GUM_SCALAR >
226 if (!expr._ileft_ && !expr._iright_)
228 "addRow ( const LpExpr & expr ) : expr : " << expr.toString()
229 <<
"is not an inequality.");
231 if ((expr._ileft_ && !expr._iright_) || (!expr._ileft_ && expr._iright_)) {
234 LpExpr lexpr(std::move(expr),
true,
true,
false);
237 LpExpr rexpr(std::move(expr),
false,
false,
true);
252 template <
typename GUM_SCALAR >
256 for (
const auto& col:
_cols_)
262 template <
typename GUM_SCALAR >
268 for (
const auto& col:
_cols_)
271 addRow(1 <= std::move(expr) <= 1);
276 template <
typename GUM_SCALAR >
293 for (
const auto& col:
_cols_) {
298 addRow(1 <= std::move(expr) <= 1);
304 template <
typename GUM_SCALAR >
310 std::vector< std::vector< GUM_SCALAR > > lrsMatrix;
312 for (
const auto& row:
_rows_) {
313 std::vector< GUM_SCALAR > expandedRow(
_cols_.size() + 1, 0);
315 expandedRow[0] = row->_cste_;
317 for (
const auto& elt: *row->_coeffs_)
318 expandedRow[elt.first.id() + 1] = elt.second;
320 lrsMatrix.push_back(expandedRow);
330 template <
typename GUM_SCALAR >
335 template <
typename GUM_SCALAR >
337 std::ostringstream s;
339 s << std::endl << std::endl <<
"Variables : " << std::endl;
341 for (
const auto& col:
_cols_)
342 s <<
" " << col.toString();
346 for (
const auto& row:
_rows_)
347 s << std::endl << row->toString();
349 s << std::endl << std::endl;
354 template <
typename GUM_SCALAR >
356 for (
const auto& row:
_rows_)
372 template <
typename GUM_SCALAR >
374 for (
const auto& row:
_rows_)
385 template <
typename T2 >
387 LpExpr expr = std::move(lhs);
393 template <
typename T2 >
401 template <
typename T1, forb
idden_type< T1, LpExpr > >
403 LpExpr expr = std::move(rhs);
410 template <
typename T1, forb
idden_type< T1, LpExpr > >
418 template <
typename T2, forb
idden_type< T2, LpExpr > >
427 template <
typename T1, forb
idden_type< T1, LpExpr >, forb
idden_type< T1, LpCol > >
437 template <
typename T2 >
439 LpExpr expr = std::move(lhs);
445 template <
typename T2 >
453 template <
typename T1, forb
idden_type< T1, LpExpr > >
456 expr += std::move(rhs);
463 template <
typename T1, forb
idden_type< T1, LpExpr > >
472 template <
typename T2, forb
idden_type< T2, LpExpr > >
481 template <
typename T1, forb
idden_type< T1, LpExpr >, forb
idden_type< T1, LpCol > >
491 template <
typename SCALAR >
499 template <
typename SCALAR >
504 template <
typename SCALAR >
510 template <
typename T1,
typename T2 >
519 template <
typename T2 >
524 template <
typename T2 >
529 template <
typename T1, forb
idden_type< T1, LpExpr& >, forb
idden_type< T1, LpCol& > >
534 template <
typename T1, forb
idden_type< T1, LpExpr& >, forb
idden_type< T1, LpCol& > >
540 template <
typename T2 >
545 template <
typename T2 >
550 template <
typename T1, forb
idden_type< T1, LpExpr >, forb
idden_type< T1, LpCol > >
555 template <
typename T1, forb
idden_type< T1, LpExpr >, forb
idden_type< T1, LpCol > >
Class representing a polytope ( credal set ) by a set of linear constraints.
Exception : operation not allowed.
Class template acting as a wrapper for Lexicographic Reverse Search by David Avis.
const matrix & getOutput() const
Get the output matrix solution of the problem.
void H2V()
H-representation to V-representation.
void fillMatrix(const std::vector< std::vector< GUM_SCALAR > > &matrix)
Fill the H-representation from the matrix given in argument.
void setUpH(const Size &card)
Sets up an H-representation.
Class representing a variable ( a column ) of a linear program, i.e.
Class representing a linear expression.
LpExpr & operator+=(const LpCol &rhs)
Compound assignment operator += with a variable.
double _rValue_
The constant on the right side L : L <= M <= R.
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R .
LpExpr & operator-=(const LpCol &rhs)
Compound assignment operator -= with a variable.
LpExpr()
Default constructor.
std::string toString() const
Get the string representation of a calling expression.
void clear()
Clear all data of the calling expression as if it was constructed.
static LpExpr multiply(const SCALAR &lhs, const LpCol &rhs)
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
static LpExpr lessThan(T1 &&lhs, T2 &&rhs)
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
double _mValue_
The constant on the middle side L : L <= M <= R.
double _lValue_
The constant on the left side L : L <= M <= R.
LpExpr & operator=(const LpCol &rhs)
Assignment operator = with a variable.
void _addSide_(const LpCol &from)
Set the side of the calling expression, from LEFT TO RIGHT : L <= M <= R.
Class representing a linear program.
bool _sumIsOne_
true if addSumIsOne() has been called, false otherwise.
std::string toString() const
Get the string representation of a calling linear program.
void addSumIsOne()
Add sum of variables is 1 constraints.
void clear()
Reset the rows (inequalities) and columns (variables) of the LP as if it was created.
std::vector< LpCol > getCols() const
Get the variables of the LP.
void clearRows()
Reset the rows (inequalities) of the LP but not the columns (variables are kept).
std::vector< LpCol > _cols_
Variables of the problem.
std::vector< LpRow * > _rows_
Rows of the problem.
LpInterface< GUM_SCALAR > & operator=(const LpInterface< GUM_SCALAR > &from)
Copy compound assignment.
LpInterface()
Default constructor, empty problem.
void addPositivity()
Add positivity constraints for all variables.
std::vector< std::vector< GUM_SCALAR > > solve()
Solve the linear program (H-representation of the polytope) by enumeration (of the polytope vertices)...
std::vector< LpCol > addCols(const unsigned int &cols)
Insert new columns, i.e.
LpCol addCol()
Insert a new column, i.e.
void addProba()
Add positivity constraints and sum of variables is 1 ( probability constraints ).
void addRow(const LpExpr &expr)
Add rows to the linear program according to a given expression ( which must be at least an inequality...
~LpInterface()
Default destructor.
bool _positivity_
true if addPositivity() has been called, false otherwise.
Class representing a row of the linear program, i.e.
#define GUM_ERROR(type, msg)
namespace for constraint-based description of credal sets
LpExpr operator+(LpExpr &&lhs, const T2 &rhs)
Overload of operator + between anything ( a scalar, a variable or an expression ) and anything except...
LpExpr operator<=(const LpExpr &lhs, T2 &&rhs)
Overload of operator <= between anything and anything.
LpExpr operator-(LpExpr &&lhs, const T2 &rhs)
Overload of operator - between anything ( a scalar, a variable or an expression ) and anything except...
std::ostream & operator<<(std::ostream &out, const LpRow &row)
namespace for all credal networks entities
gum is the global namespace for all aGrUM entities
value_type & operator*()
Returns the value pointed to by the iterator.