aGrUM 3.2.0
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:
[legend]

Public Member Functions

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

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)

Private Member Functions

Used by static method LpExpr::LessThan<T1,T2> and by operator

<=

void _addSide_ (const LpCol &from)
 Set the side of the calling expression, from LEFT TO RIGHT : L <= M <= R.
void _addSide_ (const LpExpr &from)
 Copy an expression to a side of the calling expression, from LEFT TO RIGHT : L <= M <= R.
void _addSide_ (LpExpr &&from)
 Move an expression to a side of the calling expression, from LEFT TO RIGHT : L <= M <= R.
template<typename SCALAR>
void _addSide_ (const SCALAR &from)
 Set the side of the calling expression, from LEFT TO RIGHT : L <= M <= R.

Private Attributes

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 .
bool _iright_
 True if this expression has a non-empty right side R : L <= M <= R .
double _lValue_
 The constant on the left side L : L <= M <= R.
double _mValue_
 The constant on the middle side L : L <= M <= R.
double _rValue_
 The constant on the right side L : L <= M <= R.
HashTable< LpCol, double > * _lCoeffs_
 The coefficients of each variable on the left side L : L <= M <= R.
HashTable< LpCol, double > * _mCoeffs_
 The coefficients of each variable on the middle side L : L <= M <= R.
HashTable< LpCol, double > * _rCoeffs_
 The coefficients of each variable on the right side L : L <= M <= R.

Friends

class LpRow
template<GUM_Numeric GUM_SCALAR>
class LpInterface

Detailed Description

Class representing a linear expression.

Author
Matthieu HOURBRACQ and Pierre-Henri WUILLEMIN(_at_LIP6)

Definition at line 229 of file LpInterface.h.

Constructor & Destructor Documentation

◆ LpExpr() [1/5]

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

Default constructor.

class LpExpr

Definition at line 83 of file LpInterface.cpp.

83 :
84 _ileft_(false), _imiddle_(false), _iright_(false), _lValue_(0.), _mValue_(0.),
85 _rValue_(0.), _lCoeffs_(new HashTable< LpCol, double >()),
86 _mCoeffs_(new HashTable< LpCol, double >()), _rCoeffs_(new HashTable< LpCol, double >()) {
87 GUM_CONSTRUCTOR(LpExpr);
88 }
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 .
HashTable< LpCol, double > * _lCoeffs_
The coefficients of each variable on the left side L : L <= M <= R.
LpExpr()
Default constructor.
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.
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.

References LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, and _rValue_.

Referenced by LpExpr(), LpExpr(), LpExpr(), LpExpr(), LpExpr(), ~LpExpr(), _addSide_(), _addSide_(), lessThan(), LpInterface, multiply(), operator+=(), operator+=(), operator+=(), operator+=(), operator-=(), operator-=(), operator-=(), operator=(), operator=(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 90 of file LpInterface.cpp.

90 :
91 _ileft_(expr._ileft_), _imiddle_(expr._imiddle_), _iright_(expr._iright_),
92 _lValue_(expr._lValue_), _mValue_(expr._mValue_), _rValue_(expr._rValue_),
93 _lCoeffs_(new HashTable< LpCol, double >(*expr._lCoeffs_)),
94 _mCoeffs_(new HashTable< LpCol, double >(*expr._mCoeffs_)),
95 _rCoeffs_(new HashTable< LpCol, double >(*expr._rCoeffs_)) {
96 GUM_CONS_CPY(LpExpr);
97 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, and _rValue_.

Here is the call graph for this function:

◆ 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 99 of file LpInterface.cpp.

99 :
100 _ileft_(false), _imiddle_(false), _iright_(false), _lValue_(0.), _mValue_(0.),
101 _rValue_(0.), _lCoeffs_(nullptr), _mCoeffs_(nullptr), _rCoeffs_(nullptr) {
102 if (copyLeft) {
103 _lCoeffs_ = new HashTable< LpCol, double >(*expr._lCoeffs_);
104 _lValue_ = expr._lValue_;
105 _ileft_ = true;
107
108 if (copyMiddle) {
109 _mCoeffs_ = new HashTable< LpCol, double >(*expr._mCoeffs_);
110 _mValue_ = expr._mValue_;
111 _imiddle_ = true;
113
114 if (copyRight) {
115 _rCoeffs_ = new HashTable< LpCol, double >(*expr._rCoeffs_);
116 _rValue_ = expr._rValue_;
117 _iright_ = true;
119
120 GUM_CONS_CPY(LpExpr);
121 }
HashTable(Size size_param=HashTableConst::default_size, bool resize_pol=HashTableConst::default_resize_policy, bool key_uniqueness_pol=HashTableConst::default_uniqueness_policy)
Default constructor.

References gum::HashTable< Key, Val >::HashTable(), LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, and _rValue_.

Here is the call graph for this function:

◆ 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 123 of file LpInterface.cpp.

123 :
124 _ileft_(expr._ileft_), _imiddle_(expr._imiddle_), _iright_(expr._iright_),
125 _lValue_(expr._lValue_), _mValue_(expr._mValue_), _rValue_(expr._rValue_),
126 _lCoeffs_(expr._lCoeffs_), _mCoeffs_(expr._mCoeffs_), _rCoeffs_(expr._rCoeffs_) {
127 expr._lCoeffs_ = nullptr;
128 expr._mCoeffs_ = nullptr;
129 expr._rCoeffs_ = nullptr;
130
131 GUM_CONS_CPY(LpExpr);
132 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, and _rValue_.

Here is the call graph for this function:

◆ 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 134 of file LpInterface.cpp.

134 :
135 _ileft_(false), _imiddle_(false), _iright_(false), _lValue_(0.), _mValue_(0.),
136 _rValue_(0.), _lCoeffs_(nullptr), _mCoeffs_(nullptr), _rCoeffs_(nullptr) {
137 if (copyLeft) {
138 swap(_lCoeffs_, expr._lCoeffs_);
139 _lValue_ = expr._lValue_;
140 _ileft_ = true;
142
143 if (copyMiddle) {
144 swap(_mCoeffs_, expr._mCoeffs_);
145 _mValue_ = expr._mValue_;
146 _imiddle_ = true;
148
149 if (copyRight) {
150 swap(_rCoeffs_, expr._rCoeffs_);
151 _rValue_ = expr._rValue_;
152 _iright_ = true;
154
155 GUM_CONS_CPY(LpExpr);
156 }
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.

References gum::HashTable< Key, Val >::HashTable(), LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, _rValue_, and gum::credal::lp::swap().

Here is the call graph for this function:

◆ ~LpExpr()

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

Default destructor.

Definition at line 158 of file LpInterface.cpp.

158 {
159 delete _lCoeffs_;
160 delete _mCoeffs_;
161 delete _rCoeffs_;
162
163 GUM_DESTRUCTOR(LpExpr);
164 }

References LpExpr(), _lCoeffs_, _mCoeffs_, and _rCoeffs_.

Here is the call graph for this function:

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 287 of file LpInterface.cpp.

287 {
288 if (!_ileft_) {
289 _lCoeffs_->insert(from, 1.);
290 _ileft_ = true;
291 } else if (!_imiddle_) {
292 _mCoeffs_->insert(from, 1.);
293 _imiddle_ = true;
294 } else if (!_iright_) {
295 _rCoeffs_->insert(from, 1.);
296 _iright_ = true;
297 } else
298 GUM_ERROR(OperationNotAllowed,
299 "LpExpr::setSide ( const LpCol & from "
300 ") : too many <= ; no free side");
301 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References _ileft_, _imiddle_, _iright_, _lCoeffs_, _mCoeffs_, _rCoeffs_, and GUM_ERROR.

Referenced by lessThan().

Here is the caller graph for this function:

◆ _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 303 of file LpInterface.cpp.

303 {
304 if (_ileft_ && _iright_ && from._imiddle_)
305 GUM_ERROR(OperationNotAllowed,
306 "LpExpr::setSide ( const LpCol & from "
307 ") : too many <= ; no free side");
308
310 if (!from._imiddle_) return;
311
315 if (!from._ileft_ && !from._iright_) {
316 if (!_ileft_) {
317 *_lCoeffs_ = *from._mCoeffs_;
318 _lValue_ = from._mValue_;
319 _ileft_ = true;
320
321 return;
322 } else if (!_imiddle_) {
323 *_mCoeffs_ = *from._mCoeffs_;
324 _mValue_ = from._mValue_;
325 _imiddle_ = true;
326
327 return;
328 } else if (!_iright_) {
329 *_rCoeffs_ = *from._mCoeffs_;
330 _rValue_ = from._mValue_;
331 _iright_ = true;
332
333 return;
334 } else
335 GUM_ERROR(OperationNotAllowed,
336 "LpExpr::setSide ( const LpCol & from ) "
337 ": too many <= ; no free side");
338 }
341 else if (from._ileft_ && !from._iright_) {
342 if (!_ileft_) {
343 *_lCoeffs_ = *from._lCoeffs_;
344 _lValue_ = from._lValue_;
345 _ileft_ = true;
346
347 *_mCoeffs_ = *from._mCoeffs_;
348 _mValue_ = from._mValue_;
349 _imiddle_ = true;
350
351 return;
352 } else if (!_imiddle_ && !_iright_) {
353 *_mCoeffs_ = *from._lCoeffs_;
354 _mValue_ = from._lValue_;
355 _imiddle_ = true;
356
357 *_rCoeffs_ = *from._mCoeffs_;
358 _rValue_ = from._mValue_;
359 _iright_ = true;
360
361 return;
362 } else
363 GUM_ERROR(OperationNotAllowed,
364 "LpExpr::setSide ( const LpCol & from ) "
365 ": too many <= ; no free side");
366 }
369 else if (from._ileft_ && from._iright_) {
370 if (_ileft_ || _imiddle_ || _iright_)
371 GUM_ERROR(OperationNotAllowed,
372 "LpExpr::setSide ( const LpCol & from ) "
373 ": too many <= ; no free side");
374
375 *this = from;
376
377 return;
378 } else
379 GUM_ERROR(OperationNotAllowed,
380 "LpExpr::setSide ( const LpCol & from "
381 ") : too many <= ; no free side");
382 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, _rValue_, and GUM_ERROR.

Here is the call graph for this function:

◆ _addSide_() [3/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 90 of file LpInterface_tpl.h.

90 {
91 if (!_ileft_) {
92 _lValue_ = from;
93 _ileft_ = true;
94 } else if (!_imiddle_) {
95 _mValue_ = from;
96 _imiddle_ = true;
97 } else if (!_iright_) {
98 _rValue_ = from;
99 _iright_ = true;
100 } else
101 GUM_ERROR(OperationNotAllowed,
102 "LpExpr::setSide ( const LpCol & from "
103 ") : too many <= ; no free side");
104 }

References _ileft_, _imiddle_, _iright_, _lValue_, _mValue_, _rValue_, and GUM_ERROR.

◆ _addSide_() [4/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 384 of file LpInterface.cpp.

384 {
386 if (_ileft_ && _iright_ && from._imiddle_)
387 GUM_ERROR(OperationNotAllowed,
388 "LpExpr::setSide ( const LpCol & from "
389 ") : too many <= ; no free side");
390
392 if (!from._imiddle_) return;
393
397 if (!from._ileft_ && !from._iright_) {
398 if (!_ileft_) {
400 swap(_lCoeffs_, from._mCoeffs_);
401 _lValue_ = from._mValue_;
402 _ileft_ = true;
403
404 return;
405 } else if (!_imiddle_) {
407 swap(_mCoeffs_, from._mCoeffs_);
408 _mValue_ = from._mValue_;
409 _imiddle_ = true;
410
411 return;
412 } else if (!_iright_) {
414 swap(_rCoeffs_, from._mCoeffs_);
415 _rValue_ = from._mValue_;
416 _iright_ = true;
417
418 return;
419 } else
420 GUM_ERROR(OperationNotAllowed,
421 "LpExpr::setSide ( const LpCol & from ) "
422 ": too many <= ; no free side");
423 }
426 else if (from._ileft_ && !from._iright_) {
427 if (!_ileft_) {
429 swap(_lCoeffs_, from._lCoeffs_);
430 _lValue_ = from._lValue_;
431 _ileft_ = true;
432
434 swap(_mCoeffs_, from._mCoeffs_);
435 _mValue_ = from._mValue_;
436 _imiddle_ = true;
437
438 return;
439 } else if (!_imiddle_ && !_iright_) {
441 swap(_mCoeffs_, from._lCoeffs_);
442 _mValue_ = from._lValue_;
443 _imiddle_ = true;
444
446 swap(_rCoeffs_, from._mCoeffs_);
447 _rValue_ = from._mValue_;
448 _iright_ = true;
449
450 return;
451 } else
452 GUM_ERROR(OperationNotAllowed,
453 "LpExpr::setSide ( const LpCol & from ) "
454 ": too many <= ; no free side");
455 }
458 else if (from._ileft_ && from._iright_) {
459 if (_ileft_ || _imiddle_ || _iright_)
460 GUM_ERROR(OperationNotAllowed,
461 "LpExpr::setSide ( const LpCol & from ) "
462 ": too many <= ; no free side");
463
464 *this = std::move(from);
465
466 return;
467 } else
468 GUM_ERROR(OperationNotAllowed,
469 "LpExpr::setSide ( const LpCol & from "
470 ") : too many <= ; no free side");
471 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, _rValue_, GUM_ERROR, and gum::credal::lp::swap().

Here is the call graph for this function:

◆ clear()

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

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

Definition at line 473 of file LpInterface.cpp.

473 {
474 _lCoeffs_->clear();
475 _mCoeffs_->clear();
476 _rCoeffs_->clear();
477
478 _lValue_ = 0.;
479 _mValue_ = 0.;
480 _rValue_ = 0.;
481
482 _ileft_ = false;
483 _imiddle_ = false;
484 _iright_ = false;
485 }

References _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, and _rValue_.

Referenced by LpInterface, operator=(), and operator=().

Here is the caller graph for this function:

◆ lessThan()

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

Definition at line 514 of file LpInterface_tpl.h.

514 {
515 LpExpr expr;
516 expr._addSide_(std::forward< T1 >(lhs));
517 expr._addSide_(std::forward< T2 >(rhs));
518 return expr;
519 }

References LpExpr(), and _addSide_().

Referenced by LpInterface, gum::credal::lp::operator<=(), gum::credal::lp::operator<=(), gum::credal::lp::operator<=(), gum::credal::lp::operator<=(), gum::credal::lp::operator<=(), gum::credal::lp::operator<=(), gum::credal::lp::operator<=(), and gum::credal::lp::operator<=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ multiply()

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

Definition at line 495 of file LpInterface_tpl.h.

495 {
496 LpExpr expr;
497 expr._mCoeffs_->insert(rhs, lhs);
498 expr._imiddle_ = true;
499 return expr;
500 }

References LpExpr(), _imiddle_, and _mCoeffs_.

Referenced by LpInterface, gum::credal::lp::operator*(), and gum::credal::lp::operator*().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 213 of file LpInterface.cpp.

213 {
214 if (_ileft_ || _iright_)
215 GUM_ERROR(OperationNotAllowed, "expr::operator+= (expr) : <= present on one side of expr")
216
217 if (!_imiddle_) _imiddle_ = true;
218
219 _mCoeffs_->getWithDefault(rhs, 0.) += 1.;
220
221 return *this;
222 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _mCoeffs_, and GUM_ERROR.

Referenced by LpInterface.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 224 of file LpInterface.cpp.

224 {
225 if (_ileft_ || _iright_ || rhs._ileft_ || rhs._iright_)
226 GUM_ERROR(OperationNotAllowed,
227 "expr::operator+= (rhs) : <= present "
228 "on one side of rhs and/or expr");
229
230 if (!_imiddle_) _imiddle_ = true;
231
232 for (const auto& elt: *rhs._mCoeffs_)
233 _mCoeffs_->getWithDefault(elt.first, 0.) += elt.second;
234
235 _mValue_ += rhs._mValue_;
236
237 return *this;
238 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _mCoeffs_, _mValue_, and GUM_ERROR.

Here is the call graph for this function:

◆ operator+=() [3/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 66 of file LpInterface_tpl.h.

66 {
67 if (_ileft_ || _iright_)
68 GUM_ERROR(OperationNotAllowed, "expr::operator+= (expr) : <= present on one side of expr")
69
70 if (!_imiddle_) _imiddle_ = true;
71
72 _mValue_ += rhs;
73
74 return *this;
75 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _mValue_, and GUM_ERROR.

Here is the call graph for this function:

◆ operator+=() [4/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 240 of file LpInterface.cpp.

240 {
241 if (_ileft_ || _iright_ || rhs._ileft_ || rhs._iright_)
242 GUM_ERROR(OperationNotAllowed,
243 "expr::operator+= (rhs) : <= present "
244 "on one side of rhs and/or expr");
245
246 if (!_imiddle_) {
247 _imiddle_ = true;
248 _mValue_ = rhs._mValue_;
249 swap(_mCoeffs_, rhs._mCoeffs_);
250
251 return *this;
252 }
253
254 for (const auto& elt: *rhs._mCoeffs_)
255 _mCoeffs_->getWithDefault(elt.first, 0.) += elt.second;
256 _mValue_ += rhs._mValue_;
257
258 return *this;
259 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _mCoeffs_, _mValue_, GUM_ERROR, and gum::credal::lp::swap().

Here is the call graph for this function:

◆ 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 subtract from the calling expression.
Returns
The reference of the calling expression.

Definition at line 261 of file LpInterface.cpp.

261 {
262 if (_ileft_ || _iright_)
263 GUM_ERROR(OperationNotAllowed, "expr::operator-= (rhs) : <= present in one of expr")
264
265 if (!_imiddle_) _imiddle_ = true;
266
267 _mCoeffs_->getWithDefault(rhs, 0.) -= 1.;
268
269 return *this;
270 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _mCoeffs_, and GUM_ERROR.

Referenced by LpInterface.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 subtract from the calling expression.
Returns
The reference of the calling expression.

Definition at line 272 of file LpInterface.cpp.

272 {
273 if (_ileft_ || _iright_ || rhs._ileft_ || rhs._iright_)
274 GUM_ERROR(OperationNotAllowed,
275 "expr::operator-= (rhs) : <= present in one of rhs and/or expr");
276
277 if (!_imiddle_) _imiddle_ = true;
278
279 for (const auto& elt: *rhs._mCoeffs_)
280 _mCoeffs_->getWithDefault(elt.first, 0.) -= elt.second;
281
282 _mValue_ -= rhs._mValue_;
283
284 return *this;
285 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _mCoeffs_, _mValue_, and GUM_ERROR.

Here is the call graph for this function:

◆ 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 subtract from the calling expression.
Returns
The reference of the calling expression.

Definition at line 78 of file LpInterface_tpl.h.

78 {
79 if (_ileft_ || _iright_)
80 GUM_ERROR(OperationNotAllowed, "expr::operator-= (rhs) : <= present in one of expr")
81
82 if (!_imiddle_) _imiddle_ = true;
83
84 _mValue_ -= rhs;
85
86 return *this;
87 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _mValue_, and GUM_ERROR.

Here is the call graph for this function:

◆ 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 166 of file LpInterface.cpp.

166 {
167 clear();
168
169 _mCoeffs_->insert(rhs, 1.);
170 _imiddle_ = true;
171
172 return *this;
173 }
void clear()
Clear all data of the calling expression as if it was constructed.

References LpExpr(), _imiddle_, _mCoeffs_, and clear().

Referenced by LpInterface.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 175 of file LpInterface.cpp.

175 {
177 if (this == &rhs) return *this;
178
179 *_lCoeffs_ = *rhs._lCoeffs_;
180 *_mCoeffs_ = *rhs._mCoeffs_;
181 *_rCoeffs_ = *rhs._rCoeffs_;
182
183 _lValue_ = rhs._lValue_;
184 _mValue_ = rhs._mValue_;
185 _rValue_ = rhs._rValue_;
186
187 _ileft_ = rhs._ileft_;
188 _imiddle_ = rhs._imiddle_;
189 _iright_ = rhs._iright_;
190
191 return *this;
192 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, and _rValue_.

Here is the call graph for this function:

◆ operator=() [3/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 56 of file LpInterface_tpl.h.

56 {
57 clear();
58
59 _mValue_ = rhs;
60 _imiddle_ = true;
61
62 return *this;
63 }

References LpExpr(), _imiddle_, _mValue_, and clear().

Here is the call graph for this function:

◆ operator=() [4/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 194 of file LpInterface.cpp.

194 {
196 if (this == &rhs) return *this;
197
198 swap(_lCoeffs_, rhs._lCoeffs_);
199 swap(_mCoeffs_, rhs._mCoeffs_);
200 swap(_rCoeffs_, rhs._rCoeffs_);
201
202 _lValue_ = rhs._lValue_;
203 _mValue_ = rhs._mValue_;
204 _rValue_ = rhs._rValue_;
205
206 _ileft_ = rhs._ileft_;
207 _imiddle_ = rhs._imiddle_;
208 _iright_ = rhs._iright_;
209
210 return *this;
211 }

References LpExpr(), _ileft_, _imiddle_, _iright_, _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, _rValue_, and gum::credal::lp::swap().

Here is the call graph for this function:

◆ 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 487 of file LpInterface.cpp.

487 {
488 std::string s = "\nleft side : \n";
489
490 if (_lCoeffs_ != nullptr)
491 for (const auto& elt: *_lCoeffs_)
492 s += std::format("{} {} | ", elt.first.toString(), elt.second);
493
494 s += "\nmiddle side : \n";
495
496 if (_mCoeffs_ != nullptr)
497 for (const auto& elt: *_mCoeffs_)
498 s += std::format("{} {} | ", elt.first.toString(), elt.second);
499
500 s += "\nright side : \n";
501
502 if (_rCoeffs_ != nullptr)
503 for (const auto& elt: *_rCoeffs_)
504 s += std::format("{} {} | ", elt.first.toString(), elt.second);
505
506 s += std::format("\nlvalue : {}\nmvalue : {}\nrvalue : {}\n\n",
507 _lValue_,
508 _mValue_,
509 _rValue_);
510
511 return s;
512 }

References _lCoeffs_, _lValue_, _mCoeffs_, _mValue_, _rCoeffs_, and _rValue_.

Referenced by gum::credal::lp::LpInterface< GUM_SCALAR >::addRow(), and LpInterface.

Here is the caller graph for this function:

◆ LpInterface

template<GUM_Numeric GUM_SCALAR>
friend class LpInterface
friend

Definition at line 232 of file LpInterface.h.

References LpExpr(), clear(), lessThan(), LpInterface, multiply(), operator+=(), operator-=(), operator=(), and toString().

Referenced by LpInterface.

◆ LpRow

friend class LpRow
friend

Definition at line 230 of file LpInterface.h.

References LpRow.

Referenced by LpRow.

Member Data Documentation

◆ _ileft_

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

◆ _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 439 of file LpInterface.h.

Referenced by LpExpr(), LpExpr(), LpExpr(), LpExpr(), LpExpr(), _addSide_(), _addSide_(), _addSide_(), _addSide_(), gum::credal::lp::LpInterface< GUM_SCALAR >::addRow(), clear(), multiply(), operator+=(), operator+=(), operator+=(), operator+=(), operator-=(), operator-=(), operator-=(), operator=(), operator=(), operator=(), and operator=().

◆ _iright_

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

◆ _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 455 of file LpInterface.h.

Referenced by LpExpr(), LpExpr(), LpExpr(), LpExpr(), LpExpr(), ~LpExpr(), _addSide_(), _addSide_(), _addSide_(), clear(), operator=(), operator=(), and toString().

◆ _lValue_

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

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

Definition at line 446 of file LpInterface.h.

Referenced by LpExpr(), LpExpr(), LpExpr(), LpExpr(), LpExpr(), gum::credal::lp::LpRow::LpRow(), _addSide_(), _addSide_(), _addSide_(), clear(), operator=(), operator=(), and toString().

◆ _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 459 of file LpInterface.h.

Referenced by LpExpr(), LpExpr(), LpExpr(), LpExpr(), LpExpr(), ~LpExpr(), _addSide_(), _addSide_(), _addSide_(), gum::credal::lp::LpInterface< GUM_SCALAR >::addRow(), clear(), multiply(), operator+=(), operator+=(), operator+=(), operator-=(), operator-=(), operator=(), operator=(), operator=(), and toString().

◆ _mValue_

◆ _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 463 of file LpInterface.h.

Referenced by LpExpr(), LpExpr(), LpExpr(), LpExpr(), LpExpr(), ~LpExpr(), _addSide_(), _addSide_(), _addSide_(), clear(), operator=(), operator=(), and toString().

◆ _rValue_

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

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

Definition at line 450 of file LpInterface.h.

Referenced by LpExpr(), LpExpr(), LpExpr(), LpExpr(), LpExpr(), _addSide_(), _addSide_(), _addSide_(), clear(), operator=(), operator=(), and toString().


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