PIPS
sc_enumerate.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include "linear.h"
#include "polylib/polylib.h"
+ Include dependency graph for sc_enumerate.c:

Go to the source code of this file.

Macros

#define MAX_NB_RAYS   (20000)
 IRISA/POLYLIB data structures. More...
 
#define VALUE_TO_IRINT(val)   (val)
 Irisa is based on int. More...
 
#define IRINT_TO_VALUE(i)   (i)
 

Functions

static void my_Matrix_Free (Matrix *volatile *m)
 
static void my_Polyhedron_Free (Polyhedron *volatile *p)
 
static void contrainte_to_matrix_ligne (Pcontrainte pc, Matrix *mat, int i, Pbase base)
 Fonctions de conversion traduisant une Pcontrainte en une ligne de la structure matrix de l'IRISA. More...
 
static void sc_to_matrix (Psysteme sc, Matrix *mat)
 Passage du systeme lineaire sc a une matrice matrix (structure Irisa) Cette fonction de conversion est utilisee par la fonction sc_to_sg_chernikova. More...
 
static Variable base_nth (Pbase b, size_t i)
 
static Ppolynome evalue_to_polynome (evalue *, Pbase)
 
static Ppolynome enode_to_polynome (enode *e, Pbase ordered_base)
 
Ppolynome sc_enumerate (Psysteme ordered_sc, Pbase ordered_base, const char *variable_names[])
 enumerate the systeme sc using base pb pb contains the unknow variables and sc all the constraints ordered_sc must be order as follows: elements from ordered_base appear last variable_names can be provided for debugging purpose (name of bases) or set to NULL More...
 

Macro Definition Documentation

◆ IRINT_TO_VALUE

#define IRINT_TO_VALUE (   i)    (i)

Definition at line 60 of file sc_enumerate.c.

◆ MAX_NB_RAYS

#define MAX_NB_RAYS   (20000)

IRISA/POLYLIB data structures.

maximum number of rays allowed in chernikova... (was 20000) it does not look a good idea to move the limit up, as it makes both time and memory consumption to grow a lot.

Definition at line 47 of file sc_enumerate.c.

◆ VALUE_TO_IRINT

#define VALUE_TO_IRINT (   val)    (val)

Irisa is based on int.

We would like to change this to some other type, say "long long" if desired, as VALUE may also be changed. It is currently an int. Let us assume that the future type will be be called "IRINT" (Irisa Int)

Definition at line 59 of file sc_enumerate.c.

Function Documentation

◆ base_nth()

static Variable base_nth ( Pbase  b,
size_t  i 
)
static

Definition at line 254 of file sc_enumerate.c.

255 {
256  while(i--) {
257  b=vecteur_succ(b);
258  }
259  return vecteur_var(b);
260 }
#define vecteur_var(v)
#define vecteur_succ(v)

References vecteur_succ, and vecteur_var.

Referenced by enode_to_polynome().

+ Here is the caller graph for this function:

◆ contrainte_to_matrix_ligne()

static void contrainte_to_matrix_ligne ( Pcontrainte  pc,
Matrix *  mat,
int  i,
Pbase  base 
)
static

Fonctions de conversion traduisant une Pcontrainte en une ligne de la structure matrix de l'IRISA.

Definition at line 91 of file sc_enumerate.c.

96 {
97  Pvecteur pv;
98  int j;
99  Value v;
100 
101  for (pv=base,j=1; !VECTEUR_NUL_P(pv); pv=pv->succ,j++)
102  {
104  mat->p[i][j] = VALUE_TO_IRINT(v);
105  }
106 
108  mat->p[i][j]= VALUE_TO_IRINT(v);
109 }
#define value_uminus(val)
unary operators on values
int Value
bdt base
Current expression.
Definition: bdt_read_paf.c:100
#define VALUE_TO_IRINT(val)
Irisa is based on int.
Definition: sc_enumerate.c:59
Pvecteur vecteur
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
struct Svecteur * succ
Definition: vecteur-local.h:92
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define VECTEUR_NUL_P(v)
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228

References base, Svecteur::succ, TCST, VALUE_TO_IRINT, value_uminus, vect_coeff(), Scontrainte::vecteur, VECTEUR_NUL_P, and vecteur_var.

Referenced by sc_to_matrix().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ enode_to_polynome()

static Ppolynome enode_to_polynome ( enode *  e,
Pbase  ordered_base 
)
static

Definition at line 264 of file sc_enumerate.c.

