Class representing a row of the linear program, i.e.
More...
#include <agrum/CN/LpInterface.h>
|
template<typename GUM_SCALAR > |
class | LpInterface |
|
std::ostream & | operator<< (std::ostream &out, const LpRow &row) |
| Overload of << to use with output streams ( such as std::cout << ). More...
|
|
Class representing a row of the linear program, i.e.
an inequality.
- Author
- Matthieu HOURBRACQ and Pierre-Henri WUILLEMIN
Definition at line 501 of file LpInterface.h.
◆ LpRow() [1/4]
gum::credal::lp::LpRow::LpRow |
( |
const LpExpr & |
expr, |
|
|
const std::vector< LpCol > & |
cols |
|
) |
| |
Constructor from an expression and the address of the vector of variables of the problem.
class LpRow
- Parameters
-
expr | the constant reference to the expression to convert into rows ( inequalities ). |
cols | the constant reference to the vector of variables of the problem. |
Definition at line 593 of file LpInterface_tpl.h.
References __coeffs, __cste, gum::credal::lp::LpExpr::__ileft, gum::credal::lp::LpExpr::__iright, gum::credal::lp::LpExpr::__lCoeffs, gum::credal::lp::LpExpr::__lValue, gum::credal::lp::LpExpr::__mCoeffs, gum::credal::lp::LpExpr::__mValue, gum::credal::lp::LpExpr::__rCoeffs, gum::credal::lp::LpExpr::__rValue, GUM_ERROR, and gum::credal::lp::LpExpr::toString().
596 if (expr.__ileft && !expr.__iright) {
597 __coeffs =
new HashTable< LpCol, double >(*expr.__mCoeffs);
599 for (
const auto& col : cols) {
600 double col_coeff = 0.;
603 if (expr.__lCoeffs->exists(col))
604 col_coeff = expr.__lCoeffs->operator[](col);
606 __coeffs->getWithDefault(col, 0.) -= col_coeff;
609 __cste = expr.__mValue - expr.__lValue;
610 }
else if (expr.__iright && !expr.__ileft) {
611 __coeffs =
new HashTable< LpCol, double >(*expr.__rCoeffs);
613 for (
const auto& col : cols) {
614 double col_coeff = 0;
617 if (expr.__mCoeffs->exists(col))
618 col_coeff = expr.__mCoeffs->operator[](col);
620 __coeffs->getWithDefault(col, 0.) -= col_coeff;
623 __cste = expr.__rValue - expr.__mValue;
626 "expr : " << expr.toString()
627 <<
"is not a valid inequality; no <= detected");
631 "expr : " << expr.toString()
632 <<
"is not a valid inequality; " 633 "no variable in inequality, " 636 GUM_CONSTRUCTOR(
LpRow);
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
double __cste
The constant of the linear inequality.
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.
#define GUM_ERROR(type, msg)
◆ LpRow() [2/4]
gum::credal::lp::LpRow::LpRow |
( |
LpExpr && |
expr, |
|
|
const std::vector< LpCol > & |
cols |
|
) |
| |
Move constructor from a temporary expression and the address of the vector of variables of the problem.
- Parameters
-
expr | the temporary expression to move into rows ( inequalities ). |
cols | the constant reference to the vector of variables of the problem. |
Definition at line 639 of file LpInterface_tpl.h.
References __coeffs, __cste, GUM_ERROR, and gum::credal::lp::swap().
642 if (expr.__ileft && !expr.__iright) {
645 for (
const auto& col : cols) {
646 double col_coeff = 0;
648 if (expr.__lCoeffs->exists(col))
649 col_coeff = expr.__lCoeffs->operator[](col);
651 __coeffs->getWithDefault(col, 0.) -= col_coeff;
654 __cste = expr.__mValue - expr.__lValue;
655 }
else if (expr.__iright && !expr.__ileft) {
658 for (
const auto& col : cols) {
659 double col_coeff = 0;
661 if (expr.__mCoeffs->exists(col))
662 col_coeff = expr.__mCoeffs->operator[](col);
664 __coeffs->getWithDefault(col, 0.) -= col_coeff;
667 __cste = expr.__rValue - expr.__mValue;
670 "expr : " << expr.toString()
671 <<
"is not a valid inequality; no <= detected");
675 "expr : " << expr.toString()
676 <<
"is not a valid inequality; " 677 "no variable in inequality, " 680 GUM_CONSTRUCTOR(
LpRow);
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
double __cste
The constant of the linear inequality.
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.
#define GUM_ERROR(type, msg)
◆ LpRow() [3/4]
gum::credal::lp::LpRow::LpRow |
( |
const LpRow & |
row | ) |
|
Copy constructor.
- Parameters
-
row | The constant reference to the row to be copied. |
Definition at line 683 of file LpInterface_tpl.h.
685 __coeffs(
new HashTable< LpCol, double >(*row.__coeffs)) {
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
double __cste
The constant of the linear inequality.
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.
◆ LpRow() [4/4]
gum::credal::lp::LpRow::LpRow |
( |
LpRow && |
row | ) |
|
Move copy constructor from temporary.
- Parameters
-
row | The temporary row to be copied. |
Definition at line 689 of file LpInterface_tpl.h.
690 row.__coeffs =
nullptr;
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
double __cste
The constant of the linear inequality.
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.
◆ ~LpRow()
gum::credal::lp::LpRow::~LpRow |
( |
| ) |
|
Default destructor.
Definition at line 695 of file LpInterface_tpl.h.
References __coeffs.
698 GUM_DESTRUCTOR(
LpRow);
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.
◆ operator=() [1/2]
LpRow & gum::credal::lp::LpRow::operator= |
( |
const LpRow & |
row | ) |
|
- Parameters
-
row | The constant reference to the row to be copied. |
Definition at line 701 of file LpInterface_tpl.h.
References __coeffs, and __cste.
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
double __cste
The constant of the linear inequality.
◆ operator=() [2/2]
LpRow & gum::credal::lp::LpRow::operator= |
( |
LpRow && |
row | ) |
|
- Parameters
-
row | The temporary row to be moved to this. |
Definition at line 707 of file LpInterface_tpl.h.
References __coeffs, __cste, and gum::credal::lp::swap().
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
double __cste
The constant of the linear inequality.
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
◆ toString()
std::string gum::credal::lp::LpRow::toString |
( |
| ) |
const |
Get the string representation of a calling row.
- Returns
- The string representation of the calling row.
Definition at line 718 of file LpInterface_tpl.h.
References __coeffs, and __cste.
Referenced by gum::credal::lp::operator<<().
719 std::ostringstream s;
725 if (elt.second > 0) {
726 if (elt.second != 1) {
727 s <<
" +" << elt.second <<
"*" << elt.first.toString();
729 s <<
" +" << elt.first.toString();
732 if (elt.second < 0) {
733 if (elt.second != -1) {
734 s <<
" " << elt.second <<
"*" << elt.first.toString();
736 s <<
" -" << elt.first.toString();
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
double __cste
The constant of the linear inequality.
◆ LpInterface
template<typename GUM_SCALAR >
◆ operator<<
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const LpRow & |
row |
|
) |
| |
|
friend |
Overload of <<
to use with output streams ( such as std::cout << ).
- Parameters
-
out | the reference to the caller, i.e. left side of << . |
row | the constant reference to the row whose representation we want. |
- Returns
- The address of the caller.
Definition at line 713 of file LpInterface_tpl.h.
714 out << row.toString();
◆ __coeffs
◆ __cste
double gum::credal::lp::LpRow::__cste |
|
private |
The documentation for this class was generated from the following files: