ehrhart.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <polylib/polylib.h>
#include <polylib/homogenization.h>

Go to the source code of this file.

Defines

#define EPRINT_ALL_VALIDITY_CONSTRAINTS
 define this to print all constraints on the validity domains if not defined, only new constraints (not in validity domain given by the user) are printed
#define REDUCE_DEGREE
 Reduce the degree of resulting polynomials.
#define ALL_OVERFLOW_WARNINGS
 define this to print one warning message per domain overflow these overflows should no longer happen since version 4.20
#define MAXITER   100
 This procedure finds an integer point contained in polyhedron D / first checks for positive values, then for negative values returns TRUE on success.

Functions

enodenew_enode (enode_type type, int size, int pos)
 EHRHART POLYNOMIAL SYMBOLIC ALGEBRA SYSTEM.
void free_evalue_refs (evalue *e)
 releases all memory referenced by e.
enodeecopy (enode *e)
void print_evalue (FILE *DST, evalue *e, const char **pname)
void print_enode (FILE *DST, enode *p, const char **pname)
 prints the enode to DST
static int eequal (evalue *e1, evalue *e2)
void reduce_evalue (evalue *e)
static void emul (evalue *e1, evalue *e2, evalue *res)
 multiplies two evalues and puts the result in res
void eadd (evalue *e1, evalue *res)
 adds one evalue to evalue 'res.
void edot (enode *v1, enode *v2, evalue *res)
 computes the inner product of two vectors.
static void aep_evalue (evalue *e, int *ref)
 local recursive function used in the following ref contains the new position for each old index position
static void addeliminatedparams_evalue (evalue *e, Matrix *CT)
 Comments.
int cherche_min (Value *min, Polyhedron *D, int pos)
PolyhedronPolyhedron_Preprocess (Polyhedron *D, Value *size, unsigned MAXRAYS)
 This procedure finds the smallest parallelepiped of size 'size[i]' for every dimension i, contained in polyhedron D.
PolyhedronPolyhedron_Preprocess2 (Polyhedron *D, Value *size, Value *lcm, unsigned MAXRAYS)
 This procedure finds an hypercube of size 'size', containing polyhedron D increases size and lcm if necessary (and not "too big") If this is not possible, an empty polyhedron is returned.
Polyhedronold_Polyhedron_Preprocess (Polyhedron *D, Value size, unsigned MAXRAYS)
 This procedure adds additional constraints to D so that as each parameter is scanned, it will have a minimum of 'size' points If this is not possible, an empty polyhedron is returned.
void count_points (int pos, Polyhedron *P, Value *context, Value *res)
 PROCEDURES TO COMPUTE ENUMERATION.
static enodeP_Enum (Polyhedron *L, Polyhedron *LQ, Value *context, int pos, int nb_param, int dim, Value *lcm, const char **param_name)
static void Scan_Vertices (Param_Polyhedron *PP, Param_Domain *Q, Matrix *CT, Value *lcm, int nbp, const char **param_name)
EnumerationEnumerate_NoParameters (Polyhedron *P, Polyhedron *C, Matrix *CT, Polyhedron *CEq, unsigned MAXRAYS, const char **param_name)
 Procedure to count points in a non-parameterized polytope.
EnumerationPolyhedron_Enumerate (Polyhedron *Pi, Polyhedron *C, unsigned MAXRAYS, const char **param_name)
 Procedure to count points in a parameterized polytope.
void Enumeration_Free (Enumeration *en)
void evalue_div (evalue *e, Value n)
 Divides the evalue e by the integer n
recursive function
Warning : modifies e.
EnumerationEhrhart_Quick_Apx_Full_Dim (Polyhedron *Pi, Polyhedron *C, unsigned MAXRAYS, const char **param_name)
 Ehrhart_Quick_Apx_Full_Dim(P, C, MAXRAYS, param_names).
EnumerationEhrhart_Quick_Apx (Matrix *M, Matrix *C, Matrix **Validity_Lattice, unsigned maxRays)
 Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix), treating the non-full-dimensional case.
EnumerationConstraints_EhrhartQuickApx (Matrix const *M, Matrix const *C, Matrix **validityLattice, Matrix **parmEqualities, unsigned int **elimParms, unsigned maxRays)
 Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix), treating the non-full-dimensional case.
const char ** parmsWithoutElim (char const **parmNames, unsigned int const *elimParms, unsigned int nbParms)
 Returns the array of parameter names after some of them have been eliminated.
EnumerationEnumeration_zero (unsigned int nbParms, unsigned int maxRays)
 returns a constant Ehrhart polynomial whose value is zero for any value of the parameters.

Variables

int overflow_warning_flag = 1

Define Documentation

#define ALL_OVERFLOW_WARNINGS

define this to print one warning message per domain overflow these overflows should no longer happen since version 4.20

Definition at line 94 of file ehrhart.c.

#define EPRINT_ALL_VALIDITY_CONSTRAINTS

define this to print all constraints on the validity domains if not defined, only new constraints (not in validity domain given by the user) are printed

Definition at line 70 of file ehrhart.c.

#define MAXITER   100

This procedure finds an integer point contained in polyhedron D / first checks for positive values, then for negative values returns TRUE on success.

Result is in min. returns FALSE if no integer point is found

This is the maximum number of iterations for a given parameter to find a integer point inside the context. Kind of weird. cherche_min should

Parameters:
min 
D 
pos 

Definition at line 635 of file ehrhart.c.

Referenced by cherche_min().

#define REDUCE_DEGREE

Reduce the degree of resulting polynomials.

Definition at line 88 of file ehrhart.c.


Function Documentation

static void addeliminatedparams_evalue ( evalue e,
Matrix CT 
) [static]
static void aep_evalue ( evalue e,
int *  ref 
) [static]

local recursive function used in the following ref contains the new position for each old index position

Parameters:
e pointer to an evalue
ref transformation Matrix

Definition at line 569 of file ehrhart.c.

References _enode::arr, _evalue::d, p, _enode::pos, _enode::size, and value_notzero_p.

Referenced by addeliminatedparams_evalue().

int cherche_min ( Value *  min,
Polyhedron D,
int  pos 
)
Enumeration* Constraints_EhrhartQuickApx ( Matrix const *  M,
Matrix const *  C,
Matrix **  validityLattice,
Matrix **  parmEqualities,
unsigned int **  elimParms,
unsigned  maxRays 
)

Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix), treating the non-full-dimensional case.

If there are some equalities involving only parameters, these are used to eliminate useless parameters.

Parameters:
M a polyhedron under implicit form
C M's context under implicit form
validityLattice a pointer to the parameter's validity lattice (returned)
parmsEqualities Equalities involving only the parameters
maxRays the needed "working space" for other polylib functions used here
elimParams array of the indices of the eliminated parameters (returned)

Definition at line 2677 of file ehrhart.c.

References Constraints_Remove_parm_eqs(), Ehrhart_Quick_Apx(), Matrix_Copy(), and matrix::NbRows.

void count_points ( int  pos,
Polyhedron P,
Value *  context,
Value *  res 
)

PROCEDURES TO COMPUTE ENUMERATION.

recursive procedure, recurse for each imbriquation

Parameters:
pos index position of current loop index (1..hdim-1)
P loop domain
context context values for fixed indices
res the number of integer points in this polyhedron

Definition at line 1145 of file ehrhart.c.

References count_points(), emptyQ, lower_upper_bounds(), polyhedron::next, P_VALUE_FMT, POL_ENSURE_FACETS, POL_ENSURE_VERTICES, value_add_int, value_addto, value_assign, value_clear, value_increment, value_init, value_le, value_lt, value_notmone_p, value_print, value_set_si, and value_subtract.

Referenced by check_poly(), count_points(), Enumerate_NoParameters(), and P_Enum().

void eadd ( evalue e1,
evalue res 
)

adds one evalue to evalue 'res.

result = res + e1

Parameters:
e1 an evalue
res 

Definition at line 410 of file ehrhart.c.

References _enode::arr, _evalue::d, eadd(), ecopy(), free_evalue_refs(), periodic, polynomial, value_addto, value_clear, value_divexact, value_gcd, value_init, value_multiply, value_notone_p, value_notzero_p, and value_zero_p.

Referenced by eadd(), and edot().

enode* ecopy ( enode e  ) 
Parameters:
e pointer to an evalue
Returns:
description

Definition at line 167 of file ehrhart.c.

References _enode::arr, _evalue::d, ecopy(), new_enode(), _enode::pos, _enode::size, _enode::type, value_assign, value_init, and value_zero_p.

Referenced by Domain_Enumerate(), eadd(), ecopy(), and new_eadd().

void edot ( enode v1,
enode v2,
evalue res 
)

computes the inner product of two vectors.

Result = result (evalue) = v1.v2 (dot product)

Parameters:
v1 an enode (vector)
v2 an enode (vector of constants)
res result (evalue)

Definition at line 526 of file ehrhart.c.

References _enode::arr, _evalue::d, eadd(), emul(), evector, free_evalue_refs(), _enode::size, _enode::type, value_init, and value_set_si.

Referenced by P_Enum().

static int eequal ( evalue e1,
evalue e2 
) [static]
Parameters:
e1 pointers to evalues
e2 pointers to evalues
Returns:
1 (true) if they are equal, 0 (false) if not

Definition at line 261 of file ehrhart.c.

References _enode::arr, _evalue::d, _enode::pos, _enode::size, _enode::type, value_ne, and value_notzero_p.

Referenced by reduce_evalue().

Enumeration* Ehrhart_Quick_Apx ( Matrix M,
Matrix C,
Matrix **  Validity_Lattice,
unsigned  maxRays 
)

Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix), treating the non-full-dimensional case.

Parameters:
M a polyhedron under implicit form
C M's context under implicit form
Validity_Lattice a pointer to the parameter's validity lattice
MAXRAYS the needed "working space" for other polylib functions used here
param_name the names of the parameters,

Definition at line 2635 of file ehrhart.c.

References Constraints2Polyhedron(), Ehrhart_Quick_Apx_Full_Dim(), full_dimensionize(), Matrix_Free(), mpolyhedron_compress_last_vars(), matrix::NbColumns, Polyhedron_Free(), and show_matrix.

Referenced by Constraints_EhrhartQuickApx(), and main().

Enumeration* Ehrhart_Quick_Apx_Full_Dim ( Polyhedron Pi,
Polyhedron C,
unsigned  MAXRAYS,
const char **  param_name 
)

Ehrhart_Quick_Apx_Full_Dim(P, C, MAXRAYS, param_names).

Procedure to estimate the number of points in a parameterized polytope. Returns a list of validity domains + evalues EP B.M. The most rough and quick approximation by variables expansion Deals with the full-dimensional case.

Parameters:
Pi : Polyhedron to enumerate (approximatively)
C : Context Domain
MAXRAYS : size of workspace
param_name : names for the parameters (char strings)

Definition at line 2281 of file ehrhart.c.

References addeliminatedparams_evalue(), assert, CATCH, _evalue::d, _Param_Polyhedron::D, polyhedron::Dimension, _Param_Domain::Domain, Domain_Free(), DomainIntersection(), DomainSimplify(), emptyQ, Enumerate_NoParameters(), _enumeration::EP, evalue_div(), polyhedron::NbBid, matrix::NbColumns, polyhedron::NbEq, polyhedron::NbRays, matrix::NbRows, _Param_Polyhedron::nbV, _enumeration::next, _Param_Domain::next, overflow_error, overflow_warning_flag, P_Enum(), P_VALUE_FMT, Param_Polyhedron_Scale_Integer(), Polyhedron2Param_SimplifiedDomain(), Polyhedron_Free(), Polyhedron_Preimage(), Polyhedron_Preprocess(), Polyhedron_Preprocess2(), Polyhedron_Print(), Polyhedron_Scan(), PolyhedronIncludes(), Print_Domain(), print_evalue(), polyhedron::Ray, reduce_evalue(), TRY, UNCATCH, Universe_Polyhedron(), _enumeration::ValidityDomain, value_clear, value_init, value_multiply, value_notzero_p, value_print, value_set_si, value_zero_p, and Vector_Set().

Referenced by Ehrhart_Quick_Apx().

static void emul ( evalue e1,
evalue e2,
evalue res 
) [static]

multiplies two evalues and puts the result in res

Parameters:
e1 pointer to an evalue
e2 pointer to a constant evalue
res pointer to result evalue = e1 * e2

Definition at line 368 of file ehrhart.c.

References _enode::arr, _evalue::d, new_enode(), p, _enode::pos, _enode::size, _enode::type, value_clear, value_divexact, value_gcd, value_init, value_multiply, value_notone_p, value_notzero_p, value_set_si, and value_zero_p.

Referenced by edot().

Enumeration* Enumerate_NoParameters ( Polyhedron P,
Polyhedron C,
Matrix CT,
Polyhedron CEq,
unsigned  MAXRAYS,
const char **  param_name 
)

Procedure to count points in a non-parameterized polytope.

Parameters:
P Polyhedron to count
C Parameter Context domain
CT Matrix to transform context to original
CEq additionnal equalities in context
MAXRAYS workspace size
param_name parameter names

Definition at line 1738 of file ehrhart.c.

References assert, CATCH, count_points(), _evalue::d, polyhedron::Dimension, Domain_Free(), DomainIntersection(), emptyQ, _enumeration::EP, polyhedron::NbRays, new_enode(), _enumeration::next, overflow_error, overflow_warning_flag, P_VALUE_FMT, Polyhedron_Free(), Polyhedron_Preimage(), Polyhedron_Print(), Polyhedron_Scan(), polynomial, Print_Domain(), print_evalue(), polyhedron::Ray, TRY, UNCATCH, Universe_Polyhedron(), _enumeration::ValidityDomain, value_clear, value_init, value_notone_p, value_print, value_set_si, value_zero_p, and Vector_Set().

Referenced by Ehrhart_Quick_Apx_Full_Dim(), and Polyhedron_Enumerate().

void Enumeration_Free ( Enumeration en  ) 
Enumeration* Enumeration_zero ( unsigned int  nbParms,
unsigned int  maxRays 
)

returns a constant Ehrhart polynomial whose value is zero for any value of the parameters.

Parameters:
nbParms the number of parameters, i.e., the number of arguments to the Ehrhart polynomial

Definition at line 2732 of file ehrhart.c.

References Constraints2Polyhedron(), Matrix_Alloc(), Matrix_Free(), matrix::p, Polyhedron_Enumerate(), Polyhedron_Free(), Universe_Polyhedron(), and value_set_si.

Referenced by test_Constraints_fullDimensionize().

void evalue_div ( evalue e,
Value  n 
)

Divides the evalue e by the integer n
recursive function
Warning : modifies e.

Parameters:
e an evalue (to be divided by n)
n 

Definition at line 2244 of file ehrhart.c.

References _evalue::d, value_clear, value_divexact, value_gcd, value_init, value_multiply, value_notone_p, and value_zero_p.

Referenced by Ehrhart_Quick_Apx_Full_Dim().

void free_evalue_refs ( evalue e  ) 

releases all memory referenced by e.

(recursive)

Parameters:
e pointer to an evalue

Definition at line 139 of file ehrhart.c.

References _enode::arr, _evalue::d, free_evalue_refs(), p, _enode::size, value_clear, and value_notzero_p.

Referenced by dehomogenize_evalue(), Domain_Enumerate(), eadd(), edot(), Enumeration_Free(), free_evalue_refs(), main(), P_Enum(), and reduce_evalue().

enode* new_enode ( enode_type  type,
int  size,
int  pos 
)

EHRHART POLYNOMIAL SYMBOLIC ALGEBRA SYSTEM.

The newly allocated enode can be freed with a simple free(x)

Parameters:
type : enode type
size : degree+1 for polynomial, period for periodic
pos : 1..nb_param, position of parameter
Returns:
a newly allocated enode

Definition at line 114 of file ehrhart.c.

References _enode::arr, _evalue::d, _enode::pos, _enode::size, _enode::type, value_init, and value_set_si.

Referenced by ecopy(), emul(), Enumerate_NoParameters(), new_eadd(), and P_Enum().

Polyhedron* old_Polyhedron_Preprocess ( Polyhedron D,
Value  size,
unsigned  MAXRAYS 
)

This procedure adds additional constraints to D so that as each parameter is scanned, it will have a minimum of 'size' points If this is not possible, an empty polyhedron is returned.

Parameters:
D 
size 
MAXRAYS 

Definition at line 1063 of file ehrhart.c.

References AddConstraints(), polyhedron::Constraint, polyhedron::Dimension, Matrix_Alloc(), Matrix_Free(), polyhedron::NbConstraints, matrix::p, p, matrix::p_Init, value_absolute, value_addmul, value_assign, value_clear, value_divexact, value_gcd, value_init, value_multiply, value_negz_p, value_notzero_p, value_oppose, value_posz_p, value_set_si, Vector_Combine(), and Vector_Normalize().

static enode* P_Enum ( Polyhedron L,
Polyhedron LQ,
Value *  context,
int  pos,
int  nb_param,
int  dim,
Value *  lcm,
const char **  param_name 
) [static]
const char** parmsWithoutElim ( char const **  parmNames,
unsigned int const *  elimParms,
unsigned int  nbParms 
)

Returns the array of parameter names after some of them have been eliminated.

Parameters:
parmNames the initial names of the parameters
elimParms a list of parameters that have been eliminated from the original parameters. The first element of this array is the number of elements.

Note: does not copy the parameters names themselves.

Parameters:
nbParms the initial number of parameters

Definition at line 2709 of file ehrhart.c.

Enumeration* Polyhedron_Enumerate ( Polyhedron Pi,
Polyhedron C,
unsigned  MAXRAYS,
const char **  param_name 
)

Procedure to count points in a parameterized polytope.

Parameters:
Pi Polyhedron to enumerate
C Context Domain
MAXRAYS size of workspace
param_name parameter names (array of strings), may be NULL
Returns:
a list of validity domains + evalues EP

Definition at line 1860 of file ehrhart.c.

References addeliminatedparams_evalue(), assert, CATCH, _Param_Polyhedron::D, _evalue::d, dehomogenize_evalue(), polyhedron::Dimension, _Param_Domain::Domain, Domain_Free(), DomainIntersection(), DomainSimplify(), emptyQ, Enumerate_NoParameters(), _enumeration::EP, _Param_Domain::F, homogenize(), Matrix_Free(), polyhedron::NbBid, matrix::NbColumns, polyhedron::NbEq, polyhedron::NbRays, matrix::NbRows, _Param_Domain::next, _enumeration::next, overflow_error, overflow_warning_flag, P_Enum(), P_VALUE_FMT, Param_Polyhedron_Free(), Param_Vertices_Free(), POL_ENSURE_FACETS, POL_ENSURE_VERTICES, POL_ISSET, POL_NO_DUAL, Polyhedron2Param_SimplifiedDomain(), Polyhedron_Free(), Polyhedron_Preimage(), Polyhedron_Preprocess(), Polyhedron_Preprocess2(), Polyhedron_Print(), Polyhedron_Scan(), PolyhedronIncludes(), Print_Domain(), print_evalue(), polyhedron::Ray, reduce_evalue(), Scan_Vertices(), TRY, UNCATCH, Universe_Polyhedron(), _Param_Polyhedron::V, _enumeration::ValidityDomain, value_addto, value_clear, value_init, value_multiply, value_notzero_p, value_print, value_set_si, value_zero_p, and Vector_Set().

Referenced by Domain_Enumerate(), Enumeration_zero(), main(), and test_Constraints_fullDimensionize().

Polyhedron* Polyhedron_Preprocess ( Polyhedron D,
Value *  size,
unsigned  MAXRAYS 
)

This procedure finds the smallest parallelepiped of size 'size[i]' for every dimension i, contained in polyhedron D.

If this is not possible, NULL is returned

written by vin100, 2000, for version 4.19
modified 2002, version 5.10

It first finds the coordinates of the lexicographically smallest edge of the hypercube, obtained by transforming the constraints of D (by adding 'size' as many times as there are negative coeficients in each constraint), and finding the lexicographical min of this polyhedron. Then it builds the hypercube and returns it.

Parameters:
D 
size 
MAXRAYS 

Definition at line 744 of file ehrhart.c.

References assert, cherche_min(), polyhedron::Constraint, Constraints2Polyhedron(), polyhedron::Dimension, Domain_Free(), emptyQ, Matrix_Alloc(), Matrix_Free(), Matrix_Print(), min, polyhedron::NbConstraints, matrix::NbRows, matrix::p, P_VALUE_FMT, Polyhedron_Free(), Polyhedron_Print(), Polyhedron_Scan(), Universe_Polyhedron(), value_addmul, value_addto, value_clear, value_init, value_ne, value_neg_p, value_oppose, value_print, value_set_si, value_sub_int, value_zero_p, and Vector_Copy().

Referenced by Ehrhart_Quick_Apx_Full_Dim(), and Polyhedron_Enumerate().

Polyhedron* Polyhedron_Preprocess2 ( Polyhedron D,
Value *  size,
Value *  lcm,
unsigned  MAXRAYS 
)

This procedure finds an hypercube of size 'size', containing polyhedron D increases size and lcm if necessary (and not "too big") If this is not possible, an empty polyhedron is returned.

 written by vin100, 2001, for version 4.19
Parameters:
D 
size 
lcm 
MAXRAYS 

Definition at line 899 of file ehrhart.c.

References Constraints2Polyhedron(), polyhedron::Dimension, Matrix_Alloc(), Matrix_Free(), Matrix_Print(), n, polyhedron::NbRays, matrix::p, P_VALUE_FMT, polyhedron::Ray, s, value_add_int, value_addto, value_assign, value_clear, value_division, value_gt, value_init, value_le, value_lt, value_multiply, value_oppose, value_print, value_set_si, value_sub_int, value_subtract, and value_zero_p.

Referenced by Ehrhart_Quick_Apx_Full_Dim(), and Polyhedron_Enumerate().

void print_enode ( FILE *  DST,
enode p,
const char **  pname 
)

prints the enode to DST

Parameters:
DST destination file
p pointer to enode to be printed
pname array of strings, name of the parameters

Definition at line 216 of file ehrhart.c.

References _enode::arr, evector, periodic, polynomial, _enode::pos, print_evalue(), _enode::size, and _enode::type.

Referenced by P_Enum(), and print_evalue().

void print_evalue ( FILE *  DST,
evalue e,
const char **  pname 
)
Parameters:
DST destination file
e pointer to evalue to be printed
pname array of strings, name of the parameters

Definition at line 192 of file ehrhart.c.

References _evalue::d, print_enode(), value_notone_p, value_notzero_p, and value_print.

Referenced by compute_poly(), Ehrhart_Quick_Apx_Full_Dim(), Enumerate_NoParameters(), main(), P_Enum(), Polyhedron_Enumerate(), print_enode(), and test_Constraints_fullDimensionize().

void reduce_evalue ( evalue e  ) 
static void Scan_Vertices ( Param_Polyhedron PP,
Param_Domain Q,
Matrix CT,
Value *  lcm,
int  nbp,
const char **  param_name 
) [static]

Variable Documentation


Generated on Wed Nov 25 17:45:26 2009 for polylib by  doxygen 1.6.1