aGrUM  0.20.2
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 209 of file LpInterface.h.

Constructor & Destructor Documentation

◆ LpExpr() [1/5]

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

Default constructor.

class LpExpr

Definition at line 54 of file LpInterface.cpp.

54  :
55  ileft__(false), imiddle__(false), iright__(false), lValue__(0.),
56  mValue__(0.), rValue__(0.), lCoeffs__(new HashTable< LpCol, double >()),
57  mCoeffs__(new HashTable< LpCol, double >()),
58  rCoeffs__(new HashTable< LpCol, double >()) {
59  GUM_CONSTRUCTOR(LpExpr);
60  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
LpExpr()
Default constructor.
Definition: LpInterface.cpp:54
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

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

62  :
63  ileft__(expr.ileft__), imiddle__(expr.imiddle__),
64  iright__(expr.iright__), lValue__(expr.lValue__),
65  mValue__(expr.mValue__), rValue__(expr.rValue__),
66  lCoeffs__(new HashTable< LpCol, double >(*expr.lCoeffs__)),
67  mCoeffs__(new HashTable< LpCol, double >(*expr.mCoeffs__)),
68  rCoeffs__(new HashTable< LpCol, double >(*expr.rCoeffs__)) {
69  GUM_CONS_CPY(LpExpr);
70  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
LpExpr()
Default constructor.
Definition: LpInterface.cpp:54
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

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

75  :
76  ileft__(false),
77  imiddle__(false), iright__(false), lValue__(0.), mValue__(0.),
78  rValue__(0.), lCoeffs__(nullptr), mCoeffs__(nullptr),
79  rCoeffs__(nullptr) {
80  if (copyLeft) {
81  lCoeffs__ = new HashTable< LpCol, double >(*expr.lCoeffs__);
82  lValue__ = expr.lValue__;
83  ileft__ = true;
84  } else
85  lCoeffs__ = new HashTable< LpCol, double >();
86 
87  if (copyMiddle) {
88  mCoeffs__ = new HashTable< LpCol, double >(*expr.mCoeffs__);
89  mValue__ = expr.mValue__;
90  imiddle__ = true;
91  } else
92  mCoeffs__ = new HashTable< LpCol, double >();
93 
94  if (copyRight) {
95  rCoeffs__ = new HashTable< LpCol, double >(*expr.rCoeffs__);
96  rValue__ = expr.rValue__;
97  iright__ = true;
98  } else
99  rCoeffs__ = new HashTable< LpCol, double >();
100 
101  GUM_CONS_CPY(LpExpr);
102  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
LpExpr()
Default constructor.
Definition: LpInterface.cpp:54
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

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

104  :
105  ileft__(expr.ileft__), imiddle__(expr.imiddle__),
106  iright__(expr.iright__), lValue__(expr.lValue__),
107  mValue__(expr.mValue__), rValue__(expr.rValue__),
108  lCoeffs__(expr.lCoeffs__), mCoeffs__(expr.mCoeffs__),
109  rCoeffs__(expr.rCoeffs__) {
110  expr.lCoeffs__ = nullptr;
111  expr.mCoeffs__ = nullptr;
112  expr.rCoeffs__ = nullptr;
113 
114  GUM_CONS_CPY(LpExpr);
115  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
LpExpr()
Default constructor.
Definition: LpInterface.cpp:54
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

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

120  :
121  ileft__(false),
122  imiddle__(false), iright__(false), lValue__(0.), mValue__(0.),
123  rValue__(0.), lCoeffs__(nullptr), mCoeffs__(nullptr),
124  rCoeffs__(nullptr) {
125  if (copyLeft) {
126  swap(lCoeffs__, expr.lCoeffs__);
127  lValue__ = expr.lValue__;
128  ileft__ = true;
129  } else
130  lCoeffs__ = new HashTable< LpCol, double >();
131 
132  if (copyMiddle) {
133  swap(mCoeffs__, expr.mCoeffs__);
134  mValue__ = expr.mValue__;
135  imiddle__ = true;
136  } else
137  mCoeffs__ = new HashTable< LpCol, double >();
138 
139  if (copyRight) {
140  swap(rCoeffs__, expr.rCoeffs__);
141  rValue__ = expr.rValue__;
142  iright__ = true;
143  } else
144  rCoeffs__ = new HashTable< LpCol, double >();
145 
146  GUM_CONS_CPY(LpExpr);
147  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
LpExpr()
Default constructor.
Definition: LpInterface.cpp:54
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

◆ ~LpExpr()

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

Default destructor.

Definition at line 149 of file LpInterface.cpp.

149  {
150  delete lCoeffs__;
151  delete mCoeffs__;
152  delete rCoeffs__;
153 
154  GUM_DESTRUCTOR(LpExpr);
155  }
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
LpExpr()
Default constructor.
Definition: LpInterface.cpp:54
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442

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

283  {
284  if (!ileft__) {
285  lCoeffs__->insert(from, 1.);
286  ileft__ = true;
287  } else if (!imiddle__) {
288  mCoeffs__->insert(from, 1.);
289  imiddle__ = true;
290  } else if (!iright__) {
291  rCoeffs__->insert(from, 1.);
292  iright__ = true;
293  } else
294  GUM_ERROR(OperationNotAllowed,
295  "LpExpr::setSide ( const LpCol & from "
296  ") : too many <= ; no free side");
297  }
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

299  {
300  if (ileft__ && iright__ && from.imiddle__)
301  GUM_ERROR(OperationNotAllowed,
302  "LpExpr::setSide ( const LpCol & from "
303  ") : too many <= ; no free side");
304 
306  if (!from.imiddle__) return;
307 
311  if (!from.ileft__ && !from.iright__) {
312  if (!ileft__) {
313  *lCoeffs__ = *from.mCoeffs__;
314  lValue__ = from.mValue__;
315  ileft__ = true;
316 
317  return;
318  } else if (!imiddle__) {
319  *mCoeffs__ = *from.mCoeffs__;
320  mValue__ = from.mValue__;
321  imiddle__ = true;
322 
323  return;
324  } else if (!iright__) {
325  *rCoeffs__ = *from.mCoeffs__;
326  rValue__ = from.mValue__;
327  iright__ = true;
328 
329  return;
330  } else
331  GUM_ERROR(OperationNotAllowed,
332  "LpExpr::setSide ( const LpCol & from ) "
333  ": too many <= ; no free side");
334  }
337  else if (from.ileft__ && !from.iright__) {
338  if (!ileft__) {
339  *lCoeffs__ = *from.lCoeffs__;
340  lValue__ = from.lValue__;
341  ileft__ = true;
342 
343  *mCoeffs__ = *from.mCoeffs__;
344  mValue__ = from.mValue__;
345  imiddle__ = true;
346 
347  return;
348  } else if (!imiddle__ && !iright__) {
349  *mCoeffs__ = *from.lCoeffs__;
350  mValue__ = from.lValue__;
351  imiddle__ = true;
352 
353  *rCoeffs__ = *from.mCoeffs__;
354  rValue__ = from.mValue__;
355  iright__ = true;
356 
357  return;
358  } else
359  GUM_ERROR(OperationNotAllowed,
360  "LpExpr::setSide ( const LpCol & from ) "
361  ": too many <= ; no free side");
362  }
365  else if (from.ileft__ && from.iright__) {
366  if (ileft__ || imiddle__ || iright__)
367  GUM_ERROR(OperationNotAllowed,
368  "LpExpr::setSide ( const LpCol & from ) "
369  ": too many <= ; no free side");
370 
371  *this = from;
372 
373  return;
374  } else
375  GUM_ERROR(OperationNotAllowed,
376  "LpExpr::setSide ( const LpCol & from "
377  ") : too many <= ; no free side");
378  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

380  {
382  if (ileft__ && iright__ && from.imiddle__)
383  GUM_ERROR(OperationNotAllowed,
384  "LpExpr::setSide ( const LpCol & from "
385  ") : too many <= ; no free side");
386 
388  if (!from.imiddle__) return;
389 
393  if (!from.ileft__ && !from.iright__) {
394  if (!ileft__) {
396  swap(lCoeffs__, from.mCoeffs__);
397  lValue__ = from.mValue__;
398  ileft__ = true;
399 
400  return;
401  } else if (!imiddle__) {
403  swap(mCoeffs__, from.mCoeffs__);
404  mValue__ = from.mValue__;
405  imiddle__ = true;
406 
407  return;
408  } else if (!iright__) {
410  swap(rCoeffs__, from.mCoeffs__);
411  rValue__ = from.mValue__;
412  iright__ = true;
413 
414  return;
415  } else
416  GUM_ERROR(OperationNotAllowed,
417  "LpExpr::setSide ( const LpCol & from ) "
418  ": too many <= ; no free side");
419  }
422  else if (from.ileft__ && !from.iright__) {
423  if (!ileft__) {
425  swap(lCoeffs__, from.lCoeffs__);
426  lValue__ = from.lValue__;
427  ileft__ = true;
428 
430  swap(mCoeffs__, from.mCoeffs__);
431  mValue__ = from.mValue__;
432  imiddle__ = true;
433 
434  return;
435  } else if (!imiddle__ && !iright__) {
437  swap(mCoeffs__, from.lCoeffs__);
438  mValue__ = from.lValue__;
439  imiddle__ = true;
440 
442  swap(rCoeffs__, from.mCoeffs__);
443  rValue__ = from.mValue__;
444  iright__ = true;
445 
446  return;
447  } else
448  GUM_ERROR(OperationNotAllowed,
449  "LpExpr::setSide ( const LpCol & from ) "
450  ": too many <= ; no free side");
451  }
454  else if (from.ileft__ && from.iright__) {
455  if (ileft__ || imiddle__ || iright__)
456  GUM_ERROR(OperationNotAllowed,
457  "LpExpr::setSide ( const LpCol & from ) "
458  ": too many <= ; no free side");
459 
460  *this = std::move(from);
461 
462  return;
463  } else
464  GUM_ERROR(OperationNotAllowed,
465  "LpExpr::setSide ( const LpCol & from "
466  ") : too many <= ; no free side");
467  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

68  {
69  if (!ileft__) {
70  lValue__ = from;
71  ileft__ = true;
72  } else if (!imiddle__) {
73  mValue__ = from;
74  imiddle__ = true;
75  } else if (!iright__) {
76  rValue__ = from;
77  iright__ = true;
78  } else
79  GUM_ERROR(OperationNotAllowed,
80  "LpExpr::setSide ( const LpCol & from "
81  ") : too many <= ; no free side");
82  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ clear()

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

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

Definition at line 470 of file LpInterface.cpp.

470  {
471  lCoeffs__->clear();
472  mCoeffs__->clear();
473  rCoeffs__->clear();
474 
475  lValue__ = 0.;
476  mValue__ = 0.;
477  rValue__ = 0.;
478 
479  ileft__ = false;
480  imiddle__ = false;
481  iright__ = false;
482  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

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

503  {
504  LpExpr expr;
505  expr.addSide__(std::forward< T1 >(lhs));
506  expr.addSide__(std::forward< T2 >(rhs));
507  return expr;
508  }
LpExpr()
Default constructor.
Definition: LpInterface.cpp:54

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

484  {
485  LpExpr expr;
486  expr.mCoeffs__->insert(rhs, lhs);
487  expr.imiddle__ = true;
488  return expr;
489  }
LpExpr()
Default constructor.
Definition: LpInterface.cpp:54

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

205  {
206  if (ileft__ || iright__)
207  GUM_ERROR(OperationNotAllowed,
208  "expr::operator+= (expr) : <= present on one side of expr");
209 
210  if (!imiddle__) imiddle__ = true;
211 
212  mCoeffs__->getWithDefault(rhs, 0.) += 1.;
213 
214  return *this;
215  }
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

217  {
218  if (ileft__ || iright__ || rhs.ileft__ || rhs.iright__)
219  GUM_ERROR(OperationNotAllowed,
220  "expr::operator+= (rhs) : <= present "
221  "on one side of rhs and/or expr");
222 
223  if (!imiddle__) imiddle__ = true;
224 
225  for (const auto& elt: *rhs.mCoeffs__)
226  mCoeffs__->getWithDefault(elt.first, 0.) += elt.second;
227 
228  mValue__ += rhs.mValue__;
229 
230  return *this;
231  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

233  {
234  if (ileft__ || iright__ || rhs.ileft__ || rhs.iright__)
235  GUM_ERROR(OperationNotAllowed,
236  "expr::operator+= (rhs) : <= present "
237  "on one side of rhs and/or expr");
238 
239  if (!imiddle__) {
240  imiddle__ = true;
241  mValue__ = rhs.mValue__;
242  swap(mCoeffs__, rhs.mCoeffs__);
243 
244  return *this;
245  }
246 
247  for (const auto& elt: *rhs.mCoeffs__)
248  mCoeffs__->getWithDefault(elt.first, 0.) += elt.second;
249  mValue__ += rhs.mValue__;
250 
251  return *this;
252  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ 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,
45  "expr::operator+= (expr) : <= present on one side of expr");
46 
47  if (!imiddle__) imiddle__ = true;
48 
49  mValue__ += rhs;
50 
51  return *this;
52  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

254  {
255  if (ileft__ || iright__)
256  GUM_ERROR(OperationNotAllowed,
257  "expr::operator-= (rhs) : <= present in one of expr");
258 
259  if (!imiddle__) imiddle__ = true;
260 
261  mCoeffs__->getWithDefault(rhs, 0.) -= 1.;
262 
263  return *this;
264  }
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

266  {
267  if (ileft__ || iright__ || rhs.ileft__ || rhs.iright__)
268  GUM_ERROR(
269  OperationNotAllowed,
270  "expr::operator-= (rhs) : <= present in one of rhs and/or expr");
271 
272  if (!imiddle__) imiddle__ = true;
273 
274  for (const auto& elt: *rhs.mCoeffs__)
275  mCoeffs__->getWithDefault(elt.first, 0.) -= elt.second;
276 
277  mValue__ -= rhs.mValue__;
278 
279  return *this;
280  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

55  {
56  if (ileft__ || iright__)
57  GUM_ERROR(OperationNotAllowed,
58  "expr::operator-= (rhs) : <= present in one of expr");
59 
60  if (!imiddle__) imiddle__ = true;
61 
62  mValue__ -= rhs;
63 
64  return *this;
65  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

157  {
158  clear();
159 
160  mCoeffs__->insert(rhs, 1.);
161  imiddle__ = true;
162 
163  return *this;
164  }
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
void clear()
Clear all data of the calling expression as if it was constructed.
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

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

166  {
168  if (this == &rhs) return *this;
169 
170  *lCoeffs__ = *rhs.lCoeffs__;
171  *mCoeffs__ = *rhs.mCoeffs__;
172  *rCoeffs__ = *rhs.rCoeffs__;
173 
174  lValue__ = rhs.lValue__;
175  mValue__ = rhs.mValue__;
176  rValue__ = rhs.rValue__;
177 
178  ileft__ = rhs.ileft__;
179  imiddle__ = rhs.imiddle__;
180  iright__ = rhs.iright__;
181 
182  return *this;
183  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

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

185  {
187  if (this == &rhs) return *this;
188 
189  swap(lCoeffs__, rhs.lCoeffs__);
190  swap(mCoeffs__, rhs.mCoeffs__);
191  swap(rCoeffs__, rhs.rCoeffs__);
192 
193  lValue__ = rhs.lValue__;
194  mValue__ = rhs.mValue__;
195  rValue__ = rhs.rValue__;
196 
197  ileft__ = rhs.ileft__;
198  imiddle__ = rhs.imiddle__;
199  iright__ = rhs.iright__;
200 
201  return *this;
202  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
bool iright__
True if this expression has a non-empty right side R : L <= M <= R .
Definition: LpInterface.h:422
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425
bool ileft__
True if this expression has a non-empty left side L : L <= M <= R .
Definition: LpInterface.h:414
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

◆ 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  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
void clear()
Clear all data of the calling expression as if it was constructed.
bool imiddle__
True if this expression has a non-empty middle side M ( the default ) : L <= M <= R ...
Definition: LpInterface.h:418

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

484  {
485  std::ostringstream s;
486 
487  s << std::endl << "left side : " << std::endl;
488 
489  if (lCoeffs__ != nullptr)
490  for (const auto& elt: *lCoeffs__)
491  s << elt.first.toString() << " " << elt.second << " | ";
492 
493  s << std::endl << "middle side : " << std::endl;
494 
495  if (mCoeffs__ != nullptr)
496  for (const auto& elt: *mCoeffs__)
497  s << elt.first.toString() << " " << elt.second << " | ";
498 
499  s << std::endl << "right side : " << std::endl;
500 
501  if (rCoeffs__ != nullptr)
502  for (const auto& elt: *rCoeffs__)
503  s << elt.first.toString() << " " << elt.second << " | ";
504 
505  s << std::endl
506  << "lvalue : " << lValue__ << std::endl
507  << "mvalue : " << mValue__ << std::endl
508  << "rvalue : " << rValue__ << std::endl;
509 
510  s << std::endl;
511 
512  return s.str();
513  }
double mValue__
The constant on the middle side L : L <= M <= R.
Definition: LpInterface.h:427
HashTable< LpCol, double > * mCoeffs__
The coefficients of each variable on the middle side L : L <= M <= R.
Definition: LpInterface.h:438
double rValue__
The constant on the right side L : L <= M <= R.
Definition: LpInterface.h:429
HashTable< LpCol, double > * lCoeffs__
The coefficients of each variable on the left side L : L <= M <= R.
Definition: LpInterface.h:434
HashTable< LpCol, double > * rCoeffs__
The coefficients of each variable on the right side L : L <= M <= R.
Definition: LpInterface.h:442
double lValue__
The constant on the left side L : L <= M <= R.
Definition: LpInterface.h:425

Friends And Related Function Documentation

◆ LpInterface

template<typename GUM_SCALAR >
friend class LpInterface
friend

Definition at line 212 of file LpInterface.h.

◆ LpRow

friend class LpRow
friend

Definition at line 210 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 414 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 418 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 422 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 434 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 425 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 438 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 427 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 442 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 429 of file LpInterface.h.


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