aGrUM  0.13.2
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 492 of file LpInterface.h.

Constructor & Destructor Documentation

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

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

+ Here is the call graph for this function:

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 643 of file LpInterface_tpl.h.

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

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

+ Here is the call graph for this function:

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

Copy constructor.

Parameters
rowThe constant reference to the row to be copied.

Definition at line 687 of file LpInterface_tpl.h.

687  :
688  __cste(row.__cste),
689  __coeffs(new HashTable< LpCol, double >(*row.__coeffs)) {
690  GUM_CONS_CPY(LpRow);
691  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:584
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:580
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.
gum::credal::lp::LpRow::LpRow ( LpRow &&  row)

Move copy constructor from temporary.

Parameters
rowThe temporary row to be copied.

Definition at line 693 of file LpInterface_tpl.h.

693  : __cste(row.__cste), __coeffs(row.__coeffs) {
694  row.__coeffs = nullptr;
695 
696  GUM_CONS_CPY(LpRow);
697  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:584
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:580
LpRow(const LpExpr &expr, const std::vector< LpCol > &cols)
Constructor from an expression and the address of the vector of variables of the problem.
gum::credal::lp::LpRow::~LpRow ( )

Default destructor.

Definition at line 699 of file LpInterface_tpl.h.

References __coeffs.

699  {
700  delete __coeffs;
701 
702  GUM_DESTRUCTOR(LpRow);
703  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:584
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

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

Definition at line 705 of file LpInterface_tpl.h.

References __coeffs, and __cste.

705  {
706  __cste = row.__cste;
707  *__coeffs = *row.__coeffs;
708  return *this;
709  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:584
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:580
LpRow & gum::credal::lp::LpRow::operator= ( LpRow &&  row)
Parameters
rowThe temporary row to be moved to this.

Definition at line 711 of file LpInterface_tpl.h.

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

711  {
712  __cste = row.__cste;
713  swap(__coeffs, row.__coeffs);
714  return *this;
715  }
HashTable< LpCol, double > * __coeffs
The coefficients of the variables of the linear inequality.
Definition: LpInterface.h:584
double __cste
The constant of the linear inequality.
Definition: LpInterface.h:580
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:

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 722 of file LpInterface_tpl.h.

References __coeffs, and __cste.

Referenced by gum::credal::lp::operator<<().

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

+ Here is the caller graph for this function:

Friends And Related Function Documentation

template<typename GUM_SCALAR >
friend class LpInterface
friend

Definition at line 494 of file LpInterface.h.

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 717 of file LpInterface_tpl.h.

717  {
718  out << row.toString();
719  return out;
720  }

Member Data Documentation

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

The coefficients of the variables of the linear inequality.

Definition at line 584 of file LpInterface.h.

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

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

The constant of the linear inequality.

Definition at line 580 of file LpInterface.h.

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


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