![]() |
aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
|
Class template acting as a wrapper for Lexicographic Reverse Search by David Avis. More...
#include <agrum/CN/LrsWrapper.h>
Public Member Functions | |
Constructors / Destructors | |
| LRSWrapper () | |
| Default Constructor. | |
| ~LRSWrapper () | |
| Default Destructor. | |
Getters and setters | |
| const matrix & | getInput () const |
| Get the intput matrix of the problem. | |
| const matrix & | getOutput () const |
| Get the output matrix solution of the problem. | |
| const unsigned int & | getVerticesNumber () const |
| Get the number of vertices of this polytope. | |
| const GUM_SCALAR & | getVolume () const |
| Get the volume of the polytope that has been computed. | |
setUp / tearDown | |
| void | setUpH (const Size &card) |
| Sets up an H-representation. | |
| void | setUpV (const Size &card, const Size &vertices) |
| Sets up a V-representation. | |
| void | tearDown () |
| Reset the wrapper as if it was built. | |
| void | nextHInput () |
| Reset the wrapper for next computation for a H-representation with the same variable cardinality and number of inequalities. | |
Input filling methods | |
| void | fillH (const GUM_SCALAR &min, const GUM_SCALAR &max, const Size &modal) |
Creates the H-representation of min <= p(X=modal | .) <= max and add it to the problem input _input_. | |
| void | fillMatrix (const std::vector< std::vector< GUM_SCALAR > > &matrix) |
| Fill the H-representation from the matrix given in argument. | |
| void | fillV (const std::vector< GUM_SCALAR > &vertex) |
Creates the V-representation of a polytope by adding a vertex to the problem input _input_. | |
lrs algorithms | |
| void | H2V () |
| H-representation to V-representation. | |
| void | V2H () |
| V-representation to H-representation. | |
| void | computeVolume () |
| Computes a polytope ( pseudo ) volume from it's V-representation. | |
| void | elimRedundVrep () |
| V-Redundancy elimination. | |
Private Types | |
| enum class | _states_ : char { none = char(0) , Hup = char(1) , Vup = char(2) , H2Vready = char(3) , V2Hready = char(4) } |
| The possible states of the LrsWrapper. More... | |
| using | matrix = typename std::vector< std::vector< GUM_SCALAR > > |
| Shortcut for dynamic matrix using vectors. | |
Private Member Functions | |
lrs datas <-> wrapper datas | |
| void | _freeLrs_ () |
| Free lrs space. | |
| void | _initLrs_ () |
| Initialize lrs structs and first basis according to flags. | |
| void | _fill_ () const |
Fill lrs_dictionnary and datas from _input_ using integer rationals. | |
| void | _getLRSWrapperOutput_ (lrs_mp Nin, lrs_mp Din, std::vector< int64_t > &Num, std::vector< int64_t > &Den) const |
| Translate a single output from lrs. | |
Private Attributes | |
| matrix | _input_ |
| Input matrix - either a V-representation or an H-representation. | |
| matrix | _output_ |
| Output matrix - either a V-representation or an H-representation. | |
| unsigned int | _card_ |
| Cardinality of the variable. | |
| std::unordered_set< int > | _insertedModals_ |
| To keep track of which constraints over modalities have been inserted. | |
| unsigned int | _vertices_ |
| The number of vertices of the polytope. | |
| std::vector< std::vector< GUM_SCALAR > > | _insertedVertices_ |
| To keep track of inserted vertices and total. | |
| std::vector< GUM_SCALAR > | _vertex_ |
| In case we have lower = upper for all modalities, a point probability, there is no need to use lrs. | |
| _states_ | _state_ |
| The current state of the LrsWrapper. | |
| GUM_SCALAR | _volume_ |
| The volume of the polytope, if computed, 0 otherwise. | |
| const char * | _setUpStateNames_ [5] |
| To print an enum field name instead of it's value. | |
| int | _oldCout_ |
| File descriptor of standard cout. | |
lrs structs | |
| lrs_dic * | _dic_ |
| Structure for holding current dictionary and indices of lrs. | |
| lrs_dat * | _dat_ |
| Structure for holding static problem data of lrs. | |
| lrs_mp_vector | _lrsOutput_ |
| One line of output of lrs : aither a ray, a vertex, a facet or a linearity. | |
| lrs_mp_matrix | _Lin_ |
| Holds lrs input linearities if any are found. | |
flags | |
| bool | _getVolume_ |
| bool | _hull_ |
| bool | _polytope_ |
Class template acting as a wrapper for Lexicographic Reverse Search by David Avis.
| GUM_SCALAR | A floating type ( float, double, long double ... ). |
Definition at line 121 of file LrsWrapper.h.
|
private |
Shortcut for dynamic matrix using vectors.
Definition at line 123 of file LrsWrapper.h.
|
strongprivate |
The possible states of the LrsWrapper.
Some functions will throw an exception if the state is not correct. It allows the user to avoid making - invisible - mistakes.
| Enumerator | |
|---|---|
| none | |
| Hup | |
| Vup | |
| H2Vready | |
| V2Hready | |
Definition at line 157 of file LrsWrapper.h.
| gum::credal::LRSWrapper< GUM_SCALAR >::LRSWrapper | ( | ) |
Default Constructor.
Definition at line 56 of file LrsWrapper_tpl.h.
References LRSWrapper(), _card_, _getVolume_, _hull_, _polytope_, _state_, _vertices_, _volume_, and none.
Referenced by LRSWrapper(), and ~LRSWrapper().
| gum::credal::LRSWrapper< GUM_SCALAR >::~LRSWrapper | ( | ) |
Default Destructor.
Definition at line 72 of file LrsWrapper_tpl.h.
References LRSWrapper().
|
private |
Fill lrs_dictionnary and datas from _input_ using integer rationals.
Build polyhedron constraints and objective. Rational< GUM_SCALAR >::continuedFrac is the default algorithm used to approximate reals by integer rationals.
Definition at line 557 of file LrsWrapper_tpl.h.
References _dat_, _dic_, _input_, and gum::Rational< GUM_SCALAR >::continuedFracFirst().
Referenced by _initLrs_().
|
private |
Free lrs space.
Definition at line 659 of file LrsWrapper_tpl.h.
References _dat_, _dic_, _Lin_, and _lrsOutput_.
Referenced by computeVolume(), elimRedundVrep(), and H2V().
|
private |
Translate a single output from lrs.
Only vertices are supposed to be read at this step.
| Nin | Input numerators in mp format (returned by lrs). |
| Din | Input denominators in mp format (returned by lrs). |
| Num | Output integer numerators. |
| Den | Output integer denominators. |
Definition at line 499 of file LrsWrapper_tpl.h.
References BASE.
Referenced by H2V().
|
private |
Initialize lrs structs and first basis according to flags.
Definition at line 593 of file LrsWrapper_tpl.h.
References _dat_, _dic_, _fill_(), _getVolume_, _hull_, _input_, _Lin_, _lrsOutput_, _polytope_, _setUpStateNames_, _state_, GUM_ERROR, H2Vready, and V2Hready.
Referenced by computeVolume(), elimRedundVrep(), and H2V().
| void gum::credal::LRSWrapper< GUM_SCALAR >::computeVolume | ( | ) |
Computes a polytope ( pseudo ) volume from it's V-representation.
Definition at line 380 of file LrsWrapper_tpl.h.
References _dat_, _dic_, _freeLrs_(), _getVolume_, _initLrs_(), _lrsOutput_, _setUpStateNames_, _state_, _volume_, BASE, GUM_ERROR, and V2Hready.
| void gum::credal::LRSWrapper< GUM_SCALAR >::elimRedundVrep | ( | ) |
V-Redundancy elimination.
Eliminates redundant vertices from a polytope V-representation input input.
Definition at line 428 of file LrsWrapper_tpl.h.
References _dat_, _dic_, _freeLrs_(), _initLrs_(), _input_, _output_, _setUpStateNames_, _state_, _vertices_, GUM_ERROR, and V2Hready.
| void gum::credal::LRSWrapper< GUM_SCALAR >::fillH | ( | const GUM_SCALAR & | min, |
| const GUM_SCALAR & | max, | ||
| const Size & | modal ) |
Creates the H-representation of min <= p(X=modal | .) <= max and add it to the problem input _input_.
| min | The lower value of p(X=modal | .). |
| max | The upper value of p(X=modal | .). |
| modal | The modality on which we put constraints. |
Definition at line 205 of file LrsWrapper_tpl.h.
References _card_, _input_, _insertedModals_, _setUpStateNames_, _state_, _vertex_, GUM_ERROR, H2Vready, and Hup.
Referenced by gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal().
| void gum::credal::LRSWrapper< GUM_SCALAR >::fillMatrix | ( | const std::vector< std::vector< GUM_SCALAR > > & | matrix | ) |
Fill the H-representation from the matrix given in argument.
| matrix | The H-representation of the polytope of the form 0 <= -b
|
Definition at line 234 of file LrsWrapper_tpl.h.
References _card_, _input_, _insertedModals_, _setUpStateNames_, _state_, GUM_ERROR, H2Vready, and Hup.
Referenced by gum::credal::lp::LpInterface< GUM_SCALAR >::solve().
| void gum::credal::LRSWrapper< GUM_SCALAR >::fillV | ( | const std::vector< GUM_SCALAR > & | vertex | ) |
Creates the V-representation of a polytope by adding a vertex to the problem input _input_.
| vertex | The vertex we wish to add to the V-representation of the polytope. |
Definition at line 258 of file LrsWrapper_tpl.h.
References _card_, _input_, _insertedVertices_, _setUpStateNames_, _state_, _vertices_, GUM_ERROR, V2Hready, and Vup.
| auto gum::credal::LRSWrapper< GUM_SCALAR >::getInput | ( | ) | const |
Get the intput matrix of the problem.
_intput_ matrix. Definition at line 77 of file LrsWrapper_tpl.h.
References _input_.
| auto gum::credal::LRSWrapper< GUM_SCALAR >::getOutput | ( | ) | const |
Get the output matrix solution of the problem.
_output_ matrix. Definition at line 82 of file LrsWrapper_tpl.h.
References _output_.
Referenced by gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal(), and gum::credal::lp::LpInterface< GUM_SCALAR >::solve().
| const unsigned int & gum::credal::LRSWrapper< GUM_SCALAR >::getVerticesNumber | ( | ) | const |
Get the number of vertices of this polytope.
_vertices_. Definition at line 87 of file LrsWrapper_tpl.h.
References _vertices_.
| const GUM_SCALAR & gum::credal::LRSWrapper< GUM_SCALAR >::getVolume | ( | ) | const |
Get the volume of the polytope that has been computed.
Definition at line 92 of file LrsWrapper_tpl.h.
| void gum::credal::LRSWrapper< GUM_SCALAR >::H2V | ( | ) |
H-representation to V-representation.
Computes the V-representation of a polytope, i.e. it's vertices, from it's H-representation, i.e. the hyper-plan inequalities.
Definition at line 301 of file LrsWrapper_tpl.h.
References _card_, _dat_, _dic_, _freeLrs_(), _getLRSWrapperOutput_(), _initLrs_(), _lrsOutput_, _output_, _setUpStateNames_, _state_, _vertex_, _vertices_, GUM_ERROR, H2Vready, and gum::isCloseToOne().
Referenced by gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal(), and gum::credal::lp::LpInterface< GUM_SCALAR >::solve().
| void gum::credal::LRSWrapper< GUM_SCALAR >::nextHInput | ( | ) |
Reset the wrapper for next computation for a H-representation with the same variable cardinality and number of inequalities.
Usefull when creating credal networks specified as intervals over modalities.
Reset wrapper state _state_ to it's previous state and clear output matrix _output_. Keeps the cardinality _card_ of the variable and therefore the input matrix _intput_ structure.
Definition at line 175 of file LrsWrapper_tpl.h.
References _card_, _getVolume_, _hull_, _input_, _insertedModals_, _insertedVertices_, _output_, _polytope_, _setUpStateNames_, _state_, _vertex_, _vertices_, _volume_, GUM_ERROR, H2Vready, Hup, none, V2Hready, and Vup.
Referenced by gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal().
| void gum::credal::LRSWrapper< GUM_SCALAR >::setUpH | ( | const Size & | card | ) |
Sets up an H-representation.
Initialize input matrix _input_ to correct dimensions and wrapper state _state_ to _states_::Hup.
| card | A constant reference to the cardinality of the variable. |
Definition at line 103 of file LrsWrapper_tpl.h.
References _card_, _input_, _output_, _state_, _vertex_, GUM_ERROR, Hup, and tearDown().
Referenced by gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal(), and gum::credal::lp::LpInterface< GUM_SCALAR >::solve().
| void gum::credal::LRSWrapper< GUM_SCALAR >::setUpV | ( | const Size & | card, |
| const Size & | vertices ) |
Sets up a V-representation.
Initialize input matrix _input_ to correct dimensions and wrapper state _state_ to _states_::Vup.
| card | A constant reference to the cardinality of the variable. |
| vertices | A constant reference to the number of vertices of the polytope. |
Definition at line 130 of file LrsWrapper_tpl.h.
References _card_, _input_, _output_, _state_, _vertices_, GUM_ERROR, tearDown(), and Vup.
| void gum::credal::LRSWrapper< GUM_SCALAR >::tearDown | ( | ) |
Reset the wrapper as if it was built.
Reset wrapper state _state_ to _states_::none and clear all member datas.
Definition at line 155 of file LrsWrapper_tpl.h.
References _card_, _getVolume_, _hull_, _input_, _insertedModals_, _insertedVertices_, _output_, _polytope_, _state_, _vertex_, _vertices_, _volume_, and none.
Referenced by setUpH(), and setUpV().
| void gum::credal::LRSWrapper< GUM_SCALAR >::V2H | ( | ) |
V-representation to H-representation.
Computes the H-representation of a polytope from it's V-representation.
Definition at line 370 of file LrsWrapper_tpl.h.
References _setUpStateNames_, _state_, GUM_ERROR, and V2Hready.
|
private |
Cardinality of the variable.
Definition at line 134 of file LrsWrapper.h.
Referenced by LRSWrapper(), fillH(), fillMatrix(), fillV(), H2V(), nextHInput(), setUpH(), setUpV(), and tearDown().
|
private |
Structure for holding static problem data of lrs.
Definition at line 198 of file LrsWrapper.h.
Referenced by _fill_(), _freeLrs_(), _initLrs_(), computeVolume(), elimRedundVrep(), and H2V().
|
private |
Structure for holding current dictionary and indices of lrs.
Definition at line 195 of file LrsWrapper.h.
Referenced by _fill_(), _freeLrs_(), _initLrs_(), computeVolume(), elimRedundVrep(), and H2V().
|
private |
Definition at line 213 of file LrsWrapper.h.
Referenced by LRSWrapper(), _initLrs_(), computeVolume(), nextHInput(), and tearDown().
|
private |
Definition at line 215 of file LrsWrapper.h.
Referenced by LRSWrapper(), _initLrs_(), nextHInput(), and tearDown().
|
private |
Input matrix - either a V-representation or an H-representation.
Definition at line 127 of file LrsWrapper.h.
Referenced by _fill_(), _initLrs_(), elimRedundVrep(), fillH(), fillMatrix(), fillV(), getInput(), nextHInput(), setUpH(), setUpV(), and tearDown().
|
private |
To keep track of which constraints over modalities have been inserted.
When the set is full, the state changes from up to ready.
Definition at line 138 of file LrsWrapper.h.
Referenced by fillH(), fillMatrix(), nextHInput(), and tearDown().
|
private |
To keep track of inserted vertices and total.
When set is full, the state changes from up to ready.
Definition at line 146 of file LrsWrapper.h.
Referenced by fillV(), nextHInput(), and tearDown().
|
private |
Holds lrs input linearities if any are found.
Definition at line 206 of file LrsWrapper.h.
Referenced by _freeLrs_(), and _initLrs_().
|
private |
One line of output of lrs : aither a ray, a vertex, a facet or a linearity.
Definition at line 203 of file LrsWrapper.h.
Referenced by _freeLrs_(), _initLrs_(), computeVolume(), and H2V().
|
mutableprivate |
File descriptor of standard cout.
Lrs writes a lot of stuff on standard cout. oldCout is used to save the current cout before redirecting it to /dev/null when calling lrs. The standard cout is restored when lrs is done.
Definition at line 189 of file LrsWrapper.h.
|
private |
Output matrix - either a V-representation or an H-representation.
Definition at line 131 of file LrsWrapper.h.
Referenced by elimRedundVrep(), getOutput(), H2V(), nextHInput(), setUpH(), setUpV(), and tearDown().
|
private |
Definition at line 217 of file LrsWrapper.h.
Referenced by LRSWrapper(), _initLrs_(), nextHInput(), and tearDown().
|
private |
To print an enum field name instead of it's value.
Used with GUM_ERROR.
Definition at line 173 of file LrsWrapper.h.
Referenced by _initLrs_(), computeVolume(), elimRedundVrep(), fillH(), fillMatrix(), fillV(), H2V(), nextHInput(), and V2H().
|
private |
The current state of the LrsWrapper.
Definition at line 166 of file LrsWrapper.h.
Referenced by LRSWrapper(), _initLrs_(), computeVolume(), elimRedundVrep(), fillH(), fillMatrix(), fillV(), H2V(), nextHInput(), setUpH(), setUpV(), tearDown(), and V2H().
|
private |
In case we have lower = upper for all modalities, a point probability, there is no need to use lrs.
Definition at line 150 of file LrsWrapper.h.
Referenced by fillH(), H2V(), nextHInput(), setUpH(), and tearDown().
|
private |
The number of vertices of the polytope.
Definition at line 141 of file LrsWrapper.h.
Referenced by LRSWrapper(), elimRedundVrep(), fillV(), getVerticesNumber(), H2V(), nextHInput(), setUpV(), and tearDown().
|
private |
The volume of the polytope, if computed, 0 otherwise.
Definition at line 169 of file LrsWrapper.h.
Referenced by LRSWrapper(), computeVolume(), getVolume(), nextHInput(), and tearDown().