65 GUM_CONSTRUCTOR(
LpCol);
75 GUM_DESTRUCTOR(
LpCol);
127 expr._lCoeffs_ =
nullptr;
128 expr._mCoeffs_ =
nullptr;
129 expr._rCoeffs_ =
nullptr;
177 if (
this == &rhs)
return *
this;
196 if (
this == &rhs)
return *
this;
219 _mCoeffs_->getWithDefault(rhs, 0.) += 1.;
227 "expr::operator+= (rhs) : <= present "
228 "on one side of rhs and/or expr");
233 _mCoeffs_->getWithDefault(elt.first, 0.) += elt.second;
243 "expr::operator+= (rhs) : <= present "
244 "on one side of rhs and/or expr");
254 for (
const auto& elt: *rhs._mCoeffs_)
255 _mCoeffs_->getWithDefault(elt.first, 0.) += elt.second;
267 _mCoeffs_->getWithDefault(rhs, 0.) -= 1.;
275 "expr::operator-= (rhs) : <= present in one of rhs and/or expr");
280 _mCoeffs_->getWithDefault(elt.first, 0.) -= elt.second;
299 "LpExpr::setSide ( const LpCol & from "
300 ") : too many <= ; no free side");
306 "LpExpr::setSide ( const LpCol & from "
307 ") : too many <= ; no free side");
336 "LpExpr::setSide ( const LpCol & from ) "
337 ": too many <= ; no free side");
364 "LpExpr::setSide ( const LpCol & from ) "
365 ": too many <= ; no free side");
372 "LpExpr::setSide ( const LpCol & from ) "
373 ": too many <= ; no free side");
380 "LpExpr::setSide ( const LpCol & from "
381 ") : too many <= ; no free side");
388 "LpExpr::setSide ( const LpCol & from "
389 ") : too many <= ; no free side");
392 if (!from._imiddle_)
return;
397 if (!from._ileft_ && !from._iright_) {
421 "LpExpr::setSide ( const LpCol & from ) "
422 ": too many <= ; no free side");
426 else if (from._ileft_ && !from._iright_) {
453 "LpExpr::setSide ( const LpCol & from ) "
454 ": too many <= ; no free side");
458 else if (from._ileft_ && from._iright_) {
461 "LpExpr::setSide ( const LpCol & from ) "
462 ": too many <= ; no free side");
464 *
this = std::move(from);
469 "LpExpr::setSide ( const LpCol & from "
470 ") : too many <= ; no free side");
488 std::ostringstream s;
490 s << std::endl <<
"left side : " << std::endl;
494 s << elt.first.toString() <<
" " << elt.second <<
" | ";
496 s << std::endl <<
"middle side : " << std::endl;
500 s << elt.first.toString() <<
" " << elt.second <<
" | ";
502 s << std::endl <<
"right side : " << std::endl;
506 s << elt.first.toString() <<
" " << elt.second <<
" | ";
509 <<
"lvalue : " <<
_lValue_ << std::endl
510 <<
"mvalue : " <<
_mValue_ << std::endl
511 <<
"rvalue : " <<
_rValue_ << std::endl;
526 _coeffs_ = new HashTable< LpCol, double >(*expr._mCoeffs_);
528 for (const auto& col: cols) {
529 double col_coeff = 0.;
532 if (expr._lCoeffs_->exists(col)) col_coeff = expr._lCoeffs_->operator[](col);
534 _coeffs_->getWithDefault(col, 0.) -= col_coeff;
538 }
else if (expr._iright_ && !expr._ileft_) {
539 _coeffs_ = new HashTable< LpCol, double >(*expr._rCoeffs_);
541 for (const auto& col: cols) {
542 double col_coeff = 0;
545 if (expr._mCoeffs_->exists(col)) col_coeff = expr._mCoeffs_->operator[](col);
547 _coeffs_->getWithDefault(col, 0.) -= col_coeff;
550 _cste_ = expr._rValue_ - expr._mValue_;
553 "expr : " << expr.toString() <<
"is not a valid inequality; no <= detected");
555 if (_coeffs_->size() == 0)
557 "expr : " << expr.toString()
558 <<
"is not a valid inequality; "
559 "no variable in inequality, "
562 GUM_CONSTRUCTOR(LpRow);
567 if (expr._ileft_ && !expr._iright_) {
568 swap(_coeffs_, expr._mCoeffs_);
570 for (const auto& col: cols) {
571 double col_coeff = 0;
573 if (expr._lCoeffs_->exists(col)) col_coeff = expr._lCoeffs_->operator[](col);
575 _coeffs_->getWithDefault(col, 0.) -= col_coeff;
578 _cste_ = expr._mValue_ - expr._lValue_;
579 }
else if (expr._iright_ && !expr._ileft_) {
580 swap(_coeffs_, expr._rCoeffs_);
582 for (const auto& col: cols) {
583 double col_coeff = 0;
585 if (expr._mCoeffs_->exists(col)) col_coeff = expr._mCoeffs_->operator[](col);
587 _coeffs_->getWithDefault(col, 0.) -= col_coeff;
590 _cste_ = expr._rValue_ - expr._mValue_;
593 "expr : " << expr.toString() <<
"is not a valid inequality; no <= detected");
595 if (_coeffs_->size() == 0)
597 "expr : " << expr.toString()
598 <<
"is not a valid inequality; "
599 "no variable in inequality, "
602 GUM_CONSTRUCTOR(LpRow);
611 row._coeffs_ =
nullptr;
619 GUM_DESTRUCTOR(
LpRow);
640 std::ostringstream s;
646 if (elt.second > 0) {
647 if (elt.second != 1) {
648 s <<
" +" << elt.second <<
"*" << elt.first.toString();
650 s <<
" +" << elt.first.toString();
653 if (elt.second < 0) {
654 if (elt.second != -1) {
655 s <<
" " << elt.second <<
"*" << elt.first.toString();
657 s <<
" -" << elt.first.toString();
Class representing a polytope ( credal set ) by a set of linear constraints.
Class to include at least once this header.
The class for generic Hash Tables.
Exception : operation not allowed.
Class representing a variable ( a column ) of a linear program, i.e.
LpCol(unsigned int id)
Default constructor.
unsigned int id() const
Variable id accessor.
~LpCol()
Default destructor.
unsigned int _id_
Variable id.
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.
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
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.
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
~LpExpr()
Default destructor.
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right 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.
std::string toString() const
Get the string representation of a calling row.
LpRow & operator=(const LpRow &row)
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.
HashTable< LpCol, double > * _coeffs_
The coefficients of the variables of the linear inequality.
double _cste_
The constant of the linear inequality.
~LpRow()
Default destructor.
#define GUM_ERROR(type, msg)
namespace for constraint-based description of credal sets
std::ostream & operator<<(std::ostream &out, const LpRow &row)
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
namespace for all credal networks entities
gum is the global namespace for all aGrUM entities