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