aGrUM 3.1.1
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-2026 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-2026 *
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
41#pragma once
42
43
44#include <string.h>
45
46#include <agrum/agrum.h>
47
49
51
52namespace gum {
53 namespace credal {
54
55 template < GUM_Numeric GUM_SCALAR >
58
59 _vertices_ = 0;
60 _card_ = 0;
61
62 _volume_ = 0;
63
64 _getVolume_ = false;
65 _hull_ = false;
66 _polytope_ = false;
67
68 GUM_CONSTRUCTOR(LRSWrapper);
69 }
70
71 template < GUM_Numeric GUM_SCALAR >
75
76 template < GUM_Numeric GUM_SCALAR >
78 return _input_;
79 }
80
81 template < GUM_Numeric GUM_SCALAR >
83 return _output_;
84 }
85
86 template < GUM_Numeric GUM_SCALAR >
87 const unsigned int& LRSWrapper< GUM_SCALAR >::getVerticesNumber() const {
88 return _vertices_;
89 }
90
91 template < GUM_Numeric GUM_SCALAR >
92 const GUM_SCALAR& LRSWrapper< GUM_SCALAR >::getVolume() const {
93 if (_volume_ != 0) return _volume_;
94 else
96 "LRSWrapper< GUM_SCALAR >::getVolume () : "
97 "volume computation was not asked for this "
98 "credal set, call computeVolume() from a "
99 "V-representation.");
100 }
101
102 template < GUM_Numeric GUM_SCALAR >
104 if (card < 2)
106 "LRSWrapper< GUM_SCALAR >::setUpH : "
107 "cardinality must be at least 2");
108
109 tearDown();
110
111 _input_ = std::vector< std::vector< GUM_SCALAR > >(card * 2 + 2,
112 std::vector< GUM_SCALAR >(card + 1, 0));
113
114 _input_[card * 2] = std::vector< GUM_SCALAR >(card + 1, -1);
115 _input_[card * 2][0] = 1;
116
117 _input_[card * 2 + 1] = std::vector< GUM_SCALAR >(card + 1, 1);
118 _input_[card * 2 + 1][0] = -1;
119
120 _output_ = std::vector< std::vector< GUM_SCALAR > >();
121
122 _vertex_ = std::vector< GUM_SCALAR >(card);
123
125
126 _card_ = (unsigned int)card;
127 }
128
129 template < GUM_Numeric GUM_SCALAR >
130 void LRSWrapper< GUM_SCALAR >::setUpV(const Size& card, const Size& vertices) {
131 if (card < 2)
133 "LRSWrapper< GUM_SCALAR >::setUpV : "
134 "cardinality must be at least 2");
135
136 if (vertices < 2)
138 "LRSWrapper< GUM_SCALAR >::setUpV : vertices "
139 "must be at least 2 to build a polytope");
140
141 tearDown();
142
143 _input_ = std::vector< std::vector< GUM_SCALAR > >(vertices,
144 std::vector< GUM_SCALAR >(card + 1, 1));
145
146 _output_ = std::vector< std::vector< GUM_SCALAR > >();
147
149
150 _card_ = (unsigned int)card;
151 _vertices_ = (unsigned int)vertices;
152 }
153
154 template < GUM_Numeric GUM_SCALAR >
156 _input_.clear();
157 _output_.clear();
158 _vertex_.clear();
159 _insertedModals_.clear();
160
161 _insertedVertices_.clear();
162 _vertices_ = 0;
163
164 _volume_ = 0;
165
167 _card_ = 0;
168
169 _getVolume_ = false;
170 _hull_ = false;
171 _polytope_ = false;
172 }
173
174 template < GUM_Numeric GUM_SCALAR >
176 _insertedModals_.clear();
177 _insertedVertices_.clear();
178 _output_.clear();
179 _vertex_.clear();
180 _vertex_.resize(_card_, 0);
181
182 _volume_ = 0;
183 _vertices_ = 0;
184
185 _getVolume_ = false;
186 _hull_ = false;
187 _polytope_ = false;
188
190 else if (_state_ == _states_::V2Hready) {
193 "LRSWrapper< GUM_SCALAR >::nextHInput : only for H-representation "
194 "as input. Previous state was : "
195 << _setUpStateNames_[static_cast< int >(_state_)]);
196 } else {
197 _input_.clear();
199 _card_ = 0;
200 _vertex_.clear();
201 }
202 }
203
204 template < GUM_Numeric GUM_SCALAR >
205 void LRSWrapper< GUM_SCALAR >::fillH(const GUM_SCALAR& min,
206 const GUM_SCALAR& max,
207 const Size& modal) {
208 if (_state_ != _states_::Hup)
210 "LRSWrapper< GUM_SCALAR >::fillH : setUpH or nextInput has not "
211 "been called or H-representation is complete, current state is : "
212 << _setUpStateNames_[static_cast< int >(_state_)]);
213
214 if (modal >= _card_)
216 "LRSWrapper< GUM_SCALAR >::fillH : modality is "
217 "greater or equal than cardinality : "
218 << modal << " >= " << _card_);
219
220 _input_[modal * 2][0] = -min;
221 _input_[modal * 2][modal + 1] = 1;
222
223 _input_[modal * 2 + 1][0] = max;
224 _input_[modal * 2 + 1][modal + 1] = -1;
225
226 _vertex_[modal] = max;
227
228 _insertedModals_.insert(int(modal));
229
231 }
232
233 template < GUM_Numeric GUM_SCALAR >
235 const std::vector< std::vector< GUM_SCALAR > >& matrix) {
236 if (_state_ != _states_::Hup)
238 "LRSWrapper< GUM_SCALAR >::fillH : setUpH or nextInput has not "
239 "been called or H-representation is complete, current state is : "
240 << _setUpStateNames_[static_cast< int >(_state_)]);
241
242 if (matrix[0].size() - 1 != _card_)
244 "LRSWrapper< GUM_SCALAR >::fillMatrix : size is "
245 "different than cardinality : "
246 << (matrix[0].size() - 1) << " != " << _card_);
247
248 _input_ = matrix;
249
250 for (unsigned int modal = 0; modal < _card_; modal++) {
251 _insertedModals_.insert(modal);
252 }
253
255 }
256
257 template < GUM_Numeric GUM_SCALAR >
258 void LRSWrapper< GUM_SCALAR >::fillV(const std::vector< GUM_SCALAR >& vertex) {
259 if (_state_ != _states_::Vup)
261 "LRSWrapper< GUM_SCALAR >::fillV : setUpV or nextInput has not "
262 "been called or V-representation is complete, current state is : "
263 << _setUpStateNames_[static_cast< int >(_state_)]);
264
265 if (_insertedVertices_.size() == _vertices_)
267 "LRSWrapper< GUM_SCALAR >::fillV : input is already full with " << _vertices_
268 << " vertices.");
269
270 bool eq = true;
271
272 for (const auto& v: _insertedVertices_) {
273 eq = true;
274
275 for (decltype(_card_) mod = 0; mod < _card_; mod++)
276 if (std::fabs(v[mod] - vertex[mod]) > 1e-6) {
277 eq = false;
278 break;
279 }
280
281 if (eq) {
282 _vertices_--;
283 return;
284 // GUM_ERROR ( DuplicateElement, "LRSWrapper< GUM_SCALAR >::fillV :
285 // vertex
286 // already present : " << vertex );
287 }
288 }
289
290 auto row = _insertedVertices_.size();
291
292 for (decltype(_card_) mod = 0; mod < _card_; mod++)
293 _input_[row][mod + 1] = vertex[mod];
294
295 _insertedVertices_.push_back(vertex);
296
298 }
299
300 template < GUM_Numeric GUM_SCALAR >
304 "LRSWrapper< GUM_SCALAR >::H2V : fillH has not been called with "
305 "all modalities, current state is still : "
306 << _setUpStateNames_[static_cast< int >(_state_)]);
307
308 // check that we have a credal set and not a precise point probability,
309 // i.e.
310 // sum of vertex elements is close to one ( floating type precision )
311 GUM_SCALAR sum = 0;
312
313 for (const auto elem: _vertex_)
314 sum += elem;
315
316 if (gum::isCloseToOne(sum, GUM_SCALAR(1e-6))) {
317 _output_ = std::vector< std::vector< GUM_SCALAR > >(1, _vertex_);
318 return;
319 }
320
321 // not precise point probability, initialize lrs
322
323 _initLrs_();
324
325 /* We initiate reverse search from this dictionary */
326 /* getting new dictionaries until the search is complete */
327 /* User can access each output line from output which is */
328 /* vertex/ray/facet from the lrs_mp_vector output */
329 /* prune is TRUE if tree should be pruned at current node */
330
331 // pruning is not used
332
333 std::vector< int64_t > Num; /* numerators of all vertices */
334 std::vector< int64_t > Den; /* denominators of all vertices */
335
336 do {
337 for (decltype(_dic_->d) col = 0, end = _dic_->d; col <= end; col++)
338 if (lrs_getsolution(_dic_, _dat_, _lrsOutput_, col)) {
339 // iszero macro could be used here for the test on right
340 if (_dat_->hull
341 || ((((_lrsOutput_[0])[0] == 2 || (_lrsOutput_[0])[0] == -2)
342 && (_lrsOutput_[0])[1] == 0)
343 ? 1L
344 : 0L)) {
346 "LRSWrapper< GUM_SCALAR >::H2V : asked for "
347 "Q-hull computation or not reading a vertex !");
348 } else
349 for (decltype(_dat_->n) i = 1, end = _dat_->n; i < end; i++)
351 }
352 } while (lrs_getnextbasis(&_dic_, _dat_, 0L));
353
354 auto vtx = Num.size();
355 std::vector< GUM_SCALAR > vertex(_card_);
356
357 for (decltype(vtx) i = 1; i <= vtx; i++) {
358 vertex[(i - 1) % _card_] = GUM_SCALAR(Num[i - 1] * 1.0 / Den[i - 1]);
359
360 if (i % _card_ == 0) {
361 _output_.push_back(vertex);
362 _vertices_++;
363 }
364 }
365
366 _freeLrs_();
367 }
368
369 template < GUM_Numeric GUM_SCALAR >
373 "LRSWrapper< GUM_SCALAR >::V2H : fillV has "
374 "not been called with all vertices, current "
375 "state is still : "
377 }
378
379 template < GUM_Numeric GUM_SCALAR >
383 "LRSWrapper< GUM_SCALAR >::computeVolume : "
384 "volume is only for V-representation or "
385 "fillV has not been called with all "
386 "vertices, current state is still : "
388
389 _getVolume_ = true;
390
391 _initLrs_();
392
393 do {
394 for (decltype(_dic_->d) col = 0, end = _dic_->d; col <= end; col++)
395 lrs_getsolution(_dic_, _dat_, _lrsOutput_, col);
396 } while (lrs_getnextbasis(&_dic_, _dat_, 0L));
397
398 int64_t Nsize = (_dat_->Nvolume[0] > 0) ? _dat_->Nvolume[0] : -_dat_->Nvolume[0];
399 int64_t Dsize = (_dat_->Dvolume[0] > 0) ? _dat_->Dvolume[0] : -_dat_->Dvolume[0];
400
401 int64_t num = 0L, den = 0L;
402 int64_t tmp;
403
404 for (decltype(Nsize) i = Nsize - 1; i > 0; i--) {
405 tmp = _dat_->Nvolume[i];
406
407 for (decltype(i) j = 1; j < i; j++)
408 tmp *= BASE;
409
410 num += tmp;
411 }
412
413 for (decltype(Dsize) i = Dsize - 1; i > 0; i--) {
414 tmp = _dat_->Dvolume[i];
415
416 for (decltype(i) j = 1; j < i; j++)
417 tmp *= BASE;
418
419 den += tmp;
420 }
421
422 _volume_ = num * 1.0 / den;
423
424 _freeLrs_();
425 }
426
427 template < GUM_Numeric GUM_SCALAR >
431 "LRSWrapper< GUM_SCALAR >::elimRedundVrep : only for "
432 "V-representation or fillV has not been called with all vertices, "
433 "current state is still : "
434 << _setUpStateNames_[static_cast< int >(_state_)]);
435
436 _initLrs_();
437
438 int64_t* redineq; /* redineq[i]=0 if ineq i non-red,1 if red,2 linearity */
439
440 /*********************************************************************************/
441 /* Test each row of the dictionary to see if it is redundant */
442 /*********************************************************************************/
443
444 /* note some of these may have been changed in getting initial dictionary
445 */
446 auto m = _dic_->m_A;
447 auto d = _dic_->d;
448 /* number of linearities in input */ /* should be 0 ! */
449 auto nlinearity = _dat_->nlinearity;
450 auto lastdv = _dat_->lastdv;
451
452 /* linearities are not considered for redundancy */
453 redineq = (int64_t*)calloc(std::size_t(m + 1), sizeof(int64_t));
454
455 for (decltype(nlinearity) i = 0; i < nlinearity; i++)
456 redineq[_dat_->linearity[i]] = 2L;
457
458 /* rows 0..lastdv are cost, decision variables, or linearities */
459 /* other rows need to be tested */
460
461 for (decltype(m + d) index = lastdv + 1, end = m + d; index <= end; index++) {
462 /* input inequality number of current index */
463 auto ineq = _dat_->inequality[index - lastdv]; /* the input inequality number
464 corr. to this index */
465
466 redineq[ineq] = checkindex(_dic_, _dat_, index);
467 }
468
469 /* linearities */
470 if (nlinearity > 0)
472 "LRSWrapper< GUM_SCALAR >::elimRedundVrep : not "
473 "reading a vertex but a linearity !");
474
475 /* count number of non-redundant inequalities */
476 /*
477 auto nredund = nlinearity;
478 for ( decltype ( m ) i = 1; i <= m; i++ )
479 if ( redineq[ i ] == 0 )
480 nredund++;
481 */
482
483 // __vertices = nredund;
484 // __output = std::vector< std::vector< GUM_SCALAR > > ( nredund,
485 // std::vector<
486 // GUM_SCALAR > ( _dat_->n - 1 ) );
487
488 for (decltype(m) i = 1; i <= m; i++)
489 if (redineq[i] == 0)
490 _output_.push_back(std::vector< GUM_SCALAR >(++_input_[std::size_t(i - 1)].begin(),
491 _input_[std::size_t(i - 1)].end()));
492
493 _vertices_ = (unsigned int)_output_.size();
494
495 _freeLrs_();
496 }
497
498 template < GUM_Numeric GUM_SCALAR >
500 lrs_mp Din,
501 std::vector< int64_t >& Num,
502 std::vector< int64_t >& Den) const {
503 int64_t Nsize = (Nin[0] > 0) ? Nin[0] : -Nin[0];
504 int64_t Dsize = (Din[0] > 0) ? Din[0] : -Din[0];
505
506 int64_t num = 0L;
507 int64_t den = 0L;
508
509 int64_t tmp;
510
511 for (decltype(Nsize) i = Nsize - 1; i > 0; i--) {
512 tmp = Nin[i];
513
514 for (decltype(i) j = 1; j < i; j++)
515 tmp *= BASE;
516
517 num += tmp;
518 }
519
520 if (!(Din[0] == 2L && Din[1] == 1L)) { /* rational */
521 for (decltype(Dsize) i = Dsize - 1; i > 0; i--) {
522 tmp = Din[i];
523
524 for (decltype(i) j = 1; j < i; j++)
525 tmp *= BASE;
526
527 den += tmp;
528 }
529 } else {
530 den = 1L;
531 }
532
533 int64_t Nsign = ((Nin[0] < 0) ? -1L : 1L);
534 int64_t Dsign = ((Din[0] < 0) ? -1L : 1L);
535
536 if ((Nsign * Dsign) == -1L) num = -num;
537
538 Num.push_back(num);
539 Den.push_back(den);
540 }
541
542 /*
543 void pmp (char name[], lrs_mp a) {
544 int64_t i;
545 fprintf (lrs_ofp, "%s", name);
546 if (sign (a) == NEG)
547 fprintf (lrs_ofp, "-");
548 else
549 fprintf (lrs_ofp, " ");
550 fprintf (lrs_ofp, "%lu", a[length (a) - 1]);
551 for (i = length (a) - 2; i >= 1; i--)
552 fprintf (lrs_ofp, FORMAT, a[i]);
553 fprintf (lrs_ofp, " ");
554 }*/
555
556 template < GUM_Numeric GUM_SCALAR >
558 std::size_t cols = _input_[0].size();
559
560 int64_t* num = new int64_t[cols]; // ISO C++ forbids variable length array,
561 // we need to do this instead
562 int64_t* den = new int64_t[cols];
563
564 int64_t rows = int64_t(_input_.size());
565
566 int64_t numerator, denominator;
567
568 for (int64_t row = 0; row < rows; row++) {
569 for (std::size_t col = 0; col < cols; col++) {
571 denominator,
572 _input_[std::size_t(row)][col]);
573
574 num[col] = numerator;
575 den[col] = denominator;
576 }
577
578 /* GE is inequality, EQ is equation */
579 /* 1L, 0L respectively */
580 lrs_set_row(_dic_,
581 _dat_,
582 int64_t(row + 1),
583 num,
584 den,
585 1L); // do NOT forget this + 1 on row
586 }
587
588 delete[] num;
589 delete[] den;
590 }
591
592 template < GUM_Numeric GUM_SCALAR >
596 "LRSWrapper< GUM_SCALAR >:: _initLrs_ : not ready, current state "
597 "is still : "
598 << _setUpStateNames_[static_cast< int >(_state_)]);
599
600 std::string name = "\n*LrsWrapper:";
601 std::vector< char > chars(name.c_str(), name.c_str() + name.size() + 1u);
602 // use &chars[0] as a char*
603
604 if (!lrs_init(&chars[0])) {
605 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : failed lrs_init")
606 }
607
608 name = "LRSWrapper globals";
609 chars = std::vector< char >(name.c_str(), name.c_str() + name.size() + 1u);
610
611 _dat_ = lrs_alloc_dat(&chars[0]);
612
613 if (_dat_ == nullptr) {
614 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : failed lrs_alloc_dat")
615 }
616
617 _dat_->n = Size(_input_[0].size());
618 _dat_->m = Size(_input_.size());
619
620 _dat_->getvolume = (_getVolume_) ? 1L : 0L;
621 _dat_->hull = (_hull_) ? 1L : 0L;
622 _dat_->polytope = (_polytope_) ? 1L : 0L;
623
624 _lrsOutput_ = lrs_alloc_mp_vector(_dat_->n);
625
626 _dic_ = lrs_alloc_dic(_dat_);
627
628 if (_dic_ == nullptr) {
629 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : failed lrs_alloc_dic")
630 }
631
632 _fill_();
633
634 /* Pivot to a starting dictionary */
635 if (!lrs_getfirstbasis(&_dic_, _dat_, &_Lin_, 0L)) {
636 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : failed lrs_getfirstbasis");
637 }
638
639 /* There may have been column redundancy */
640 /* If so the linearity space is obtained and redundant */
641 /* columns are removed. User can access linearity space */
642 /* from lrs_mp_matrix Lin dimensions nredundcol x d+1 */
643
644 decltype(_dat_->nredundcol) startcol = 0;
645
646 if (_dat_->homogeneous && _dat_->hull) {
647 startcol++; /* col zero not treated as redundant */
648
649 if (!_dat_->restart) {
650 for (decltype(_dat_->nredundcol) col = startcol; col < _dat_->nredundcol; col++)
651 lrs_printoutput(_dat_, _Lin_[col]);
652
653 GUM_ERROR(FatalError, "LRSWrapper< GUM_SCALAR >:: _initLrs_ : redundant columns !")
654 }
655 }
656 }
657
658 template < GUM_Numeric GUM_SCALAR >
660 /* free space : do not change order of next lines! */
661
662 lrs_clear_mp_vector(_lrsOutput_, _dat_->n);
663
664 if (_dat_->nredundcol > 0) lrs_clear_mp_matrix(_Lin_, _dat_->nredundcol, _dat_->n);
665
666 if (_dat_->runs > 0) {
667 free(_dat_->isave);
668 free(_dat_->jsave);
669 }
670
671 auto savem = _dic_->m; /* need this to clear _dat_*/
672
673 lrs_free_dic(_dic_, _dat_); /* deallocate lrs_dic */
674
675 _dat_->m = savem;
676 lrs_free_dat(_dat_);
677
678 std::string name = "LrsWrapper:";
679 std::vector< char > chars(name.c_str(), name.c_str() + name.size() + 1u);
680
681 lrs_close(&chars[0]);
682 }
683 } // namespace credal
684} // namespace gum
Lrs wrapper.
#define BASE
Definition LrsWrapper.h:88
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:138
_states_ _state_
The current state of the LrsWrapper.
Definition LrsWrapper.h:166
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:123
lrs_mp_vector _lrsOutput_
One line of output of lrs : aither a ray, a vertex, a facet or a linearity.
Definition LrsWrapper.h:203
std::vector< std::vector< GUM_SCALAR > > _insertedVertices_
To keep track of inserted vertices and total.
Definition LrsWrapper.h:146
const char * _setUpStateNames_[5]
To print an enum field name instead of it's value.
Definition LrsWrapper.h:173
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:206
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:150
lrs_dat * _dat_
Structure for holding static problem data of lrs.
Definition LrsWrapper.h:198
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:131
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:141
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:134
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:169
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:127
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:195
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:76
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Useful macros for maths.
namespace for all credal networks entities
Definition agrum.h:61
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
bool isCloseToOne(T x, T tol=T(1e-9))