265 {
266  int i;
267  if (!e)
268  return POLYNOME_UNDEFINED;
270  switch(e->type) {
271  case evector:
272  for (i=0; i<e->size; i++) {
273  Ppolynome pp = evalue_to_polynome(&e->arr[i],ordered_base);
274  polynome_add(&p,pp);
275  }
276  return p;
277  case polynomial:
278  for (i=e->size-1; i>=0; i--) {
279  Ppolynome pp = evalue_to_polynome(&e->arr[i],ordered_base);
280  pp=polynome_mult(pp,make_polynome(1,base_nth(ordered_base,e->pos-1),i));
281  polynome_add(&p,pp);
282  }
283  return p;
284  default:
285  fprintf(stderr,"cannot represent periodic polynomials in linear\n");
286  return POLYNOME_UNDEFINED;
287  }
288 }
Ppolynome make_polynome(float coeff, Variable var, Value expo)
Ppolynome make_polynome(float coeff, Variable var, Value expo) PRIVATE allocates space for,...
Definition: pnome-alloc.c:100
Ppolynome polynome_mult(Ppolynome pp1, Ppolynome pp2)
Ppolynome polynome_mult(Ppolynome pp1, Ppolynome pp2) returns pp1 * pp2.
Definition: pnome-bin.c:287
void polynome_add(Ppolynome *ppp, Ppolynome pp2)
void polynome_add(Ppolynome* ppp, Ppolynome pp2) (*ppp) = (*ppp) + pp2.
Definition: pnome-bin.c:171
#define POLYNOME_NUL
#define POLYNOME_UNDEFINED
static Variable base_nth(Pbase b, size_t i)
Definition: sc_enumerate.c:254
static Ppolynome evalue_to_polynome(evalue *, Pbase)
Definition: sc_enumerate.c:290
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References base_nth(), evalue_to_polynome(), fprintf(), make_polynome(), polynome_add(), polynome_mult(), POLYNOME_NUL, and POLYNOME_UNDEFINED.

Referenced by evalue_to_polynome().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ evalue_to_polynome()

static Ppolynome evalue_to_polynome ( evalue *  e,
Pbase  ordered_base 
)
static

Definition at line 290 of file sc_enumerate.c.

291 {
292  Ppolynome p = NULL;
293  if(value_notzero_p(e->d))
294  p=make_polynome((float)e->x.n/(float)e->d,TCST,0);
295  else
296  p = enode_to_polynome(e->x.p,ordered_base);
297  return p;
298 }
#define value_notzero_p(val)
static Ppolynome enode_to_polynome(enode *e, Pbase ordered_base)
Definition: sc_enumerate.c:264

References enode_to_polynome(), make_polynome(), TCST, and value_notzero_p.

Referenced by enode_to_polynome(), and sc_enumerate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ my_Matrix_Free()

static void my_Matrix_Free ( Matrix *volatile *  m)
static

Definition at line 63 of file sc_enumerate.c.

64 {
65  ifscdebug(9)
66  fprintf(stderr, "[my_Matrix_Free] in %p\n", *m);
67 
68  Matrix_Free(*m);
69  *m = NULL;
70 
71  ifscdebug(9)
72  fprintf(stderr, "[my_Matrix_Free] out %p\n", *m);
73 }
static FILE * out
Definition: alias_check.c:128
static void my_Matrix_Free(Matrix *volatile *m)
Definition: sc_enumerate.c:63

References fprintf().

Referenced by sc_enumerate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ my_Polyhedron_Free()

static void my_Polyhedron_Free ( Polyhedron *volatile *  p)
static

Definition at line 75 of file sc_enumerate.c.

76 {
77  ifscdebug(9)
78  fprintf(stderr, "[my_Polyhedron_Free] in %p\n", *p);
79 
80  Polyhedron_Free(*p);
81  *p = NULL;
82 
83  ifscdebug(9)
84  fprintf(stderr, "[my_Polyhedron_Free] out %p\n", *p);
85 }
static void my_Polyhedron_Free(Polyhedron *volatile *p)
Definition: sc_enumerate.c:75

References fprintf().

Referenced by sc_enumerate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_enumerate()

Ppolynome sc_enumerate ( Psysteme  ordered_sc,
Pbase  ordered_base,
const char *  variable_names[] 
)

enumerate the systeme sc using base pb pb contains the unknow variables and sc all the constraints ordered_sc must be order as follows: elements from ordered_base appear last variable_names can be provided for debugging purpose (name of bases) or set to NULL

sc_enumerate.c

Parameters
ordered_scrdered_sc
ordered_baserdered_base
variable_namesariable_names

Definition at line 307 of file sc_enumerate.c.

