polylib 5.22.8
matrix_addon.h
Go to the documentation of this file.
1/**
2 * Polylib matrix addons
3 * Mainly, deals with polyhedra represented in implicit form (set of
4 * constraints).
5 * @author Benoit Meister
6 */
7
8#ifndef __BM_MATRIX_ADDON_H__
9#define __BM_MATRIX_ADDON_H__
10
11#include <assert.h>
12#include <polylib/polylib.h>
13
14/** Shortcut for Matrix_Print */
15#define show_matrix(M) \
16 { \
17 printf(#M "= \n"); \
18 if (M != NULL) { \
19 Matrix_Print(stderr, P_VALUE_FMT, (M)); \
20 } else { \
21 printf("<NULL>\n"); \
22 } \
23 }
24
25/**
26 * Allocates a matrix if it is null, or else asserts that it has at least a
27 * certain size */
28#define ensureMatrix(M, r, c) \
29 { \
30 if (M == NULL) \
31 M = Matrix_Alloc(r, c); \
32 else \
33 assert(M->NbRows >= r && M->NbColumns >= c); \
34 }
35
36/* Creates a view of the constraints of a polyhedron as a Matrix * */
38
39/* "Frees" a view of the constraints of a polyhedron */
41
42/* splits a matrix of constraints M into a matrix of equalities Eqs and a
43 matrix of inequalities Ineqs allocs the new matrices. */
44void split_constraints(Matrix const *M, Matrix **Eqs, Matrix **Ineqs);
45
46/* returns the dim-dimensional identity matrix */
47Matrix *Identity_Matrix(unsigned int dim);
48
49void Matrix_identity(unsigned int dim, Matrix **I);
50
51/* given a n x n integer transformation matrix transf, compute its inverse M/g,
52 where M is a nxn integer matrix. g is a common denominator for elements of
53 (transf^{-1})*/
54void mtransformation_inverse(Matrix *transf, Matrix **inv, Value *g);
55
56/* simplifies a matrix seen as a polyhedron, by dividing its rows by the gcd of
57their elements. */
58void mpolyhedron_simplify(Matrix *polyh);
59
60/* inflates a polyhedron (represented as a matrix) P, so that the apx of its
61 Ehrhart Polynomial is an upper bound of the Ehrhart polynomial of P WARNING:
62 this inflation is supposed to be applied on full-dimensional polyhedra. */
63void mpolyhedron_inflate(Matrix *polyh, unsigned int nb_parms);
64
65/* deflates a polyhedron (represented as a matrix) P, so that the apx of its
66 Ehrhart Polynomial is a lower bound of the Ehrhart polynomial of P WARNING:
67 this deflation is supposed to be applied on full-dimensional polyhedra. */
68void mpolyhedron_deflate(Matrix *polyh, unsigned int nb_parms);
69
70/* use an eliminator row to eliminate a variable in a victim row (without
71changing the sign of the victim row -> important if it is an inequality). */
72void eliminate_var_with_constr(Matrix *Eliminator, unsigned int eliminator_row,
73 Matrix *Victim, unsigned int victim_row,
74 unsigned int var_to_elim);
75
76/* ----- PARTIAL MAPPINGS ----- */
77
78/* compresses the last vars/pars of the polyhedron M expressed as a polylib
79 matrix
80 - adresses the full-rank compressions only
81 - modfies M */
82void mpolyhedron_compress_last_vars(Matrix *M, Matrix *compression);
83#define Constraints_compressLastVars(a, b) mpolyhedron_compress_last_vars(a, b)
84
85/* uses a set of m equalities Eqs to eliminate m variables in the polyhedron.
86 Ineqs represented as a matrix eliminates the m first variables
87- assumes that Eqs allows to eliminate the m equalities
88- modifies Ineqs */
89unsigned int mpolyhedron_eliminate_first_variables(Matrix *Eqs, Matrix *Ineqs);
90#define Constraints_eliminateFirstVars(a, b) \
91 mpolyhedron_eliminate_first_variables(a, b)
92
93/** returns a contiguous submatrix of a matrix. */
94void Matrix_subMatrix(Matrix *M, unsigned int sr, unsigned int sc,
95 unsigned int nbR, unsigned int nbC, Matrix **sub);
96/**
97 * Cloning function. Similar to Matrix_Copy() but allocates the target matrix
98 * if it is set to NULL.
99 */
100void Matrix_clone(Matrix *M, Matrix **Cl);
101
102/**
103 * Copies a contiguous submatrix of M1 into M2, at the indicated position.
104 * M1 and M2 are assumed t be allocated already.
105 */
106void Matrix_copySubMatrix(Matrix *M1, unsigned int sr1, unsigned int sc1,
107 unsigned int nbR, unsigned int nbC, Matrix *M2,
108 unsigned int sr2, unsigned int sc2);
109
110/**
111 * given a matrix M into -M
112 */
113void Matrix_oppose(Matrix *M);
114
115#endif /* __BM_MATRIX_ADDON_H__ */
void mpolyhedron_deflate(Matrix *polyh, unsigned int nb_parms)
deflates a polyhedron (represented as a matrix) P, so that the apx of its Ehrhart Polynomial is a low...
Definition: matrix_addon.c:186
void split_constraints(Matrix const *M, Matrix **Eqs, Matrix **Ineqs)
splits a matrix of constraints M into a matrix of equalities Eqs and a matrix of inequalities Ineqs a...
Definition: matrix_addon.c:31
void mpolyhedron_compress_last_vars(Matrix *M, Matrix *compression)
compress the last vars/pars of the polyhedron M expressed as a polylib matrix
Definition: matrix_addon.c:261
Matrix * Identity_Matrix(unsigned int dim)
Definition: matrix_addon.c:58
unsigned int mpolyhedron_eliminate_first_variables(Matrix *Eqs, Matrix *Ineqs)
use a set of m equalities Eqs to eliminate m variables in the polyhedron Ineqs represented as a matri...
Definition: matrix_addon.c:288
void eliminate_var_with_constr(Matrix *Eliminator, unsigned int eliminator_row, Matrix *Victim, unsigned int victim_row, unsigned int var_to_elim)
use an eliminator row to eliminate a variable in a victim row (without changing the sign of the victi...
Definition: matrix_addon.c:213
void Matrix_clone(Matrix *M, Matrix **Cl)
Cloning function.
Definition: matrix_addon.c:345
void constraintsView_Free(Matrix *M)
"Frees" a view of the constraints of a polyhedron
Definition: matrix_addon.c:24
void mpolyhedron_inflate(Matrix *polyh, unsigned int nb_parms)
inflates a polyhedron (represented as a matrix) P, so that the apx of its Ehrhart Polynomial is an up...
Definition: matrix_addon.c:164
void Matrix_copySubMatrix(Matrix *M1, unsigned int sr1, unsigned int sc1, unsigned int nbR, unsigned int nbC, Matrix *M2, unsigned int sr2, unsigned int sc2)
Copies a contiguous submatrix of M1 into M2, at the indicated position.
Definition: matrix_addon.c:361
void Matrix_oppose(Matrix *M)
given a matrix M into -M
Definition: matrix_addon.c:373
void mpolyhedron_simplify(Matrix *polyh)
simplify a matrix seen as a polyhedron, by dividing its rows by the gcd of their elements.
Definition: matrix_addon.c:145
void Matrix_identity(unsigned int dim, Matrix **I)
returns the dim-dimensional identity matrix.
Definition: matrix_addon.c:77
void mtransformation_inverse(Matrix *transf, Matrix **inv, Value *g)
given a n x n integer transformation matrix transf, compute its inverse M/g, where M is a nxn integer...
Definition: matrix_addon.c:98
void Matrix_subMatrix(Matrix *M, unsigned int sr, unsigned int sc, unsigned int nbR, unsigned int nbC, Matrix **sub)
returns a contiguous submatrix of a matrix.
Definition: matrix_addon.c:325
Matrix * constraintsView(Polyhedron *P)
Creates a view of the constraints of a polyhedron as a Matrix *.
Definition: matrix_addon.c:15
Definition: types.h:75