aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
LrsWrapper_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
43#include <string.h>
44
45#include <agrum/agrum.h>
46
48
49namespace gum {
50 namespace credal {
51
52 template < typename GUM_SCALAR >
55
56 _vertices_ = 0;
57 _card_ = 0;
58
59 _volume_ = 0;
60
61 _getVolume_ = false;
62 _hull_ = false;
63 _polytope_ = false;
64
65 GUM_CONSTRUCTOR(LRSWrapper);
66 }
67
68 template < typename GUM_SCALAR >
72
73 template < typename GUM_SCALAR >
75 return _input_;
76 }
77
78 template < typename GUM_SCALAR >
80 return _output_;
81 }
82
83 template < typename GUM_SCALAR >
84 const unsigned int& LRSWrapper< GUM_SCALAR >::getVerticesNumber() const {
85 return _vertices_;
86 }
87
88 template < typename GUM_SCALAR >
89 const GUM_SCALAR& LRSWrapper< GUM_SCALAR >::getVolume() const {
90 if (_volume_ != 0) return _volume_;
91 else
93 "LRSWrapper< GUM_SCALAR >::getVolume () : "
94 "volume computation was not asked for this "
95 "credal set, call computeVolume() from a "
96 "V-representation.");
97 }
98
99 template < typename GUM_SCALAR >
101 if (card < 2)
103 "LRSWrapper< GUM_SCALAR >::setUpH : "
104 "cardinality must be at least 2");
105
106 tearDown();
107
108 _input_ = std::vector< std::vector< GUM_SCALAR > >(card * 2 + 2,
109 std::vector< GUM_SCALAR >(card + 1, 0));
110
111 _input_[card * 2] = std::vector< GUM_SCALAR >(card + 1, -1);
112 _input_[card * 2][0] = 1;
113
114 _input_[card * 2 + 1] = std::vector< GUM_SCALAR >(card + 1, 1);
115 _input_[card * 2 + 1][0] = -1;
116
117 _output_ = std::vector< std::vector< GUM_SCALAR > >();
118
119 _vertex_ = std::vector< GUM_SCALAR >(card);
120
122
123 _card_ = (unsigned int)card;
124 }
125
126 template < typename GUM_SCALAR >
127 void LRSWrapper< GUM_SCALAR >::setUpV(const Size& card, const Size& vertices) {
128 if (card < 2)
130 "LRSWrapper< GUM_SCALAR >::setUpV : "
131 "cardinality must be at least 2");
132
133 if (vertices < 2)
135 "LRSWrapper< GUM_SCALAR >::setUpV : vertices "
136 "must be at least 2 to build a polytope");
137
138 tearDown();
139
140 _input_ = std::vector< std::vector< GUM_SCALAR > >(vertices,
141 std::vector< GUM_SCALAR >(card + 1, 1));
142
143 _output_ = std::vector< std::vector< GUM_SCALAR > >();
144
146
147 _card_ = (unsigned int)card;
148 _vertices_ = (unsigned int)vertices;
149 }
150
151 template < typename GUM_SCALAR >
153 _input_.clear();
154 _output_.clear();
155 _vertex_.clear();
156 _insertedModals_.clear();
157
158 _insertedVertices_.clear();
159 _vertices_ = 0;
160
161 _volume_ = 0;
162
164 _card_ = 0;
165
166 _getVolume_ = false;
167 _hull_ = false;
168 _polytope_ = false;
169 }
170
171 template < typename GUM_SCALAR >
173 _insertedModals_.clear();
174 _insertedVertices_.clear();
175 _output_.clear();
176 _vertex_.clear();
177 _vertex_.resize(_card_, 0);
178
179 _volume_ = 0;
180 _vertices_ = 0;
181
182 _getVolume_ = false;
183 _hull_ = false;
184 _polytope_ = false;
185
187 else if (_state_ == _states_::V2Hready) {
190 "LRSWrapper< GUM_SCALAR >::nextHInput : only for H-representation "
191 "as input. Previous state was : "
192 << _setUpStateNames_[static_cast< int >(_state_)]);
193 } else {
194 _input_.clear();
196 _card_ = 0;
197 _vertex_.clear();
198 }
199 }
200
201 template < typename GUM_SCALAR >
202 void LRSWrapper< GUM_SCALAR >::fillH(const GUM_SCALAR& min,
203 const GUM_SCALAR& max,
204 const Size& modal) {
205 if (_state_ != _states_::Hup)
207 "LRSWrapper< GUM_SCALAR >::fillH : setUpH or nextInput has not "
208 "been called or H-representation is complete, current state is : "
209 << _setUpStateNames_[static_cast< int >(_state_)]);
210
211 if (modal >= _card_)
213 "LRSWrapper< GUM_SCALAR >::fillH : modality is "
214 "greater or equal than cardinality : "
215 << modal << " >= " << _card_);
216
217 _input_[modal * 2][0] = -min;
218 _input_[modal * 2][modal + 1] = 1;
219
220 _input_[modal * 2 + 1][0] = max;
221 _input_[modal * 2 + 1][modal + 1] = -1;
222
223 _vertex_[modal] = max;
224
225 _insertedModals_.insert(int(modal));
226
228 }
229
230 template < typename GUM_SCALAR >
232 const std::vector< std::vector< GUM_SCALAR > >& matrix) {
233 if (_state_ != _states_::Hup)
235 "LRSWrapper< GUM_SCALAR >::fillH : setUpH or nextInput has not "
236 "been called or H-representation is complete, current state is : "
237 << _setUpStateNames_[static_cast< int >(_state_)]);
238
239 if (matrix[0].size() - 1 != _card_)
241 "LRSWrapper< GUM_SCALAR >::fillMatrix : size is "
242 "different than cardinality : "
243 << (matrix[0].size() - 1) << " != " << _card_);
244
245 _input_ = matrix;
246
247 for (unsigned int modal = 0; modal < _card_; modal++) {
248 _insertedModals_.insert(modal);
249 }
250
252 }
253
254 template < typename GUM_SCALAR >
255 void LRSWrapper< GUM_SCALAR >::fillV(const std::vector< GUM_SCALAR >& vertex) {
256 if (_state_ != _states_::Vup)
258 "LRSWrapper< GUM_SCALAR >::fillV : setUpV or nextInput has not "
259 "been called or V-representation is complete, current state is : "
260 << _setUpStateNames_[static_cast< int >(_state_)]);
261
262 if (_insertedVertices_.size() == _vertices_)
264 "LRSWrapper< GUM_SCALAR >::fillV : input is already full with " << _vertices_
265 << " vertices.");
266
267 bool eq = true;
268
269 for (const auto& v: _insertedVertices_) {
270 eq = true;
271
272 for (decltype(_card_) mod = 0; mod < _card_; mod++)
273 if (std::fabs(v[mod] - vertex[mod]) > 1e-6) {
274 eq = false;
275 break;
276 }
277
278 if (eq) {
279 _vertices_--;
280 return;
281 // GUM_ERROR ( DuplicateElement, "LRSWrapper< GUM_SCALAR >::fillV :
282 // vertex
283 // already present : " << vertex );
284 }
285 }
286
287 auto row = _insertedVertices_.size();
288
289 for (decltype(_card_) mod = 0; mod < _card_; mod++)
290 _input_[row][mod + 1] = vertex[mod];
291
292 _insertedVertices_.push_back(vertex);
293
295 }
296
297 template < typename GUM_SCALAR >
301 "LRSWrapper< GUM_SCALAR >::H2V : fillH has not been called with "
302 "all modalities, current state is still : "
303 << _setUpStateNames_[static_cast< int >(_state_)]);
304
305 // check that we have a credal set and not a precise point probability,
306 // i.e.
307 // sum of vertex elements is close to one ( floating type precision )
308 GUM_SCALAR sum = 0;
309
310 for (const auto elem: _vertex_)
311 sum += elem;
312
313 if (std::fabs(sum - 1) < 1e-6) {
314 _output_ = std::vector< std::vector< GUM_SCALAR > >(1, _vertex_);
315 return;
316 }
317
318 // not precise point probability, initialize lrs
319
320 _initLrs_();
321
322 /* We initiate reverse search from this dictionary */
323 /* getting new dictionaries until the search is complete */
324 /* User can access each output line from output which is */
325 /* vertex/ray/facet from the lrs_mp_vector output */
326 /* prune is TRUE if tree should be pruned at current node */
327
328 // pruning is not used
329
330 std::vector< int64_t > Num; /* numerators of all vertices */
331 std::vector< int64_t > Den; /* denominators of all vertices */
332
333 do {
334 for (decltype(_dic_->d) col = 0, end = _dic_->d; col <= end; col++)
335 if (lrs_getsolution(_dic_, _dat_, _lrsOutput_, col)) {
336 // iszero macro could be used here for the test on right
337 if (_dat_->hull
338 || ((((_lrsOutput_[0])[0] == 2 || (_lrsOutput_[0])[0] == -2)
339 && (_lrsOutput_[0])[1] == 0)
340 ? 1L
341 : 0L)) {
343 "LRSWrapper< GUM_SCALAR >::H2V : asked for "
344 "Q-hull computation or not reading a vertex !");
345 } else
346 for (decltype(_dat_->n) i = 1, end = _dat_->n; i < end; i++)
348 }
349 } while (lrs_getnextbasis(&_dic_, _dat_, 0L));
350
351 auto vtx = Num.size();
352 std::vector< GUM_SCALAR > vertex(_card_);
353
354 for (decltype(vtx) i = 1; i <= vtx; i++) {
355 vertex[(i - 1) % _card_] = GUM_SCALAR(Num[i - 1] * 1.0 / Den[i - 1]);
356
357 if (i % _card_ == 0) {
358 _output_.push_back(vertex);
359 _vertices_++;
360 }
361 }
362
363 _freeLrs_();
364 }
365
366 template < typename GUM_SCALAR >
370 "LRSWrapper< GUM_SCALAR >::V2H : fillV has "
371 "not been called with all vertices, current "
372 "state is still : "
374 }
375
376 template < typename GUM_SCALAR >
380 "LRSWrapper< GUM_SCALAR >::computeVolume : "
381 "volume is only for V-representation or "
382 "fillV has not been called with all "
383 "vertices, current state is still : "
385
386 _getVolume_ = true;
387
388 _initLrs_();
389
390 do {
391 for (decltype(_dic_->d) col = 0, end = _dic_->d; col <= end; col++)
392 lrs_getsolution(_dic_, _dat_, _lrsOutput_, col);
393 } while (lrs_getnextbasis(&_dic_, _dat_, 0L));
394
395 int64_t Nsize = (_dat_->Nvolume[0] > 0) ? _dat_->Nvolume[0] : -_dat_->Nvolume[0];
396 int64_t Dsize = (_dat_->Dvolume[0] > 0) ? _dat_->Dvolume[0] : -_dat_->Dvolume[0];
397
398 int64_t num = 0L, den = 0L;
399 int64_t tmp;
400
401 for (decltype(Nsize) i = Nsize - 1; i > 0; i--) {
402 tmp = _dat_->Nvolume[i];
403
404 for (decltype(i) j = 1; j < i; j++)
405 tmp *= BASE;
406
407 num += tmp;
408 }
409
410 for (decltype(Dsize) i = Dsize - 1; i > 0; i--) {
411 tmp = _dat_->Dvolume[i];
412
413 for (decltype(i) j = 1; j < i; j++)
414 tmp *= BASE;
415
416 den += tmp;
417 }
418
419 _volume_ = num * 1.0 / den;
420
421 _freeLrs_();
422 }
423
424 template < typename GUM_SCALAR >
428 "LRSWrapper< GUM_SCALAR >::elimRedundVrep : only for "
429 "V-representation or fillV has not been called with all vertices, "
430 "current state is still : "
431 << _setUpStateNames_[static_cast< int >(_state_)]);
432
433 _initLrs_();
434
435 int64_t* redineq; /* redineq[i]=0 if ineq i non-red,1 if red,2 linearity */
436
437 /*********************************************************************************/
438 /* Test each row of the dictionary to see if it is redundant */
439 /*********************************************************************************/
440
441 /* note some of these may have been changed in getting initial dictionary
442 */
443 auto m = _dic_->m_A;
444 auto d = _dic_->d;
445 /* number of linearities in input */ /* should be 0 ! */
446 auto nlinearity = _dat_->nlinearity;
447 auto lastdv = _dat_->lastdv;
448
449 /* linearities are not considered for redundancy */
450 redineq = (int64_t*)calloc(std::size_t(m + 1), sizeof(int64_t));
451
452 for (decltype(nlinearity) i = 0; i < nlinearity; i++)
453 redineq[_dat_->linearity[i]] = 2L;
454
455 /* rows 0..lastdv are cost, decision variables, or linearities */
456 /* other rows need to be tested */
457
458 for (decltype(m + d) index = lastdv + 1, end = m + d; index <= end; index++) {
459 /* input inequality number of current index */
460 auto ineq = _dat_->inequality[index - lastdv]; /* the input inequality number
461 corr. to this index */
462
463 redineq[ineq] = checkindex(_dic_, _dat_, index);
464 }
465
466 /* linearities */
467 if (nlinearity > 0)
469 "LRSWrapper< GUM_SCALAR >::elimRedundVrep : not "
470 "reading a vertex but a linearity !");
471
472 /* count number of non-redundant inequalities */
473 /*
474 auto nredund = nlinearity;
475 for ( decltype ( m ) i = 1; i <= m; i++ )
476 if ( redineq[ i ] == 0 )
477 nredund++;
478 */
479
480 // __vertices = nredund;
481 // __output = std::vector< std::vector< GUM_SCALAR > > ( nredund,
482 // std::vector<
483 // GUM_SCALAR > ( _dat_->n - 1 ) );
484
485 for (decltype(m) i = 1; i <= m; i++)
486 if (redineq[i] == 0)
487 _output_.push_back(std::vector< GUM_SCALAR >(++_input_[std::size_t(i - 1)].begin(),
488 _input_[std::size_t(i - 1)].end()));
489
490 _vertices_ = (unsigned int)_output_.size();
491
492 _freeLrs_();
493 }
494
495 template < typename GUM_SCALAR >
497 lrs_mp Din,
498 std::vector< int64_t >& Num,
499 std::vector< int64_t >& Den) const {
500 int64_t Nsize = (Nin[0] > 0) ? Nin[0] : -Nin[0];
501 int64_t Dsize = (Din[0] > 0) ? Din[0] : -Din[0];
502
503 int64_t num = 0L;
504 int64_t den = 0L;
505
506 int64_t tmp;
507
508 for (decltype(Nsize) i = Nsize - 1; i > 0; i--) {
509 tmp = Nin[i];
510
511 for (decltype(i) j = 1; j < i; j++)
512 tmp *= BASE;
513
514 num += tmp;
515 }
516
517 if (!(Din[0] == 2L && Din[1] == 1L)) { /* rational */
518 for (decltype(Dsize) i = Dsize - 1; i > 0; i--) {
519 tmp = Din[i];
520
521 for (decltype(i) j = 1; j < i; j++)
522 tmp *= BASE;
523
524 den += tmp;
525 }
526 } else {
527 den = 1L;
528 }
529
530 int64_t Nsign = ((Nin[0] < 0) ? -1L : 1L);
531 int64_t Dsign = ((Din[0] < 0) ? -1L : 1L);
532
533 if ((Nsign * Dsign) == -1L) num = -num;
534
535 Num.push_back(num);
536 Den.push_back(den);
537 }
538
539 /*
540 void pmp (char name[], lrs_mp a) {
541 int64_t i;
542 fprintf (lrs_ofp, "%s", name);
543 if (sign (a) == NEG)
544 fprintf (lrs_ofp, "-");
545 else
546 fprintf (lrs_ofp, " ");
547 fprintf (lrs_ofp, "%lu", a[length (a) - 1]);
548 for (i = length (a) - 2; i >= 1; i--)
549 fprintf (lrs_ofp, FORMAT, a[i]);
550 fprintf (lrs_ofp, " ");
551 }*/
552
553 template < typename GUM_SCALAR >
555 std::size_t cols = _input_[0].size();
556
557 int64_t* num = new int64_t[cols]; // ISO C++ forbids variable length array,
558 // we need to do this instead
559 int64_t* den = new int64_t[cols];
560
561 int64_t rows = int64_t(_input_.size());
562
563 int64_t numerator, denominator;
564
565 for (int64_t row = 0; row < rows; row++) {
566 for (std::size_t col = 0; col < cols; col++) {
568 denominator,
569 _input_[std::size_t(row)][col]);
570
571 num[col] = numerator;
572 den[col] = denominator;
573 }
574
575 /* GE is inequality, EQ is equation */
576 /* 1L, 0L respectively */
577 lrs_set_row(_dic_,
578 _dat_,
579 int64_t(row + 1),
580 num,
581 den,
582 1L); // do NOT forget this + 1 on row
583 }
584
585 delete[] num;
586 delete[] den;
587 }
588
589 template < typename GUM_SCALAR >
593 "LRSWrapper< GUM_SCALAR >:: _initLrs_ : not ready, current state "
594 "is still : "
595 << _setUpStateNames_[static_cast< int >(_state_)]);
596
597 std::string name = "\n*LrsWrapper:";
598 std::vector< char > chars(name.c_str(), name.c_str() + name.size() + 1u);
599 // use &chars[0] as a char*
600
601 if (!lrs_init(&chars[0])) {
602 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : failed lrs_init")
603 }
604
605 name = "LRSWrapper globals";
606 chars = std::vector< char >(name.c_str(), name.c_str() + name.size() + 1u);
607
608 _dat_ = lrs_alloc_dat(&chars[0]);
609
610 if (_dat_ == nullptr) {
611 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : failed lrs_alloc_dat")
612 }
613
614 _dat_->n = Size(_input_[0].size());
615 _dat_->m = Size(_input_.size());
616
617 _dat_->getvolume = (_getVolume_) ? 1L : 0L;
618 _dat_->hull = (_hull_) ? 1L : 0L;
619 _dat_->polytope = (_polytope_) ? 1L : 0L;
620
621 _lrsOutput_ = lrs_alloc_mp_vector(_dat_->n);
622
623 _dic_ = lrs_alloc_dic(_dat_);
624
625 if (_dic_ == nullptr) {
626 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : failed lrs_alloc_dic")
627 }
628
629 _fill_();
630
631 /* Pivot to a starting dictionary */
632 if (!lrs_getfirstbasis(&_dic_, _dat_, &_Lin_, 0L)) {
633 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : failed lrs_getfirstbasis");
634 }
635
636 /* There may have been column redundancy */
637 /* If so the linearity space is obtained and redundant */
638 /* columns are removed. User can access linearity space */
639 /* from lrs_mp_matrix Lin dimensions nredundcol x d+1 */
640
641 decltype(_dat_->nredundcol) startcol = 0;
642
643 if (_dat_->homogeneous && _dat_->hull) {
644 startcol++; /* col zero not treated as redundant */
645
646 if (!_dat_->restart) {
647 for (decltype(_dat_->nredundcol) col = startcol; col < _dat_->nredundcol; col++)
648 lrs_printoutput(_dat_, _Lin_[col]);
649
650 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : redundant columns !")
651 }
652 }
653 }
654
655 template < typename GUM_SCALAR >
657 /* free space : do not change order of next lines! */
658
659 lrs_clear_mp_vector(_lrsOutput_, _dat_->n);
660
661 if (_dat_->nredundcol > 0) lrs_clear_mp_matrix(_Lin_, _dat_->nredundcol, _dat_->n);
662
663 if (_dat_->runs > 0) {
664 free(_dat_->isave);
665 free(_dat_->jsave);
666 }
667
668 auto savem = _dic_->m; /* need this to clear _dat_*/
669
670 lrs_free_dic(_dic_, _dat_); /* deallocate lrs_dic */
671
672 _dat_->m = savem;
673 lrs_free_dat(_dat_);
674
675 std::string name = "LrsWrapper:";
676 std::vector< char > chars(name.c_str(), name.c_str() + name.size() + 1u);
677
678 lrs_close(&chars[0]);
679 }
680 } // namespace credal
681} // namespace gum
Lrs wrapper.
#define BASE
Definition LrsWrapper.h:86
Exception : fatal (unknown ?) error.
Exception : operation not allowed.
Exception : out of bound.
static void continuedFracFirst(int64_t &numerator, int64_t &denominator, const GUM_SCALAR &number, const double &zero=1e-6)
Find the first best rational approximation.
std::unordered_set< int > _insertedModals_
To keep track of which constraints over modalities have been inserted.
Definition LrsWrapper.h:136
_states_ _state_
The current state of the LrsWrapper.
Definition LrsWrapper.h:164
const matrix & getOutput() const
Get the output matrix solution of the problem.
typename std::vector< std::vector< GUM_SCALAR > > matrix
Shortcut for dynamic matrix using vectors.
Definition LrsWrapper.h:121
lrs_mp_vector _lrsOutput_
One line of output of lrs : aither a ray, a vertex, a facet or a linearity.
Definition LrsWrapper.h:201
std::vector< std::vector< GUM_SCALAR > > _insertedVertices_
To keep track of inserted vertices and total.
Definition LrsWrapper.h:144
const char * _setUpStateNames_[5]
To print an enum field name instead of it's value.
Definition LrsWrapper.h:171
void setUpV(const Size &card, const Size &vertices)
Sets up a V-representation.
void H2V()
H-representation to V-representation.
void computeVolume()
Computes a polytope ( pseudo ) volume from it's V-representation.
lrs_mp_matrix _Lin_
Holds lrs input linearities if any are found.
Definition LrsWrapper.h:204
void _initLrs_()
Initialize lrs structs and first basis according to flags.
std::vector< GUM_SCALAR > _vertex_
In case we have lower = upper for all modalities, a point probability, there is no need to use lrs.
Definition LrsWrapper.h:148
lrs_dat * _dat_
Structure for holding static problem data of lrs.
Definition LrsWrapper.h:196
void elimRedundVrep()
V-Redundancy elimination.
void fillMatrix(const std::vector< std::vector< GUM_SCALAR > > &matrix)
Fill the H-representation from the matrix given in argument.
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_.
const matrix & getInput() const
Get the intput matrix of the problem.
matrix _output_
Output matrix - either a V-representation or an H-representation.
Definition LrsWrapper.h:129
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.
unsigned int _vertices_
The number of vertices of the polytope.
Definition LrsWrapper.h:139
LRSWrapper()
Default Constructor.
void fillV(const std::vector< GUM_SCALAR > &vertex)
Creates the V-representation of a polytope by adding a vertex to the problem input _input_.
unsigned int _card_
Cardinality of the variable.
Definition LrsWrapper.h:132
void _fill_() const
Fill lrs_dictionnary and datas from _input_ using integer rationals.
void V2H()
V-representation to H-representation.
GUM_SCALAR _volume_
The volume of the polytope, if computed, 0 otherwise.
Definition LrsWrapper.h:167
void _freeLrs_()
Free lrs space.
void tearDown()
Reset the wrapper as if it was built.
matrix _input_
Input matrix - either a V-representation or an H-representation.
Definition LrsWrapper.h:125
const unsigned int & getVerticesNumber() const
Get the number of vertices of this polytope.
lrs_dic * _dic_
Structure for holding current dictionary and indices of lrs.
Definition LrsWrapper.h:193
const GUM_SCALAR & getVolume() const
Get the volume of the polytope that has been computed.
~LRSWrapper()
Default Destructor.
void setUpH(const Size &card)
Sets up an H-representation.
void nextHInput()
Reset the wrapper for next computation for a H-representation with the same variable cardinality and ...
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
namespace for all credal networks entities
Definition agrum.h:61
gum is the global namespace for all aGrUM entities
Definition agrum.h:46