310 {
311  // Automatic variables read in a CATCH block need to be declared volatile as
312  // specified by the documentation
313  Polyhedron * volatile A = NULL;
314  Matrix * volatile a = NULL;
315  Polyhedron * volatile C = NULL;
316  Enumeration * volatile ehrhart = NULL;
317 
318  int nbrows = 0;
319  int nbcolumns = 0;
320  if( sc_dimension(ordered_sc) == 0 )
321  return make_polynome(1,TCST,1);
322  else
323  {
325  {
326  if (A) my_Polyhedron_Free(&A);
327  if (a) my_Matrix_Free(&a);
328  if (C) my_Polyhedron_Free(&C);
329  RETHROW();
330  }
331  TRY
332  {
333  assert(!SC_UNDEFINED_P(ordered_sc) && (sc_dimension(ordered_sc) != 0));
334  nbrows = ordered_sc->nb_eq + ordered_sc->nb_ineq+1;
335  nbcolumns = ordered_sc->dimension +2;
336  a = Matrix_Alloc(nbrows, nbcolumns);
337  sc_to_matrix(ordered_sc,a);
338 
339  A = Constraints2Polyhedron(a, MAX_NB_RAYS);
340  my_Matrix_Free(&a);
341 
342  C = Universe_Polyhedron(base_dimension(ordered_base));
343 
344  ehrhart = Polyhedron_Enumerate(A, C, MAX_NB_RAYS, variable_names);
345  // Value vals[2]= {0,0};
346  // Value *val = compute_poly(ehrhart,&vals[0]);
347  // printf("%lld\n",*val);
349  my_Polyhedron_Free(&C);
350  } // end TRY
351 
353  return evalue_to_polynome(&ehrhart->EP,ordered_base);
354  }
355 }
#define CATCH(what)
@ any_exception_error
catch all
#define UNCATCH(what)
#define RETHROW()
#define TRY
#define assert(ex)
Definition: newgen_assert.h:41
static void sc_to_matrix(Psysteme sc, Matrix *mat)
Passage du systeme lineaire sc a une matrice matrix (structure Irisa) Cette fonction de conversion es...
Definition: sc_enumerate.c:115
#define MAX_NB_RAYS
IRISA/POLYLIB data structures.
Definition: sc_enumerate.c:47
Definition: pip__tab.h:25
int dimension
Definition: sc-local.h:74
int nb_ineq
Definition: sc-local.h:73
int nb_eq
Definition: sc-local.h:72
#define base_dimension(b)

References any_exception_error, assert, base_dimension, CATCH, Ssysteme::dimension, evalue_to_polynome(), make_polynome(), MAX_NB_RAYS, my_Matrix_Free(), my_Polyhedron_Free(), Ssysteme::nb_eq, Ssysteme::nb_ineq, RETHROW, sc_to_matrix(), TCST, TRY, and UNCATCH.

+ Here is the call graph for this function:

◆ sc_to_matrix()

static void sc_to_matrix ( Psysteme  sc,
Matrix *  mat 
)
static

Passage du systeme lineaire sc a une matrice matrix (structure Irisa) Cette fonction de conversion est utilisee par la fonction sc_to_sg_chernikova.

Definition at line 115 of file sc_enumerate.c.

116 {
117  int nbrows, i, j;
118  Pcontrainte peq;
119  Pvecteur pv;
120 
121  nbrows = mat->NbRows;
122 
123  // Differentiation equations and inequations
124  for (i=0; i<=sc->nb_eq-1;i++)
125  mat->p[i][0] =0;
126  for (; i<=nbrows-1;i++)
127  mat->p[i][0] =1;
128 
129  // Matrix initialisation
130  for (peq = sc->egalites,i=0;
132  peq=peq->succ, i++)
133  contrainte_to_matrix_ligne(peq,mat,i,sc->base);
134 
135  for (peq =sc->inegalites;
137  peq=peq->succ, i++)
138  contrainte_to_matrix_ligne(peq,mat,i,sc->base);
139 
140  for (pv=sc->base,j=1; !VECTEUR_NUL_P(pv); pv=pv->succ, j++)
141  mat->p[i][j] = 0;
142  mat->p[i][j]=1;
143 }
#define CONTRAINTE_UNDEFINED_P(c)
static void contrainte_to_matrix_ligne(Pcontrainte pc, Matrix *mat, int i, Pbase base)
Fonctions de conversion traduisant une Pcontrainte en une ligne de la structure matrix de l'IRISA.
Definition: sc_enumerate.c:91
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
Pcontrainte egalites
Definition: sc-local.h:70
Pbase base
Definition: sc-local.h:75

References Ssysteme::base, contrainte_to_matrix_ligne(), CONTRAINTE_UNDEFINED_P, Ssysteme::egalites, Ssysteme::inegalites, Ssysteme::nb_eq, Scontrainte::succ, Svecteur::succ, and VECTEUR_NUL_P.

Referenced by sc_enumerate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: