aGrUM  0.16.0
gum::credal::lp::LpRow Class Reference

Class representing a row of the linear program, i.e. More...

#include <agrum/CN/LpInterface.h>

+ Collaboration diagram for gum::credal::lp::LpRow:

Public Member Functions

std::string toString () const
 Get the string representation of a calling row. More...
 
Constructors / Destructors
 LpRow (const LpExpr &expr, const std::vector< LpCol > &cols)
 Constructor from an expression and the address of the vector of variables of the problem. More...
 
 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. More...
 
 LpRow (const LpRow &row)
 Copy constructor. More...
 
 LpRow (LpRow &&row)
 Move copy constructor from temporary. More...
 
 ~LpRow ()
 Default destructor. More...
 
Assignment operators
LpRowoperator= (const LpRow &row)
 
LpRowoperator= (LpRow &&row)
 

Friends

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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
exprthe constant reference to the expression to convert into rows ( inequalities ).
colsthe 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().

593  :
594  __coeffs(nullptr) {
595  // we write 0 <= Ax + b from Ex + f <= Cx + d
596  if (expr.__ileft && !expr.__iright) {
597  __coeffs = new HashTable< LpCol, double >(*expr.__mCoeffs);
598 
599  for (const auto& col : cols) {
600  double col_coeff = 0.;
601 
602  // from left side to middle side : 0 <= middle - left
603  if (expr.__lCoeffs->exists(col))
604  col_coeff = expr.__lCoeffs->operator[](col);
605 
606  __coeffs->getWithDefault(col, 0.) -= col_coeff;
607  }
608 
609  __cste = expr.__mValue - expr.__lValue;
610  } else if (expr.__iright && !expr.__ileft) {
611  __coeffs = new HashTable< LpCol, double >(*expr.__rCoeffs);
612 
613  for (const auto& col : cols) {
614  double col_coeff = 0;
615 
616  // from middle side to right side : 0 <= right - middle
617  if (expr.__mCoeffs->exists(col))
618  col_coeff = expr.__mCoeffs->operator[](col);
619 
620  __coeffs->getWithDefault(col, 0.) -= col_coeff;
621  }
622 
623  __cste = expr.__rValue - expr.__mValue;
624  } else
625  GUM_ERROR(OperationNotAllowed,
626  "expr : " << expr.toString()
627  << "is not a valid inequality; no <= detected");
628 
629  if (__coeffs->size() == 0)
630  GUM_ERROR(OperationNotAllowed,
631  "expr : " << expr.toString()
632  << "is not a valid inequality; "
633  "no variable in inequality, "
634  "only constants");
635 
636  GUM_CONSTRUCTOR(LpRow);
637  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:593
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:589
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)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ 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
exprthe temporary expression to move into rows ( inequalities ).
colsthe 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().

639  :
640  __coeffs(nullptr) {
642  if (expr.__ileft && !expr.__iright) {
643  swap(__coeffs, expr.__mCoeffs);
644 
645  for (const auto& col : cols) {
646  double col_coeff = 0;
647 
648  if (expr.__lCoeffs->exists(col))
649  col_coeff = expr.__lCoeffs->operator[](col);
650 
651  __coeffs->getWithDefault(col, 0.) -= col_coeff;
652  }
653 
654  __cste = expr.__mValue - expr.__lValue;
655  } else if (expr.__iright && !expr.__ileft) {
656  swap(__coeffs, expr.__rCoeffs);
657 
658  for (const auto& col : cols) {
659  double col_coeff = 0;
660 
661  if (expr.__mCoeffs->exists(col))
662  col_coeff = expr.__mCoeffs->operator[](col);
663 
664  __coeffs->getWithDefault(col, 0.) -= col_coeff;
665  }
666 
667  __cste = expr.__rValue - expr.__mValue;
668  } else
669  GUM_ERROR(OperationNotAllowed,
670  "expr : " << expr.toString()
671  << "is not a valid inequality; no <= detected");
672 
673  if (__coeffs->size() == 0)
674  GUM_ERROR(OperationNotAllowed,
675  "expr : " << expr.toString()
676  << "is not a valid inequality; "
677  "no variable in inequality, "
678  "only constants");
679 
680  GUM_CONSTRUCTOR(LpRow);
681  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:593
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:589
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)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ LpRow() [3/4]

