aGrUM  0.13.2
LrsWrapper_tpl.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * Copyright (C) 2017 by Pierre-Henri WUILLEMIN and Christophe GONZALES *
4  * {prenom.nom}_at_lip6.fr *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
21 
22 
23 #include <string.h>
24 
25 #include <agrum/CN/LrsWrapper.h>
26 #include <agrum/agrum.h>
27 
28 namespace gum {
29  namespace credal {
30 
31  template < typename GUM_SCALAR >
33  __state = __states::none;
34 
35  __vertices = 0;
36  __card = 0;
37 
38  __volume = 0;
39 
40  __getVolume = false;
41  __hull = false;
42  __polytope = false;
43 
44  GUM_CONSTRUCTOR(LRSWrapper);
45  }
46 
47  template < typename GUM_SCALAR >
49  GUM_DESTRUCTOR(LRSWrapper);
50  }
51 
52  template < typename GUM_SCALAR >
53  auto LRSWrapper< GUM_SCALAR >::getInput() const -> const matrix& {
54  return __input;
55  }
56 
57  template < typename GUM_SCALAR >
59  return __output;
60  }
61 
62  template < typename GUM_SCALAR >
63  const unsigned int& LRSWrapper< GUM_SCALAR >::getVerticesNumber() const {
64  return __vertices;
65  }
66 
67  template < typename GUM_SCALAR >
68  const GUM_SCALAR& LRSWrapper< GUM_SCALAR >::getVolume() const {
69  if (__volume != 0)
70  return __volume;
71  else
73  "LRSWrapper< GUM_SCALAR >::getVolume () : "
74  "volume computation was not asked for this "
75  "credal set, call computeVolume() from a "
76  "V-representation.");
77  }
78 
79  template < typename GUM_SCALAR >
80  void LRSWrapper< GUM_SCALAR >::setUpH(const unsigned int& card) {
81  if (card < 2)
83  "LRSWrapper< GUM_SCALAR >::setUpH : "
84  "cardinality must be at least 2");
85 
86  tearDown();
87 
88  __input = std::vector< std::vector< GUM_SCALAR > >(
89  card * 2 + 2, std::vector< GUM_SCALAR >(card + 1, 0));
90 
91  __input[card * 2] = std::vector< GUM_SCALAR >(card + 1, -1);
92  __input[card * 2][0] = 1;
93 
94  __input[card * 2 + 1] = std::vector< GUM_SCALAR >(card + 1, 1);
95  __input[card * 2 + 1][0] = -1;
96 
97  __output = std::vector< std::vector< GUM_SCALAR > >();
98 
99  __vertex = std::vector< GUM_SCALAR >(card);
100 
101  __state = __states::Hup;
102 
103  __card = card;
104  }
105 
106  template < typename GUM_SCALAR >
107  void LRSWrapper< GUM_SCALAR >::setUpV(const unsigned int& card,
108  const unsigned int& vertices) {
109  if (card < 2)
111  "LRSWrapper< GUM_SCALAR >::setUpV : "
112  "cardinality must be at least 2");
113 
114  if (vertices < 2)
116  "LRSWrapper< GUM_SCALAR >::setUpV : vertices "
117  "must be at least 2 to build a polytope");
118 
119  tearDown();
120 
121  __input = std::vector< std::vector< GUM_SCALAR > >(
122  vertices, std::vector< GUM_SCALAR >(card + 1, 1));
123 
124  __output = std::vector< std::vector< GUM_SCALAR > >();
125 
126  __state = __states::Vup;
127 
128  __card = card;
129  __vertices = vertices;
130  }
131 
132  template < typename GUM_SCALAR >
134  __input.clear();
135  __output.clear();
136  __vertex.clear();
137  __insertedModals.clear();
138 
139  __insertedVertices.clear();
140  __vertices = 0;
141 
142  __volume = 0;
143 
144  __state = __states::none;
145  __card = 0;
146 
147  __getVolume = false;
148  __hull = false;
149  __polytope = false;
150  }
151 
152  template < typename GUM_SCALAR >
154  __insertedModals.clear();
155  __insertedVertices.clear();
156  __output.clear();
157  __vertex.clear();
158  __vertex.resize(__card, 0);
159 
160  __volume = 0;
161  __vertices = 0;
162 
163  __getVolume = false;
164  __hull = false;
165  __polytope = false;
166 
167  if (__state == __states::H2Vready)
168  __state = __states::Hup;
169  else if (__state == __states::V2Hready) {
170  __state = __states::Vup;
171  GUM_ERROR(
173  "LRSWrapper< GUM_SCALAR >::nextHInput : only for H-representation "
174  "as input. Previous state was : "
175  << __setUpStateNames[static_cast< int >(__state)]);
176  } else {
177  __input.clear();
178  __state = __states::none;
179  __card = 0;
180  __vertex.clear();
181  }
182  }
183 
184  template < typename GUM_SCALAR >
185  void LRSWrapper< GUM_SCALAR >::fillH(const GUM_SCALAR& min,
186  const GUM_SCALAR& max,
187  const unsigned int& modal) {
188  if (__state != __states::Hup)
189  GUM_ERROR(
191  "LRSWrapper< GUM_SCALAR >::fillH : setUpH or nextInput has not "
192  "been called or H-representation is complete, current state is : "
193  << __setUpStateNames[static_cast< int >(__state)]);
194 
195  if (modal >= __card)
197  "LRSWrapper< GUM_SCALAR >::fillH : modality is "
198  "greater or equal than cardinality : "
199  << modal << " >= " << __card);
200 
201  __input[modal * 2][0] = -min;
202  __input[modal * 2][modal + 1] = 1;
203 
204  __input[modal * 2 + 1][0] = max;
205  __input[modal * 2 + 1][modal + 1] = -1;
206 
207  __vertex[modal] = max;
208 
209  __insertedModals.insert(modal);
210 
211  if (__insertedModals.size() == __card) __state = __states::H2Vready;
212  }
213 
214  template < typename GUM_SCALAR >
216  const std::vector< std::vector< GUM_SCALAR > >& matrix) {
217  if (__state != __states::Hup)
218  GUM_ERROR(
220  "LRSWrapper< GUM_SCALAR >::fillH : setUpH or nextInput has not "
221  "been called or H-representation is complete, current state is : "
222  << __setUpStateNames[static_cast< int >(__state)]);
223 
224  if (matrix[0].size() - 1 != __card)
226  "LRSWrapper< GUM_SCALAR >::fillMatrix : size is "
227  "different than cardinality : "
228  << (matrix[0].size() - 1) << " != " << __card);
229 
230  __input = matrix;
231 
232  for (unsigned int modal = 0; modal < __card; modal++) {
233  __insertedModals.insert(modal);
234  }
235 
236  __state = __states::H2Vready;
237  }
238 
239  template < typename GUM_SCALAR >
240  void LRSWrapper< GUM_SCALAR >::fillV(const std::vector< GUM_SCALAR >& vertex) {
241  if (__state != __states::Vup)
242  GUM_ERROR(
244  "LRSWrapper< GUM_SCALAR >::fillV : setUpV or nextInput has not "
245  "been called or V-representation is complete, current state is : "
246  << __setUpStateNames[static_cast< int >(__state)]);
247 
248  if (__insertedVertices.size() == __vertices)
250  "LRSWrapper< GUM_SCALAR >::fillV : input is already full with "
251  << __vertices << " vertices.");
252 
253  bool eq = true;
254 
255  for (const auto& v : __insertedVertices) {
256  eq = true;
257 
258  for (decltype(__card) mod = 0; mod < __card; mod++)
259  if (std::fabs(v[mod] - vertex[mod]) > 1e-6) {
260  eq = false;
261  break;
262  }
263 
264  if (eq) {
265  __vertices--;
266  return;
267  // GUM_ERROR ( DuplicateElement, "LRSWrapper< GUM_SCALAR >::fillV :
268  // vertex
269  // already present : " << vertex );
270  }
271  }
272 
273  auto row = __insertedVertices.size();
274 
275  for (decltype(__card) mod = 0; mod < __card; mod++)
276  __input[row][mod + 1] = vertex[mod];
277 
278  __insertedVertices.push_back(vertex);
279 
280  if (__insertedVertices.size() == __vertices) __state = __states::V2Hready;
281  }
282 
283  template < typename GUM_SCALAR >
285  if (__state != __states::H2Vready)
287  "LRSWrapper< GUM_SCALAR >::H2V : fillH has not been called with "
288  "all modalities, current state is still : "
289  << __setUpStateNames[static_cast< int >(__state)]);
290 
291  // check that we have a credal set and not a precise point probability,
292  // i.e.
293  // sum of vertex elements is close to one ( floating type precision )
294  GUM_SCALAR sum = 0;
295 
296  for (const auto elem : __vertex)
297  sum += elem;
298 
299  if (std::fabs(sum - 1) < 1e-6) {
300  __output = std::vector< std::vector< GUM_SCALAR > >(1, __vertex);
301  return;
302  }
303 
304  // not precise point probability, initialize lrs
305 
306  // __coutOff();
307 
308  __initLrs();
309 
310  /* We initiate reverse search from this dictionary */
311  /* getting new dictionaries until the search is complete */
312  /* User can access each output line from output which is */
313  /* vertex/ray/facet from the lrs_mp_vector output */
314  /* prune is TRUE if tree should be pruned at current node */
315 
316  // pruning is not used
317 
318  std::vector< int64_t > Num; /* numerators of all vertices */
319  std::vector< int64_t > Den; /* denominators of all vertices */
320 
321  do {
322  for (decltype(__dic->d) col = 0, end = __dic->d; col <= end; col++)
323  if (lrs_getsolution(__dic, __dat, __lrsOutput, col)) {
324  // iszero macro could be used here for the test on right
325  if (__dat->hull
326  || ((((__lrsOutput[0])[0] == 2 || (__lrsOutput[0])[0] == -2)
327  && (__lrsOutput[0])[1] == 0)
328  ? 1L
329  : 0L)) {
330  // __coutOn();
331  /*for ( decltype(Q->n) i = 0; i < Q->n; i++ )
332  pmp ("", output[i]);*/
334  "LRSWrapper< GUM_SCALAR >::H2V : asked for "
335  "Q-hull computation or not reading a vertex !");
336  } else
337  for (decltype(__dat->n) i = 1, end = __dat->n; i < end; i++)
338  __getLRSWrapperOutput(__lrsOutput[i], __lrsOutput[0], Num, Den);
339  }
340  } while (lrs_getnextbasis(&__dic, __dat, 0L));
341 
342  auto vtx = Num.size();
343  std::vector< GUM_SCALAR > vertex(__card);
344 
345  for (decltype(vtx) i = 1; i <= vtx; i++) {
346  vertex[(i - 1) % __card] = GUM_SCALAR(Num[i - 1] * 1.0 / Den[i - 1]);
347 
348  if (i % __card == 0) {
349  __output.push_back(vertex);
350  __vertices++;
351  }
352  }
353 
354  __freeLrs();
355 
356  // __coutOn();
357  }
358 
359  template < typename GUM_SCALAR >
361  if (!__state == __states::V2Hready)
363  "LRSWrapper< GUM_SCALAR >::V2H : fillV has "
364  "not been called with all vertices, current "
365  "state is still : "
366  << __setUpStateNames[__state]);
367  }
368 
369  template < typename GUM_SCALAR >
371  if (!__state == __states::V2Hready)
373  "LRSWrapper< GUM_SCALAR >::computeVolume : "
374  "volume is only for V-representation or "
375  "fillV has not been called with all "
376  "vertices, current state is still : "
377  << __setUpStateNames[__state]);
378 
379  // __coutOff();
380 
381  __getVolume = true;
382 
383  __initLrs();
384 
385  do {
386  for (decltype(__dic->d) col = 0, end = __dic->d; col <= end; col++)
387  lrs_getsolution(__dic, __dat, __lrsOutput, col);
388  } while (lrs_getnextbasis(&__dic, __dat, 0L));
389 
390  int64_t Nsize =
391  (__dat->Nvolume[0] > 0) ? __dat->Nvolume[0] : -__dat->Nvolume[0];
392  int64_t Dsize =
393  (__dat->Dvolume[0] > 0) ? __dat->Dvolume[0] : -__dat->Dvolume[0];
394 
395  int64_t num = 0L, den = 0L;
396  int64_t tmp;
397 
398  for (decltype(Nsize) i = Nsize - 1; i > 0; i--) {
399  tmp = __dat->Nvolume[i];
400 
401  for (decltype(i) j = 1; j < i; j++)
402  tmp *= BASE;
403 
404  num += tmp;
405  }
406 
407  for (decltype(Dsize) i = Dsize - 1; i > 0; i--) {
408  tmp = __dat->Dvolume[i];
409 
410  for (decltype(i) j = 1; j < i; j++)
411  tmp *= BASE;
412 
413  den += tmp;
414  }
415 
416  __volume = num * 1.0 / den;
417 
418  __freeLrs();
419 
420  // __coutOn();
421  }
422 
423  template < typename GUM_SCALAR >
425  if (__state != __states::V2Hready)
426  GUM_ERROR(
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  // __coutOff();
434 
435  __initLrs();
436 
437  int64_t* redineq; /* redineq[i]=0 if ineq i non-red,1 if red,2 linearity */
438 
439  /*********************************************************************************/
440  /* Test each row of the dictionary to see if it is redundant */
441  /*********************************************************************************/
442 
443  /* note some of these may have been changed in getting initial dictionary
444  */
445  auto m = __dic->m_A;
446  auto d = __dic->d;
447  /* number of linearities in input */ /* should be 0 ! */
448  auto nlinearity = __dat->nlinearity;
449  auto lastdv = __dat->lastdv;
450 
451  /* linearities are not considered for redundancy */
452  redineq = (int64_t*)calloc((m + 1), sizeof(int64_t));
453 
454  for (decltype(nlinearity) i = 0; i < nlinearity; i++)
455  redineq[__dat->linearity[i]] = 2L;
456 
457  /* rows 0..lastdv are cost, decision variables, or linearities */
458  /* other rows need to be tested */
459 
460  for (decltype(m + d) index = lastdv + 1, end = m + d; index <= end;
461  index++) {
462  /* input inequality number of current index */
463  auto ineq =
464  __dat->inequality[index - lastdv]; /* the input inequality number corr.
465  to this index */
466 
467  redineq[ineq] = checkindex(__dic, __dat, index);
468  }
469 
470  /* linearities */
471  if (nlinearity > 0)
473  "LRSWrapper< GUM_SCALAR >::elimRedundVrep : not "
474  "reading a vertex but a linearity !");
475 
476  /* count number of non-redundant inequalities */
477  /*
478  auto nredund = nlinearity;
479  for ( decltype ( m ) i = 1; i <= m; i++ )
480  if ( redineq[ i ] == 0 )
481  nredund++;
482  */
483 
484  //__vertices = nredund;
485  //__output = std::vector< std::vector< GUM_SCALAR > > ( nredund,
486  // std::vector<
487  // GUM_SCALAR > ( __dat->n - 1 ) );
488 
489  for (decltype(m) i = 1; i <= m; i++)
490  if (redineq[i] == 0)
491  __output.push_back(std::vector< GUM_SCALAR >(++__input[i - 1].begin(),
492  __input[i - 1].end()));
493 
494  __vertices = (unsigned int)__output.size();
495 
496  __freeLrs();
497 
498  // __coutOn();
499  }
500 
501  template < typename GUM_SCALAR >
503  lrs_mp Nin,
504  lrs_mp Din,
505  std::vector< int64_t >& Num,
506  std::vector< int64_t >& Den) const {
507  int64_t Nsize = (Nin[0] > 0) ? Nin[0] : -Nin[0];
508  int64_t Dsize = (Din[0] > 0) ? Din[0] : -Din[0];
509 
510  int64_t num = 0L;
511  int64_t den = 0L;
512 
513  int64_t tmp;
514 
515  for (decltype(Nsize) i = Nsize - 1; i > 0; i--) {
516  tmp = Nin[i];
517 
518  for (decltype(i) j = 1; j < i; j++)
519  tmp *= BASE;
520 
521  num += tmp;
522  }
523 
524  if (!(Din[0] == 2L && Din[1] == 1L)) { /* rational */
525  for (decltype(Dsize) i = Dsize - 1; i > 0; i--) {
526  tmp = Din[i];
527 
528  for (decltype(i) j = 1; j < i; j++)
529  tmp *= BASE;
530 
531  den += tmp;
532  }
533  } else {
534  den = 1L;
535  }
536 
537  int64_t Nsign = ((Nin[0] < 0) ? -1L : 1L);
538  int64_t Dsign = ((Din[0] < 0) ? -1L : 1L);
539 
540  if ((Nsign * Dsign) == -1L) num = -num;
541 
542  Num.push_back(num);
543  Den.push_back(den);
544  }
545 
546  /*
547  void pmp (char name[], lrs_mp a) {
548  int64_t i;
549  fprintf (lrs_ofp, "%s", name);
550  if (sign (a) == NEG)
551  fprintf (lrs_ofp, "-");
552  else
553  fprintf (lrs_ofp, " ");
554  fprintf (lrs_ofp, "%lu", a[length (a) - 1]);
555  for (i = length (a) - 2; i >= 1; i--)
556  fprintf (lrs_ofp, FORMAT, a[i]);
557  fprintf (lrs_ofp, " ");
558  }*/
559 
560  template < typename GUM_SCALAR >
562  int64_t cols = int64_t(__input[0].size());
563 
564  int64_t* num = new int64_t[cols]; // ISO C++ forbids variable length array,
565  // we need to do this instead
566  int64_t* den = new int64_t[cols];
567 
568  int64_t rows = int64_t(__input.size());
569 
570  int64_t numerator, denominator;
571 
572  for (int64_t row = 0; row < rows; row++) {
573  for (int64_t col = 0; col < cols; col++) {
575  numerator, denominator, __input[row][col]);
576 
577  num[col] = numerator;
578  den[col] = denominator;
579  }
580 
581  /* GE is inequality, EQ is equation */
582  /* 1L, 0L respectively */
583  lrs_set_row(__dic,
584  __dat,
585  row + 1,
586  num,
587  den,
588  1L); // do NOT forget this + 1 on row
589  }
590 
591  delete[] num;
592  delete[] den;
593  }
594 
595  template < typename GUM_SCALAR >
597  if (__state != __states::H2Vready && __state != __states::V2Hready)
599  "LRSWrapper< GUM_SCALAR >::__initLrs : not ready, current state "
600  "is still : "
601  << __setUpStateNames[static_cast< int >(__state)]);
602 
603  //__coutOff();
604 
605  std::string name = "\n*LrsWrapper:";
606  std::vector< char > chars(name.c_str(), name.c_str() + name.size() + 1u);
607  // use &chars[0] as a char*
608 
609  if (!lrs_init(&chars[0])) {
610  // __coutOn();
612  "LRSWrapper< GUM_SCALAR >::__initLrs : failed lrs_init");
613  }
614 
615  name = "LRSWrapper globals";
616  chars = std::vector< char >(name.c_str(), name.c_str() + name.size() + 1u);
617 
618  __dat = lrs_alloc_dat(&chars[0]);
619 
620  if (__dat == nullptr) {
621  // __coutOn();
623  "LRSWrapper< GUM_SCALAR >::__initLrs : failed lrs_alloc_dat");
624  }
625 
626  __dat->n = Size(__input[0].size());
627  __dat->m = Size(__input.size());
628 
629  __dat->getvolume = (__getVolume) ? 1L : 0L;
630  __dat->hull = (__hull) ? 1L : 0L;
631  __dat->polytope = (__polytope) ? 1L : 0L;
632 
633  __lrsOutput = lrs_alloc_mp_vector(__dat->n);
634 
635  __dic = lrs_alloc_dic(__dat);
636 
637  if (__dic == nullptr) {
638  // __coutOn();
640  "LRSWrapper< GUM_SCALAR >::__initLrs : failed lrs_alloc_dic");
641  }
642 
643  __fill();
644 
645  /* Pivot to a starting dictionary */
646  if (!lrs_getfirstbasis(&__dic, __dat, &__Lin, 0L)) {
647  // __coutOn();
648  GUM_ERROR(
649  FatalError,
650  "LRSWrapper< GUM_SCALAR >::__initLrs : failed lrs_getfirstbasis");
651  }
652 
653  /* There may have been column redundancy */
654  /* If so the linearity space is obtained and redundant */
655  /* columns are removed. User can access linearity space */
656  /* from lrs_mp_matrix Lin dimensions nredundcol x d+1 */
657 
658  decltype(__dat->nredundcol) startcol = 0;
659 
660  if (__dat->homogeneous && __dat->hull) {
661  startcol++; /* col zero not treated as redundant */
662 
663  if (!__dat->restart) {
664  // __coutOn();
665 
666  for (decltype(__dat->nredundcol) col = startcol; col < __dat->nredundcol;
667  col++)
668  lrs_printoutput(__dat, __Lin[col]);
669 
671  "LRSWrapper< GUM_SCALAR >::__initLrs : redundant columns !");
672  }
673  }
674  /*
675  if ( __dat->nredundcol > 0 ) {
676  __coutOn();
677 
678  for ( decltype( __dat->nredundcol ) col = 0, end =
679  __dat->nredundcol;
680  col < end;
681  col++ )
682  lrs_printoutput( __dat, __Lin[col] );
683 
684  GUM_ERROR(
685  FatalError,
686  "LRSWrapper< GUM_SCALAR >::__initLrs : redundant columns !" );
687  }
688  */
689  }
690 
691  template < typename GUM_SCALAR >
693  /* free space : do not change order of next lines! */
694 
695  lrs_clear_mp_vector(__lrsOutput, __dat->n);
696 
697  if (__dat->nredundcol > 0)
698  lrs_clear_mp_matrix(__Lin, __dat->nredundcol, __dat->n);
699 
700  if (__dat->runs > 0) {
701  free(__dat->isave);
702  free(__dat->jsave);
703  }
704 
705  auto savem = __dic->m; /* need this to clear __dat*/
706 
707  lrs_free_dic(__dic, __dat); /* deallocate lrs_dic */
708 
709  __dat->m = savem;
710  lrs_free_dat(__dat);
711 
712  std::string name = "LrsWrapper:";
713  std::vector< char > chars(name.c_str(), name.c_str() + name.size() + 1u);
714 
715  lrs_close(&chars[0]);
716 
717  // __coutOn();
718  }
719 
720  template < typename GUM_SCALAR >
722  fflush(stdout);
723 #ifdef _MSC_VER
724  freopen("NUL", "w", stdout);
725 #else // _MSC_VER
726  __oldCout = dup(1);
727 
728  int new_cout = open("/dev/null", O_WRONLY);
729  dup2(new_cout, 1);
730  close(new_cout);
731 #endif // _MSC_VER
732  }
733 
734  template < typename GUM_SCALAR >
736  fflush(stdout);
737 #ifdef _MSC_VER
738  freopen("CON", "w", stdout);
739 #else // _MSC_VER
740  dup2(__oldCout, 1);
741  close(__oldCout);
742 #endif // _MSC_VER
743  }
744 
745  } // namespace credal
746 } // namespace gum
const GUM_SCALAR & getVolume() const
Get the volume of the polytope that has been computed.
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
void setUpH(const unsigned int &card)
Sets up an H-representation.
~LRSWrapper()
Default Destructor.
void setUpV(const unsigned int &card, const unsigned int &vertices)
Sets up a V-representation.
void V2H()
V-representation to H-representation.
void fillMatrix(const std::vector< std::vector< GUM_SCALAR > > &matrix)
Fill the H-representation from the matrix given in argument.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
#define BASE
Definition: LrsWrapper.h:71
void __initLrs()
Initialize lrs structs and first basis according to flags.
typename std::vector< std::vector< GUM_SCALAR > > matrix
Shortcut for dynamic matrix using vectors.
Definition: LrsWrapper.h:107
const matrix & getOutput() const
Get the output matrix solution of the problem.
void __freeLrs()
Free lrs space.
void fillV(const std::vector< GUM_SCALAR > &vertex)
Creates the V-representation of a polytope by adding a vertex to the problem input __input...
Class template acting as a wrapper for Lexicographic Reverse Search by David Avis.
Definition: LrsWrapper.h:104
Lrs wrapper.
void nextHInput()
Reset the wrapper for next computation for a H-representation with the same variable cardinality and ...
const unsigned int & getVerticesNumber() const
Get the number of vertices of this polytope.
void tearDown()
Reset the wrapper as if it was built.
static void continuedFracFirst(int64_t &numerator, int64_t &denominator, const GUM_SCALAR &number, const double &zero=1e-6)
Find the first best rational approximation.
Definition: rational_tpl.h:93
const matrix & getInput() const
Get the intput matrix of the problem.
void __coutOn() const
The function that restores standard cout.
void __fill() const
Fill lrs_dictionnary and datas from __input using integer rationals.
void H2V()
H-representation to V-representation.
void __coutOff() const
The function that redirects standard cout to /dev/null.
void fillH(const GUM_SCALAR &min, const GUM_SCALAR &max, const unsigned int &modal)
Creates the H-representation of min <= p(X=modal | .) <= max and add it to the problem input __input...
void elimRedundVrep()
V-Redundancy elimination.
LRSWrapper()
Default Constructor.
void computeVolume()
Computes a polytope ( pseudo ) volume from it&#39;s V-representation.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
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.