aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::credal::lp::LpExpr Class Reference

Class representing a linear expression. More...

#include <agrum/CN/LpInterface.h>

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

Public Member Functions

void clear ()
 Clear all data of the calling expression as if it was constructed. More...
 
std::string toString () const
 Get the string representation of a calling expression. More...
 
template<typename SCALAR >
INLINE LpExpr multiply (const SCALAR &lhs, const LpCol &rhs)
 
template<typename T1 , typename T2 >
INLINE LpExpr lessThan (T1 &&lhs, T2 &&rhs)
 
Constructors / Destructors
 LpExpr ()
 Default constructor. More...
 
 LpExpr (const LpExpr &expr)
 Copy constructor. More...
 
 LpExpr (const LpExpr &expr, bool copyLeft, bool copyMiddle, bool copyRight)
 Copy constructor. More...
 
 LpExpr (LpExpr &&expr)
 Move copy constructor from temporary. More...
 
 LpExpr (LpExpr &&expr, bool copyLeft, bool copyMiddle, bool copyRight)
 Move copy constructor from temporary. More...
 
 ~LpExpr ()
 Default destructor. More...
 
Assignment operators =
LpExproperator= (const LpCol &rhs)
 Assignment operator = with a variable. More...
 
LpExproperator= (const LpExpr &rhs)
 Assignment operator = with another expression, by copy. More...
 
LpExproperator= (LpExpr &&rhs)
 Assignment operator = with another expression, by move. More...
 
template<typename SCALAR >
LpExproperator= (const SCALAR &rhs)
 Assignment operator = with a scalar. More...
 
Compound assignment operators +=
LpExproperator+= (const LpCol &rhs)
 Compound assignment operator += with a variable. More...
 
LpExproperator+= (const LpExpr &rhs)
 Compound assignment operator += with another expression. More...
 
LpExproperator+= (LpExpr &&rhs)
 Compound assignment operator += with another temporary expression. More...
 
template<typename T >
LpExproperator+= (const T &rhs)
 Compound assignment operator += with a scalar. More...
 
Compound assignment operators -=
LpExproperator-= (const LpCol &rhs)
 Compound assignment operator -= with a variable. More...
 
LpExproperator-= (const LpExpr &rhs)
 Compound assignment operator -= with another expression. More...
 
template<typename T >
LpExproperator-= (const T &rhs)
 Compound assignment operator -= with a salar. More...
 

Static Public Member Functions

Helper static methods for operations
template<typename T1 , typename T2 >
static LpExpr lessThan (T1 &&lhs, T2 &&rhs)
 
template<typename SCALAR >
static LpExpr multiply (const SCALAR &lhs, const LpCol &rhs)
 

Friends

class LpRow
 
template<typename GUM_SCALAR >
class LpInterface
 

Detailed Description

Class representing a linear expression.

Author
Matthieu HOURBRACQ and Pierre-Henri WUILLEMIN()

Definition at line 208 of file LpInterface.h.

Constructor & Destructor Documentation

◆ LpExpr() [1/5]

gum::credal::lp::LpExpr::LpExpr ( )

Default constructor.

class LpExpr

Definition at line 63 of file LpInterface.cpp.