gum::credal::lp::LpRow::LpRow ( const LpRow row)

Copy constructor.

Parameters
rowThe constant reference to the row to be copied.

Definition at line 683 of file LpInterface_tpl.h.

683  :
684  __cste(row.__cste),
685  __coeffs(new HashTable< LpCol, double >(*row.__coeffs)) {
686  GUM_CONS_CPY(LpRow);
687  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:593
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:589
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
rowThe temporary row to be copied.

Definition at line 689 of file LpInterface_tpl.h.

689  : __cste(row.__cste), __coeffs(row.__coeffs) {
690  row.__coeffs = nullptr;
691 
692  GUM_CONS_CPY(LpRow);
693  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:593
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:589
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.

695  {
696  delete __coeffs;
697 
698  GUM_DESTRUCTOR(LpRow);
699  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:593
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.

Member Function Documentation

◆ operator=() [1/2]

LpRow & gum::credal::lp::LpRow::operator= ( const LpRow row)
Parameters
rowThe constant reference to the row to be copied.

Definition at line 701 of file LpInterface_tpl.h.

References __coeffs, and __cste.

701  {
702  __cste = row.__cste;
703  *__coeffs = *row.__coeffs;
704  return *this;
705  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:593
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:589

◆ operator=() [2/2]

LpRow & gum::credal::lp::LpRow::operator= ( LpRow &&  row)
Parameters
rowThe temporary row to be moved to this.

Definition at line 707 of file LpInterface_tpl.h.

References __coeffs, __cste, and gum::credal::lp::swap().

707  {
708  __cste = row.__cste;
709  swap(__coeffs, row.__coeffs);
710  return *this;
711  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:593
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:589
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
+ Here is the call graph for this function:

◆ 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<<().

718  {
719  std::ostringstream s;
720 
721  s << "0 <= " << __cste;
722 
723  if (__coeffs != nullptr) {
724  for (const auto& elt : *__coeffs) {
725  if (elt.second > 0) {
726  if (elt.second != 1) {
727  s << " +" << elt.second << "*" << elt.first.toString();
728  } else {
729  s << " +" << elt.first.toString();
730  }
731  } else {
732  if (elt.second < 0) {
733  if (elt.second != -1) {
734  s << " " << elt.second << "*" << elt.first.toString();
735  } else {
736  s << " -" << elt.first.toString();
737  }
738  }
739  }
740  }
741  }
742 
743  return s.str();
744  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:593
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:589
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ LpInterface

template<typename GUM_SCALAR >
friend class LpInterface
friend

Definition at line 503 of file LpInterface.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const LpRow row 
)
friend

Overload of << to use with output streams ( such as std::cout << ).

Parameters
outthe reference to the caller, i.e. left side of <<.
rowthe constant reference to the row whose representation we want.
Returns
The address of the caller.

Definition at line 713 of file LpInterface_tpl.h.

713  {
714  out << row.toString();
715  return out;
716  }

Member Data Documentation

◆ __coeffs

HashTable< LpCol, double >* gum::credal::lp::LpRow::__coeffs
private

The coefficients of the variables of the linear inequality.

Definition at line 593 of file LpInterface.h.

Referenced by LpRow(), operator=(), toString(), and ~LpRow().

◆ __cste

double gum::credal::lp::LpRow::__cste
private

The constant of the linear inequality.

Definition at line 589 of file LpInterface.h.

Referenced by LpRow(), operator=(), and toString().


The documentation for this class was generated from the following files: