polylib 5.22.8
polyhedron.c File Reference
#include <assert.h>
#include <polylib/polylib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  SatMatrix
 

Macros

#define WSIZE   (8 * sizeof(int))
 
#define bexchange(a, b, l)
 
#define exchange(a, b, t)
 
#define SMVector_Copy(p1, p2, length)    memcpy((char *)(p2), (char *)(p1), (int)((length) * sizeof(int)))
 
#define SMVector_Init(p1, length)    memset((char *)(p1), 0, (int)((length) * sizeof(int)))
 

Functions

void errormsg1 (const char *f, const char *msgname, const char *msg)
 
static SatMatrixSMAlloc (int rows, int cols)
 
static void SMFree (SatMatrix **matrix)
 
static void SMPrint (SatMatrix *matrix)
 
static void SatVector_OR (int *p1, int *p2, int *p3, unsigned length)
 
static void Combine (Value *p1, Value *p2, Value *p3, int pos, unsigned length)
 
static SatMatrixTransformSat (Matrix *Mat, Matrix *Ray, SatMatrix *Sat)
 
static void RaySort (Matrix *Ray, SatMatrix *Sat, int NbBid, int NbRay, int *equal_bound, int *sup_bound, unsigned RowSize1, unsigned RowSize2, unsigned bx, unsigned jx)
 
static void SatMatrix_Extend (SatMatrix *Sat, Matrix *Mat, unsigned rows)
 
static int Chernikova (Matrix *Mat, Matrix *Ray, SatMatrix *Sat, unsigned NbBid, unsigned NbMaxRays, unsigned FirstConstraint, unsigned dual)
 
static int Gauss4 (Value **p, int NbEq, int NbRows, int Dimension)
 
int Gauss (Matrix *Mat, int NbEq, int Dimension)
 
static PolyhedronRemove_Redundants (Matrix *Mat, Matrix *Ray, SatMatrix *Sat, unsigned *Filter)
 
PolyhedronPolyhedron_Alloc (unsigned Dimension, unsigned NbConstraints, unsigned NbRays)
 
void Polyhedron_Free (Polyhedron *Pol)
 
void Domain_Free (Polyhedron *Pol)
 
void Polyhedron_Print (FILE *Dst, const char *Format, const Polyhedron *Pol)
 
void PolyPrint (Polyhedron *Pol)
 
PolyhedronEmpty_Polyhedron (unsigned Dimension)
 
PolyhedronUniverse_Polyhedron (unsigned Dimension)
 
static void SortConstraints (Matrix *Constraints, unsigned NbEq)
 
static int ImplicitEqualities (Matrix *Constraints, unsigned NbEq)
 
PolyhedronConstraints2Polyhedron (Matrix *Constraints, unsigned NbMaxRays)
 Given a matrix of constraints ('Constraints'), construct and return a polyhedron. More...
 
MatrixPolyhedron2Constraints (Polyhedron *Pol)
 
PolyhedronRays2Polyhedron (Matrix *Ray, unsigned NbMaxConstrs)
 Given a matrix of rays 'Ray', create and return a polyhedron. More...
 
void Polyhedron_Compute_Dual (Polyhedron *P)
 
static SatMatrixBuildSat (Matrix *Mat, Matrix *Ray, unsigned NbConstraints, unsigned NbMaxRays)
 
PolyhedronAddConstraints (Value *Con, unsigned NbConstraints, Polyhedron *Pol, unsigned NbMaxRays)
 
int PolyhedronIncludes (Polyhedron *Pol1, Polyhedron *Pol2)
 
PolyhedronAddPolyToDomain (Polyhedron *Pol, Polyhedron *PolDomain)
 
PolyhedronSubConstraint (Value *Con, Polyhedron *Pol, unsigned NbMaxRays, int Pass)
 
PolyhedronDomainIntersection (Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
 Return the intersection of two polyhedral domains 'Pol1' and 'Pol2'. More...
 
MatrixPolyhedron2Rays (Polyhedron *Pol)
 Given a polyhedron 'Pol', return a matrix of rays. More...
 
PolyhedronAddRays (Value *AddedRays, unsigned NbAddedRays, Polyhedron *Pol, unsigned NbMaxConstrs)
 Add 'NbAddedRays' rays to polyhedron 'Pol'. More...
 
PolyhedronDomainAddRays (Polyhedron *Pol, Matrix *Ray, unsigned NbMaxConstrs)
 Add rays pointed by 'Ray' to each and every polyhedron in the polyhedral domain 'Pol'. More...
 
PolyhedronPolyhedron_Copy (Polyhedron *Pol)
 
PolyhedronDomain_Copy (Polyhedron *Pol)
 
static void addToFilter (int k, unsigned *Filter, SatMatrix *Sat, Value *tmpR, Value *tmpC, int NbRays, int NbConstraints)
 
static void FindSimple (Polyhedron *P1, Polyhedron *P2, unsigned *Filter, unsigned NbMaxRays)
 
static int SimplifyConstraints (Polyhedron *Pol1, Polyhedron *Pol2, unsigned *Filter, unsigned NbMaxRays)
 
static void SimplifyEqualities (Polyhedron *Pol1, Polyhedron *Pol2, unsigned *Filter)
 
PolyhedronDomainSimplify (Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
 
PolyhedronStras_DomainSimplify (Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
 
PolyhedronDomainUnion (Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
 
PolyhedronDomainConvex (Polyhedron *Pol, unsigned NbMaxConstrs)
 
PolyhedronDomainDifference (Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
 
Polyhedronalign_context (Polyhedron *Pol, int align_dimension, int NbMaxRays)
 
PolyhedronPolyhedron_Scan (Polyhedron *D, Polyhedron *C, unsigned NbMaxRays)
 
int lower_upper_bounds (int pos, Polyhedron *P, Value *context, Value *LBp, Value *UBp)
 
static void Rays_Mult (Value **A, Matrix *B, Value **C, unsigned NbRays)
 
static void Rays_Mult_Transpose (Value **A, Matrix *B, Value **C, unsigned NbRays)
 
PolyhedronPolyhedron_Preimage (Polyhedron *Pol, Matrix *Func, unsigned NbMaxRays)
 
PolyhedronDomainPreimage (Polyhedron *Pol, Matrix *Func, unsigned NbMaxRays)
 
PolyhedronPolyhedron_Image (Polyhedron *Pol, Matrix *Func, unsigned NbMaxConstrs)
 
PolyhedronDomainImage (Polyhedron *Pol, Matrix *Func, unsigned NbMaxConstrs)
 
IntervalDomainCost (Polyhedron *Pol, Value *Cost)
 
PolyhedronDomainAddConstraints (Polyhedron *Pol, Matrix *Mat, unsigned NbMaxRays)
 
PolyhedronDisjoint_Domain (Polyhedron *P, int flag, unsigned NbMaxRays)
 
void Polyhedron_PrintConstraints (FILE *Dst, const char *Format, Polyhedron *Pol)
 
void Domain_PrintConstraints (FILE *Dst, const char *Format, Polyhedron *Pol)
 
static Polyhedronp_simplify_constraints (Polyhedron *P, Vector *row, Value *g, unsigned MaxRays)
 
PolyhedronDomainConstraintSimplify (Polyhedron *P, unsigned MaxRays)
 
void polylib_close ()
 Free all cache allocated memory: call this function before exiting in a memory checker environment like valgrind. More...
 

Variables

int Pol_status
 

Macro Definition Documentation

◆ bexchange

#define bexchange (   a,
  b,
 
)
Value:
{ \
char *t = (char *)malloc(l * sizeof(char)); \
memcpy((t), (char *)(a), (int)(l)); \
memcpy((char *)(a), (char *)(b), (int)(l)); \
memcpy((char *)(b), (t), (int)(l)); \
free(t); \
}

Definition at line 50 of file polyhedron.c.

◆ exchange

#define exchange (   a,
  b,
 
)
Value:
{ \
(t) = (a); \
(a) = (b); \
(b) = (t); \
}

Definition at line 59 of file polyhedron.c.

◆ SMVector_Copy

#define SMVector_Copy (   p1,
  p2,
  length 
)     memcpy((char *)(p2), (char *)(p1), (int)((length) * sizeof(int)))

Definition at line 182 of file polyhedron.c.

◆ SMVector_Init

#define SMVector_Init (   p1,
  length 
)     memset((char *)(p1), 0, (int)((length) * sizeof(int)))

Definition at line 188 of file polyhedron.c.

◆ WSIZE

#define WSIZE   (8 * sizeof(int))

Definition at line 48 of file polyhedron.c.

Function Documentation

◆ AddConstraints()

◆ AddPolyToDomain()

◆ AddRays()

Polyhedron * AddRays ( Value *  AddedRays,
unsigned  NbAddedRays,
Polyhedron Pol,
unsigned  NbMaxConstrs 
)

◆ addToFilter()

static void addToFilter ( int  k,
unsigned *  Filter,
SatMatrix Sat,
Value *  tmpR,
Value *  tmpC,
int  NbRays,
int  NbConstraints 
)
static

Definition at line 2907 of file polyhedron.c.

References MSB, NEXT, SatMatrix::p, Sat, value_decrement, value_posz_p, value_set_si, and WSIZE.

Referenced by FindSimple().

◆ align_context()

◆ BuildSat()

static SatMatrix * BuildSat ( Matrix Mat,
Matrix Ray,
unsigned  NbConstraints,
unsigned  NbMaxRays 
)
static

◆ Chernikova()

◆ Combine()

static void Combine ( Value *  p1,
Value *  p2,
Value *  p3,
int  pos,
unsigned  length 
)
static

◆ Constraints2Polyhedron()

Polyhedron * Constraints2Polyhedron ( Matrix Constraints,
unsigned  NbMaxRays 
)

Given a matrix of constraints ('Constraints'), construct and return a polyhedron.

Parameters
ConstraintsConstraints (may be modified!)
NbMaxRaysEstimated number of rays in the ray matrix of the polyhedron.
Returns
newly allocated Polyhedron

Definition at line 1905 of file polyhedron.c.

References any_exception_error, CATCH, Chernikova(), polyhedron::Constraint, ConstraintSimplify(), Empty_Polyhedron(), errormsg1(), ExchangeRows(), F_SET, First_Non_Zero(), Gauss(), ImplicitEqualities(), Matrix_Alloc(), Matrix_Free(), Matrix_Print(), matrix::NbColumns, polyhedron::NbEq, matrix::NbRows, SatMatrix::NbRows, matrix::p, matrix::p_Init, SatMatrix::p_init, POL_INEQUALITIES, POL_INTEGER, POL_ISSET, POL_NO_DUAL, POL_VALID, Polyhedron_Alloc(), Polyhedron_Free(), Polyhedron_Print(), polyhedron::Ray, Remove_Redundants(), RETHROW, Sat, SMAlloc(), SMFree(), SMPrint(), SMVector_Init, SortConstraints(), TRY, UNCATCH, Universe_Polyhedron(), value_clear, value_init, value_notzero_p, value_set_si, value_zero_p, Vector_Copy(), and Vector_Set().

Referenced by AddConstraints(), dehomogenize_polyhedron(), DomainSimplify(), Ehrhart_Quick_Apx(), Elim_Columns(), eliminable_vars(), Enumeration_zero(), Find_m_faces(), homogenize(), LexSmaller(), main(), Param_Vertices_Print(), Polyhedron_Compute_Dual(), Polyhedron_Preimage(), Polyhedron_Preprocess(), Polyhedron_Preprocess2(), Polyhedron_Remove_parm_eqs(), Recession_Cone(), Stras_DomainSimplify(), test_Constraints_fullDimensionize(), test_Constraints_Remove_parm_eqs(), test_Polyhedron_Remove_parm_eqs(), and Union_Read().

◆ Disjoint_Domain()

◆ Domain_Copy()

◆ Domain_Free()

◆ Domain_PrintConstraints()

void Domain_PrintConstraints ( FILE *  Dst,
const char *  Format,
Polyhedron Pol 
)

Definition at line 4752 of file polyhedron.c.

References polyhedron::next, and Polyhedron_PrintConstraints().

◆ DomainAddConstraints()

Polyhedron * DomainAddConstraints ( Polyhedron Pol,
Matrix Mat,
unsigned  NbMaxRays 
)

◆ DomainAddRays()

Polyhedron * DomainAddRays ( Polyhedron Pol,
Matrix Ray,
unsigned  NbMaxConstrs 
)

Add rays pointed by 'Ray' to each and every polyhedron in the polyhedral domain 'Pol'.

'NbMaxConstrs' is maximum allowed constraints in the constraint set of a polyhedron.

Definition at line 2794 of file polyhedron.c.

References AddRays(), polyhedron::Dimension, Domain_Copy(), errormsg1(), matrix::NbColumns, matrix::NbRows, polyhedron::next, matrix::p, Polyhedron_Free(), and PolyhedronIncludes().

Referenced by Find_m_faces(), and Polyhedron_Scan().

◆ DomainConstraintSimplify()

Polyhedron * DomainConstraintSimplify ( Polyhedron P,
unsigned  MaxRays 
)

◆ DomainConvex()

Polyhedron * DomainConvex ( Polyhedron Pol,
unsigned  NbMaxConstrs 
)

◆ DomainCost()

◆ DomainDifference()

◆ DomainImage()

◆ DomainIntersection()

Polyhedron * DomainIntersection ( Polyhedron Pol1,
Polyhedron Pol2,
unsigned  NbMaxRays 
)

◆ DomainPreimage()

◆ DomainSimplify()

◆ DomainUnion()

Polyhedron * DomainUnion ( Polyhedron Pol1,
Polyhedron Pol2,
unsigned  NbMaxRays 
)

◆ Empty_Polyhedron()

◆ errormsg1()

◆ FindSimple()

◆ Gauss()

int Gauss ( Matrix Mat,
int  NbEq,
int  Dimension 
)

◆ Gauss4()

static int Gauss4 ( Value **  p,
int  NbEq,
int  NbRows,
int  Dimension 
)
static

◆ ImplicitEqualities()

static int ImplicitEqualities ( Matrix Constraints,
unsigned  NbEq 
)
static

◆ lower_upper_bounds()

◆ p_simplify_constraints()

◆ Polyhedron2Constraints()

◆ Polyhedron2Rays()

Matrix * Polyhedron2Rays ( Polyhedron Pol)

Given a polyhedron 'Pol', return a matrix of rays.

Definition at line 2672 of file polyhedron.c.

References polyhedron::Dimension, errormsg1(), Matrix_Alloc(), polyhedron::NbRays, matrix::p_Init, POL_ENSURE_POINTS, polyhedron::Ray, and Vector_Copy().

Referenced by main().

◆ Polyhedron_Alloc()

◆ Polyhedron_Compute_Dual()

◆ Polyhedron_Copy()

◆ Polyhedron_Free()

◆ Polyhedron_Image()

◆ Polyhedron_Preimage()

◆ Polyhedron_Print()

◆ Polyhedron_PrintConstraints()

void Polyhedron_PrintConstraints ( FILE *  Dst,
const char *  Format,
Polyhedron Pol 
)

◆ Polyhedron_Scan()

◆ PolyhedronIncludes()

◆ polylib_close()

void polylib_close ( void  )

Free all cache allocated memory: call this function before exiting in a memory checker environment like valgrind.

Notice that, in a multithreaded environment, all your threads have to call this function

Definition at line 4843 of file polyhedron.c.

References free_exception_stack(), and free_value_cache().

◆ PolyPrint()

void PolyPrint ( Polyhedron Pol)

Definition at line 1710 of file polyhedron.c.

References Polyhedron_Print().

◆ Rays2Polyhedron()

Polyhedron * Rays2Polyhedron ( Matrix Ray,
unsigned  NbMaxConstrs 
)

Given a matrix of rays 'Ray', create and return a polyhedron.

Parameters
RayRays (may be modified!)
NbMaxConstrsEstimated number of constraints in the polyhedron.
Returns
newly allocated Polyhedron

Definition at line 2087 of file polyhedron.c.

References any_exception_error, CATCH, Chernikova(), Empty_Polyhedron(), errormsg1(), Matrix_Alloc(), Matrix_Free(), Matrix_Print(), matrix::NbColumns, matrix::NbRows, matrix::p, matrix::p_Init, POL_ISSET, POL_NO_DUAL, Polyhedron_Free(), Polyhedron_Print(), Remove_Redundants(), RETHROW, Sat, SMAlloc(), SMFree(), SMPrint(), SMVector_Init, TransformSat(), TRY, UNCATCH, value_set_si, and Vector_Set().

Referenced by main(), Polyhedron_Image(), and traite_m_face().

◆ Rays_Mult()

static void Rays_Mult ( Value **  A,
Matrix B,
Value **  C,
unsigned  NbRays 
)
static

◆ Rays_Mult_Transpose()

static void Rays_Mult_Transpose ( Value **  A,
Matrix B,
Value **  C,
unsigned  NbRays 
)
static

◆ RaySort()

static void RaySort ( Matrix Ray,
SatMatrix Sat,
int  NbBid,
int  NbRay,
int *  equal_bound,
int *  sup_bound,
unsigned  RowSize1,
unsigned  RowSize2,
unsigned  bx,
unsigned  jx 
)
static

Definition at line 296 of file polyhedron.c.

References bexchange, matrix::p, SatMatrix::p, Sat, value_neg_p, value_zero_p, and Vector_Exchange().

Referenced by Chernikova().

◆ Remove_Redundants()

◆ SatMatrix_Extend()

static void SatMatrix_Extend ( SatMatrix Sat,
Matrix Mat,
unsigned  rows 
)
static

Definition at line 352 of file polyhedron.c.

References errormsg1(), matrix::NbRows, SatMatrix::NbRows, SatMatrix::p, SatMatrix::p_init, and Sat.

Referenced by Chernikova().

◆ SatVector_OR()

static void SatVector_OR ( int *  p1,
int *  p2,
int *  p3,
unsigned  length 
)
static

Definition at line 163 of file polyhedron.c.

Referenced by Chernikova().

◆ SimplifyConstraints()

◆ SimplifyEqualities()

static void SimplifyEqualities ( Polyhedron Pol1,
Polyhedron Pol2,
unsigned *  Filter 
)
static

◆ SMAlloc()

static SatMatrix * SMAlloc ( int  rows,
int  cols 
)
static

◆ SMFree()

static void SMFree ( SatMatrix **  matrix)
static

◆ SMPrint()

static void SMPrint ( SatMatrix matrix)
static

Definition at line 144 of file polyhedron.c.

References matrix::NbColumns, matrix::NbRows, and matrix::p.

Referenced by Chernikova(), Constraints2Polyhedron(), and Rays2Polyhedron().

◆ SortConstraints()

static void SortConstraints ( Matrix Constraints,
unsigned  NbEq 
)
static

◆ Stras_DomainSimplify()

◆ SubConstraint()

◆ TransformSat()

static SatMatrix * TransformSat ( Matrix Mat,
Matrix Ray,
SatMatrix Sat 
)
static

Definition at line 257 of file polyhedron.c.

References MSB, matrix::NbRows, NEXT, SatMatrix::p, SatMatrix::p_init, Sat, SMAlloc(), and SMVector_Init.

Referenced by AddRays(), and Rays2Polyhedron().

◆ Universe_Polyhedron()

Variable Documentation

◆ Pol_status