63  :
64  _ileft_(false), _imiddle_(false), _iright_(false), _lValue_(0.), _mValue_(0.),
65  _rValue_(0.), _lCoeffs_(new HashTable< LpCol, double >()),
66  _mCoeffs_(new HashTable< LpCol, double >()), _rCoeffs_(new HashTable< LpCol, double >()) {
67  GUM_CONSTRUCTOR(LpExpr);
68  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
LpExpr()
Default constructor.
Definition: LpInterface.cpp:63
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

◆ LpExpr() [2/5]

gum::credal::lp::LpExpr::LpExpr ( const LpExpr expr)

Copy constructor.

Parameters
exprThe constant reference to the expression to copy.

Definition at line 70 of file LpInterface.cpp.

70  :
71  _ileft_(expr._ileft_), _imiddle_(expr._imiddle_), _iright_(expr._iright_),
72  _lValue_(expr._lValue_), _mValue_(expr._mValue_), _rValue_(expr._rValue_),
73  _lCoeffs_(new HashTable< LpCol, double >(*expr._lCoeffs_)),
74  _mCoeffs_(new HashTable< LpCol, double >(*expr._mCoeffs_)),
75  _rCoeffs_(new HashTable< LpCol, double >(*expr._rCoeffs_)) {
76  GUM_CONS_CPY(LpExpr);
77  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
LpExpr()
Default constructor.
Definition: LpInterface.cpp:63
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

◆ LpExpr() [3/5]

gum::credal::lp::LpExpr::LpExpr ( const LpExpr expr,
bool  copyLeft,
bool  copyMiddle,
bool  copyRight 
)

Copy constructor.

Makes a ( partial ) copy.

Parameters
exprThe constant reference to the expression to copy.
copyLeftTrue if we want to copy left side of expr, False otherwise.
copyMiddleTrue if we want to copy middle side of expr, False otherwise.
copyRightTrue if we want to copy right side of expr, False otherwise.

Definition at line 79 of file LpInterface.cpp.

79  :
80  _ileft_(false), _imiddle_(false), _iright_(false), _lValue_(0.), _mValue_(0.),
81  _rValue_(0.), _lCoeffs_(nullptr), _mCoeffs_(nullptr), _rCoeffs_(nullptr) {
82  if (copyLeft) {
83  _lCoeffs_ = new HashTable< LpCol, double >(*expr._lCoeffs_);
84  _lValue_ = expr._lValue_;
85  _ileft_ = true;
86  } else
87  _lCoeffs_ = new HashTable< LpCol, double >();
88 
89  if (copyMiddle) {
90  _mCoeffs_ = new HashTable< LpCol, double >(*expr._mCoeffs_);
91  _mValue_ = expr._mValue_;
92  _imiddle_ = true;
93  } else
94  _mCoeffs_ = new HashTable< LpCol, double >();
95 
96  if (copyRight) {
97  _rCoeffs_ = new HashTable< LpCol, double >(*expr._rCoeffs_);
98  _rValue_ = expr._rValue_;
99  _iright_ = true;
100  } else
101  _rCoeffs_ = new HashTable< LpCol, double >();
102 
103  GUM_CONS_CPY(LpExpr);
104  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
LpExpr()
Default constructor.
Definition: LpInterface.cpp:63
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

◆ LpExpr() [4/5]

gum::credal::lp::LpExpr::LpExpr ( LpExpr &&  expr)

Move copy constructor from temporary.

Swap ressources between the temporary expr and the caller instead of copying the temporary.

Parameters
exprThe temporary expression to move to this.

Definition at line 106 of file LpInterface.cpp.

106  :
107  _ileft_(expr._ileft_), _imiddle_(expr._imiddle_), _iright_(expr._iright_),
108  _lValue_(expr._lValue_), _mValue_(expr._mValue_), _rValue_(expr._rValue_),
109  _lCoeffs_(expr._lCoeffs_), _mCoeffs_(expr._mCoeffs_), _rCoeffs_(expr._rCoeffs_) {
110  expr._lCoeffs_ = nullptr;
111  expr._mCoeffs_ = nullptr;
112  expr._rCoeffs_ = nullptr;
113 
114  GUM_CONS_CPY(LpExpr);
115  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
LpExpr()
Default constructor.
Definition: LpInterface.cpp:63
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

◆ LpExpr() [5/5]

gum::credal::lp::LpExpr::LpExpr ( LpExpr &&  expr,
bool  copyLeft,
bool  copyMiddle,
bool  copyRight 
)

Move copy constructor from temporary.

Makes ( partial ) moves.

Warning
Proceed with care; partial moves are dangerous because the object being moved may still briefly exist after being moved and could be used afterward.
Parameters
exprThe temporary expression to ( partially ) move to this.
copyLeftTrue if we want to copy left side of expr, False otherwise.
copyMiddleTrue if we want to copy middle side of expr, False otherwise.
copyRightTrue if we want to copy right side of expr, False otherwise.

Definition at line 117 of file LpInterface.cpp.

117  :
118  _ileft_(false), _imiddle_(false), _iright_(false), _lValue_(0.), _mValue_(0.),
119  _rValue_(0.), _lCoeffs_(nullptr), _mCoeffs_(nullptr), _rCoeffs_(nullptr) {
120  if (copyLeft) {
121  swap(_lCoeffs_, expr._lCoeffs_);
122  _lValue_ = expr._lValue_;
123  _ileft_ = true;
124  } else
125  _lCoeffs_ = new HashTable< LpCol, double >();
126 
127  if (copyMiddle) {
128  swap(_mCoeffs_, expr._mCoeffs_);
129  _mValue_ = expr._mValue_;
130  _imiddle_ = true;
131  } else
132  _mCoeffs_ = new HashTable< LpCol, double >();
133 
134  if (copyRight) {
135  swap(_rCoeffs_, expr._rCoeffs_);
136  _rValue_ = expr._rValue_;
137  _iright_ = true;
138  } else
139  _rCoeffs_ = new HashTable< LpCol, double >();
140 
141  GUM_CONS_CPY(LpExpr);
142  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
LpExpr()
Default constructor.
Definition: LpInterface.cpp:63
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

◆ ~LpExpr()

gum::credal::lp::LpExpr::~LpExpr ( )

Default destructor.

Definition at line 144 of file LpInterface.cpp.

144  {
145  delete _lCoeffs_;
146  delete _mCoeffs_;
147  delete _rCoeffs_;
148 
149  GUM_DESTRUCTOR(LpExpr);
150  }
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
LpExpr()
Default constructor.
Definition: LpInterface.cpp:63
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

Member Function Documentation

◆ _addSide_() [1/4]

void gum::credal::lp::LpExpr::_addSide_ ( const LpCol from)
private

Set the side of the calling expression, from LEFT TO RIGHT : L <= M <= R.

Parameters
fromthe constant reference to the variable ( the side ) to put on the first empty side met, starting at left.

Definition at line 275 of file LpInterface.cpp.

275  {
276  if (!_ileft_) {
277  _lCoeffs_->insert(from, 1.);
278  _ileft_ = true;
279  } else if (!_imiddle_) {
280  _mCoeffs_->insert(from, 1.);
281  _imiddle_ = true;
282  } else if (!_iright_) {
283  _rCoeffs_->insert(from, 1.);
284  _iright_ = true;
285  } else
286  GUM_ERROR(OperationNotAllowed,
287  "LpExpr::setSide ( const LpCol & from "
288  ") : too many <= ; no free side");
289  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ _addSide_() [2/4]

void gum::credal::lp::LpExpr::_addSide_ ( const LpExpr from)
private

Copy an expression to a side of the calling expression, from LEFT TO RIGHT : L <= M <= R.

Parameters
fromthe constant reference to the expression ( the side ) to copy on the first empty side met, starting at left.

Definition at line 291 of file LpInterface.cpp.

291  {
292  if (_ileft_ && _iright_ && from._imiddle_)
293  GUM_ERROR(OperationNotAllowed,
294  "LpExpr::setSide ( const LpCol & from "
295  ") : too many <= ; no free side");
296 
298  if (!from._imiddle_) return;
299 
303  if (!from._ileft_ && !from._iright_) {
304  if (!_ileft_) {
305  *_lCoeffs_ = *from._mCoeffs_;
306  _lValue_ = from._mValue_;
307  _ileft_ = true;
308 
309  return;
310  } else if (!_imiddle_) {
311  *_mCoeffs_ = *from._mCoeffs_;
312  _mValue_ = from._mValue_;
313  _imiddle_ = true;
314 
315  return;
316  } else if (!_iright_) {
317  *_rCoeffs_ = *from._mCoeffs_;
318  _rValue_ = from._mValue_;
319  _iright_ = true;
320 
321  return;
322  } else
323  GUM_ERROR(OperationNotAllowed,
324  "LpExpr::setSide ( const LpCol & from ) "
325  ": too many <= ; no free side");
326  }
329  else if (from._ileft_ && !from._iright_) {
330  if (!_ileft_) {
331  *_lCoeffs_ = *from._lCoeffs_;
332  _lValue_ = from._lValue_;
333  _ileft_ = true;
334 
335  *_mCoeffs_ = *from._mCoeffs_;
336  _mValue_ = from._mValue_;
337  _imiddle_ = true;
338 
339  return;
340  } else if (!_imiddle_ && !_iright_) {
341  *_mCoeffs_ = *from._lCoeffs_;
342  _mValue_ = from._lValue_;
343  _imiddle_ = true;
344 
345  *_rCoeffs_ = *from._mCoeffs_;
346  _rValue_ = from._mValue_;
347  _iright_ = true;
348 
349  return;
350  } else
351  GUM_ERROR(OperationNotAllowed,
352  "LpExpr::setSide ( const LpCol & from ) "
353  ": too many <= ; no free side");
354  }
357  else if (from._ileft_ && from._iright_) {
358  if (_ileft_ || _imiddle_ || _iright_)
359  GUM_ERROR(OperationNotAllowed,
360  "LpExpr::setSide ( const LpCol & from ) "
361  ": too many <= ; no free side");
362 
363  *this = from;
364 
365  return;
366  } else
367  GUM_ERROR(OperationNotAllowed,
368  "LpExpr::setSide ( const LpCol & from "
369  ") : too many <= ; no free side");
370  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ _addSide_() [3/4]

void gum::credal::lp::LpExpr::_addSide_ ( LpExpr &&  from)
private

Move an expression to a side of the calling expression, from LEFT TO RIGHT : L <= M <= R.

Parameters
fromthe expression ( the side ) to move on the first empty side met, starting at left.

Definition at line 372 of file LpInterface.cpp.

372  {
374  if (_ileft_ && _iright_ && from._imiddle_)
375  GUM_ERROR(OperationNotAllowed,
376  "LpExpr::setSide ( const LpCol & from "
377  ") : too many <= ; no free side");
378 
380  if (!from._imiddle_) return;
381 
385  if (!from._ileft_ && !from._iright_) {
386  if (!_ileft_) {
388  swap(_lCoeffs_, from._mCoeffs_);
389  _lValue_ = from._mValue_;
390  _ileft_ = true;
391 
392  return;
393  } else if (!_imiddle_) {
395  swap(_mCoeffs_, from._mCoeffs_);
396  _mValue_ = from._mValue_;
397  _imiddle_ = true;
398 
399  return;
400  } else if (!_iright_) {
402  swap(_rCoeffs_, from._mCoeffs_);
403  _rValue_ = from._mValue_;
404  _iright_ = true;
405 
406  return;
407  } else
408  GUM_ERROR(OperationNotAllowed,
409  "LpExpr::setSide ( const LpCol & from ) "
410  ": too many <= ; no free side");
411  }
414  else if (from._ileft_ && !from._iright_) {
415  if (!_ileft_) {
417  swap(_lCoeffs_, from._lCoeffs_);
418  _lValue_ = from._lValue_;
419  _ileft_ = true;
420 
422  swap(_mCoeffs_, from._mCoeffs_);
423  _mValue_ = from._mValue_;
424  _imiddle_ = true;
425 
426  return;
427  } else if (!_imiddle_ && !_iright_) {
429  swap(_mCoeffs_, from._lCoeffs_);
430  _mValue_ = from._lValue_;
431  _imiddle_ = true;
432 
434  swap(_rCoeffs_, from._mCoeffs_);
435  _rValue_ = from._mValue_;
436  _iright_ = true;
437 
438  return;
439  } else
440  GUM_ERROR(OperationNotAllowed,
441  "LpExpr::setSide ( const LpCol & from ) "
442  ": too many <= ; no free side");
443  }
446  else if (from._ileft_ && from._iright_) {
447  if (_ileft_ || _imiddle_ || _iright_)
448  GUM_ERROR(OperationNotAllowed,
449  "LpExpr::setSide ( const LpCol & from ) "
450  ": too many <= ; no free side");
451 
452  *this = std::move(from);
453 
454  return;
455  } else
456  GUM_ERROR(OperationNotAllowed,
457  "LpExpr::setSide ( const LpCol & from "
458  ") : too many <= ; no free side");
459  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ _addSide_() [4/4]

template<typename SCALAR >
void gum::credal::lp::LpExpr::_addSide_ ( const SCALAR &  from)
private

Set the side of the calling expression, from LEFT TO RIGHT : L <= M <= R.

Template Parameters
SCALARA scalar type ( integer or float ( any precision ) ).
Parameters
fromthe constant reference to the scalar ( the side ) to put on the first empty side met, starting at left.

Definition at line 66 of file LpInterface_tpl.h.

66  {
67  if (!_ileft_) {
68  _lValue_ = from;
69  _ileft_ = true;
70  } else if (!_imiddle_) {
71  _mValue_ = from;
72  _imiddle_ = true;
73  } else if (!_iright_) {
74  _rValue_ = from;
75  _iright_ = true;
76  } else
77  GUM_ERROR(OperationNotAllowed,
78  "LpExpr::setSide ( const LpCol & from "
79  ") : too many <= ; no free side");
80  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ clear()

void gum::credal::lp::LpExpr::clear ( )

Clear all data of the calling expression as if it was constructed.

Definition at line 462 of file LpInterface.cpp.

462  {
463  _lCoeffs_->clear();
464  _mCoeffs_->clear();
465  _rCoeffs_->clear();
466 
467  _lValue_ = 0.;
468  _mValue_ = 0.;
469  _rValue_ = 0.;
470 
471  _ileft_ = false;
472  _imiddle_ = false;
473  _iright_ = false;
474  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

◆ lessThan() [1/2]

template<typename T1 , typename T2 >
static LpExpr gum::credal::lp::LpExpr::lessThan ( T1 &&  lhs,
T2 &&  rhs 
)
static

◆ lessThan() [2/2]

template<typename T1 , typename T2 >
INLINE LpExpr gum::credal::lp::LpExpr::lessThan ( T1 &&  lhs,
T2 &&  rhs 
)

Definition at line 490 of file LpInterface_tpl.h.

490  {
491  LpExpr expr;
492  expr._addSide_(std::forward< T1 >(lhs));
493  expr._addSide_(std::forward< T2 >(rhs));
494  return expr;
495  }
LpExpr()
Default constructor.
Definition: LpInterface.cpp:63

◆ multiply() [1/2]

template<typename SCALAR >
static LpExpr gum::credal::lp::LpExpr::multiply ( const SCALAR &  lhs,
const LpCol rhs 
)
static

◆ multiply() [2/2]

template<typename SCALAR >
INLINE LpExpr gum::credal::lp::LpExpr::multiply ( const SCALAR &  lhs,
const LpCol rhs 
)

Definition at line 471 of file LpInterface_tpl.h.

471  {
472  LpExpr expr;
473  expr._mCoeffs_->insert(rhs, lhs);
474  expr._imiddle_ = true;
475  return expr;
476  }
LpExpr()
Default constructor.
Definition: LpInterface.cpp:63

◆ operator+=() [1/4]

LpExpr & gum::credal::lp::LpExpr::operator+= ( const LpCol rhs)

Compound assignment operator += with a variable.

Parameters
rhsthe constant reference to the variable to add to the calling expression.
Returns
The reference of the calling expression.

Definition at line 200 of file LpInterface.cpp.

200  {
201  if (_ileft_ || _iright_)
202  GUM_ERROR(OperationNotAllowed, "expr::operator+= (expr) : <= present on one side of expr")
203 
204  if (!_imiddle_) _imiddle_ = true;
205 
206  _mCoeffs_->getWithDefault(rhs, 0.) += 1.;
207 
208  return *this;
209  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ operator+=() [2/4]

LpExpr & gum::credal::lp::LpExpr::operator+= ( const LpExpr rhs)

Compound assignment operator += with another expression.

Parameters
rhsthe constant reference to the expression to add to the calling expression.
Returns
The reference of the calling expression.

Definition at line 211 of file LpInterface.cpp.

211  {
212  if (_ileft_ || _iright_ || rhs._ileft_ || rhs._iright_)
213  GUM_ERROR(OperationNotAllowed,
214  "expr::operator+= (rhs) : <= present "
215  "on one side of rhs and/or expr");
216 
217  if (!_imiddle_) _imiddle_ = true;
218 
219  for (const auto& elt: *rhs._mCoeffs_)
220  _mCoeffs_->getWithDefault(elt.first, 0.) += elt.second;
221 
222  _mValue_ += rhs._mValue_;
223 
224  return *this;
225  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ operator+=() [3/4]

LpExpr & gum::credal::lp::LpExpr::operator+= ( LpExpr &&  rhs)

Compound assignment operator += with another temporary expression.

Parameters
rhsthe temporary expression to add to the calling expression.
Returns
The reference of the calling expression.

Definition at line 227 of file LpInterface.cpp.

227  {
228  if (_ileft_ || _iright_ || rhs._ileft_ || rhs._iright_)
229  GUM_ERROR(OperationNotAllowed,
230  "expr::operator+= (rhs) : <= present "
231  "on one side of rhs and/or expr");
232 
233  if (!_imiddle_) {
234  _imiddle_ = true;
235  _mValue_ = rhs._mValue_;
236  swap(_mCoeffs_, rhs._mCoeffs_);
237 
238  return *this;
239  }
240 
241  for (const auto& elt: *rhs._mCoeffs_)
242  _mCoeffs_->getWithDefault(elt.first, 0.) += elt.second;
243  _mValue_ += rhs._mValue_;
244 
245  return *this;
246  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ operator+=() [4/4]

template<typename T >
LpExpr & gum::credal::lp::LpExpr::operator+= ( const T &  rhs)

Compound assignment operator += with a scalar.

Template Parameters
SCALARA scalar type ( integer or float ( any precision ) ).
Parameters
rhsthe constant reference to the scalar to add to the calling expression.
Returns
The reference of the calling expression.

Definition at line 42 of file LpInterface_tpl.h.

42  {
43  if (_ileft_ || _iright_)
44  GUM_ERROR(OperationNotAllowed, "expr::operator+= (expr) : <= present on one side of expr")
45 
46  if (!_imiddle_) _imiddle_ = true;
47 
48  _mValue_ += rhs;
49 
50  return *this;
51  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ operator-=() [1/3]

LpExpr & gum::credal::lp::LpExpr::operator-= ( const LpCol rhs)

Compound assignment operator -= with a variable.

Parameters
rhsthe constant reference to the variable to substract from the calling expression.
Returns
The reference of the calling expression.

Definition at line 248 of file LpInterface.cpp.

248  {
249  if (_ileft_ || _iright_)
250  GUM_ERROR(OperationNotAllowed, "expr::operator-= (rhs) : <= present in one of expr")
251 
252  if (!_imiddle_) _imiddle_ = true;
253 
254  _mCoeffs_->getWithDefault(rhs, 0.) -= 1.;
255 
256  return *this;
257  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ operator-=() [2/3]

LpExpr & gum::credal::lp::LpExpr::operator-= ( const LpExpr rhs)

Compound assignment operator -= with another expression.

Parameters
rhsthe constant reference to the expression to substract from the calling expression.
Returns
The reference of the calling expression.

Definition at line 259 of file LpInterface.cpp.

259  {
260  if (_ileft_ || _iright_ || rhs._ileft_ || rhs._iright_)
261  GUM_ERROR(OperationNotAllowed,
262  "expr::operator-= (rhs) : <= present in one of rhs and/or expr");
263 
264  if (!_imiddle_) _imiddle_ = true;
265 
266  for (const auto& elt: *rhs._mCoeffs_)
267  _mCoeffs_->getWithDefault(elt.first, 0.) -= elt.second;
268 
269  _mValue_ -= rhs._mValue_;
270 
271  return *this;
272  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ operator-=() [3/3]

template<typename T >
LpExpr & gum::credal::lp::LpExpr::operator-= ( const T &  rhs)

Compound assignment operator -= with a salar.

Template Parameters
SCALARA scalar type ( integer or float ( any precision ) ).
Parameters
rhsthe constant reference to the scalar to substract from the calling expression.
Returns
The reference of the calling expression.

Definition at line 54 of file LpInterface_tpl.h.

54  {
55  if (_ileft_ || _iright_)
56  GUM_ERROR(OperationNotAllowed, "expr::operator-= (rhs) : <= present in one of expr")
57 
58  if (!_imiddle_) _imiddle_ = true;
59 
60  _mValue_ -= rhs;
61 
62  return *this;
63  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ operator=() [1/4]

LpExpr & gum::credal::lp::LpExpr::operator= ( const LpCol rhs)

Assignment operator = with a variable.

Parameters
rhsthe constant reference to the variable to form an expression with.
Returns
The address of the calling expression.

Definition at line 152 of file LpInterface.cpp.

152  {
153  clear();
154 
155  _mCoeffs_->insert(rhs, 1.);
156  _imiddle_ = true;
157 
158  return *this;
159  }
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
void clear()
Clear all data of the calling expression as if it was constructed.

◆ operator=() [2/4]

LpExpr & gum::credal::lp::LpExpr::operator= ( const LpExpr rhs)

Assignment operator = with another expression, by copy.

Parameters
rhsthe constant reference to the expression to copy.
Returns
The address of the calling expression.

Definition at line 161 of file LpInterface.cpp.

161  {
163  if (this == &rhs) return *this;
164 
165  *_lCoeffs_ = *rhs._lCoeffs_;
166  *_mCoeffs_ = *rhs._mCoeffs_;
167  *_rCoeffs_ = *rhs._rCoeffs_;
168 
169  _lValue_ = rhs._lValue_;
170  _mValue_ = rhs._mValue_;
171  _rValue_ = rhs._rValue_;
172 
173  _ileft_ = rhs._ileft_;
174  _imiddle_ = rhs._imiddle_;
175  _iright_ = rhs._iright_;
176 
177  return *this;
178  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

◆ operator=() [3/4]

LpExpr & gum::credal::lp::LpExpr::operator= ( LpExpr &&  rhs)

Assignment operator = with another expression, by move.

Parameters
rhsthe expression to move to this.
Returns
The address of the calling expression.

Definition at line 180 of file LpInterface.cpp.

180  {
182  if (this == &rhs) return *this;
183 
184  swap(_lCoeffs_, rhs._lCoeffs_);
185  swap(_mCoeffs_, rhs._mCoeffs_);
186  swap(_rCoeffs_, rhs._rCoeffs_);
187 
188  _lValue_ = rhs._lValue_;
189  _mValue_ = rhs._mValue_;
190  _rValue_ = rhs._rValue_;
191 
192  _ileft_ = rhs._ileft_;
193  _imiddle_ = rhs._imiddle_;
194  _iright_ = rhs._iright_;
195 
196  return *this;
197  }
bool _ileft_
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:413
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
bool _iright_
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:421
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

◆ operator=() [4/4]

template<typename SCALAR >
LpExpr & gum::credal::lp::LpExpr::operator= ( const SCALAR &  rhs)

Assignment operator = with a scalar.

class LpExpr

Template Parameters
SCALARA scalar type ( integer or float ( any precision ) ).
Parameters
rhsthe constant reference to the scalar to form an expression with.
Returns
The address of the calling expression.

Definition at line 32 of file LpInterface_tpl.h.

32  {
33  clear();
34 
35  _mValue_ = rhs;
36  _imiddle_ = true;
37 
38  return *this;
39  }
bool _imiddle_
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:417
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
void clear()
Clear all data of the calling expression as if it was constructed.

◆ toString()

std::string gum::credal::lp::LpExpr::toString ( ) const

Get the string representation of a calling expression.

Returns
The string representation of the calling expression.

Definition at line 476 of file LpInterface.cpp.

476  {
477  std::ostringstream s;
478 
479  s << std::endl << "left side : " << std::endl;
480 
481  if (_lCoeffs_ != nullptr)
482  for (const auto& elt: *_lCoeffs_)
483  s << elt.first.toString() << " " << elt.second << " | ";
484 
485  s << std::endl << "middle side : " << std::endl;
486 
487  if (_mCoeffs_ != nullptr)
488  for (const auto& elt: *_mCoeffs_)
489  s << elt.first.toString() << " " << elt.second << " | ";
490 
491  s << std::endl << "right side : " << std::endl;
492 
493  if (_rCoeffs_ != nullptr)
494  for (const auto& elt: *_rCoeffs_)
495  s << elt.first.toString() << " " << elt.second << " | ";
496 
497  s << std::endl
498  << "lvalue : " << _lValue_ << std::endl
499  << "mvalue : " << _mValue_ << std::endl
500  << "rvalue : " << _rValue_ << std::endl;
501 
502  s << std::endl;
503 
504  return s.str();
505  }
HashTable< LpCol, double > * _mCoeffs_
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:437
double _rValue_
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:428
double _mValue_
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:426
double _lValue_
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:424
HashTable< LpCol, double > * _rCoeffs_
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:441
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:433

Friends And Related Function Documentation

◆ LpInterface

template<typename GUM_SCALAR >
friend class LpInterface
friend

Definition at line 211 of file LpInterface.h.

◆ LpRow

friend class LpRow
friend

Definition at line 209 of file LpInterface.h.

Member Data Documentation

◆ _ileft_

bool gum::credal::lp::LpExpr::_ileft_
private

True if this expression has a non-empty left side L : L <= M <= R .

False otherwise.

Definition at line 413 of file LpInterface.h.

◆ _imiddle_

bool gum::credal::lp::LpExpr::_imiddle_
private

True if this expression has a non-empty middle side M ( the default ) : L <= M <= R .

False otherwise.

Definition at line 417 of file LpInterface.h.

◆ _iright_

bool gum::credal::lp::LpExpr::_iright_
private

True if this expression has a non-empty right side R : L <= M <= R .

False otherwise.

Definition at line 421 of file LpInterface.h.

◆ _lCoeffs_

HashTable< LpCol, double >* gum::credal::lp::LpExpr::_lCoeffs_
private

The coefficients of each variable on the left side L : L <= M <= R.

If a variable is not present, it's coefficient is 0.

Definition at line 433 of file LpInterface.h.

◆ _lValue_

double gum::credal::lp::LpExpr::_lValue_
private

The constant on the left side L : L <= M <= R.

Definition at line 424 of file LpInterface.h.

◆ _mCoeffs_

HashTable< LpCol, double >* gum::credal::lp::LpExpr::_mCoeffs_
private

The coefficients of each variable on the middle side L : L <= M <= R.

If a variable is not present, it's coefficient is 0.

Definition at line 437 of file LpInterface.h.

◆ _mValue_

double gum::credal::lp::LpExpr::_mValue_
private

The constant on the middle side L : L <= M <= R.

Definition at line 426 of file LpInterface.h.

◆ _rCoeffs_

HashTable< LpCol, double >* gum::credal::lp::LpExpr::_rCoeffs_
private

The coefficients of each variable on the right side L : L <= M <= R.

If a variable is not present, it's coefficient is 0.

Definition at line 441 of file LpInterface.h.

◆ _rValue_

double gum::credal::lp::LpExpr::_rValue_
private

The constant on the right side L : L <= M <= R.

Definition at line 428 of file LpInterface.h.


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