polylib: matrix_addon.h Source File

- Main Page
- Classes
- Files

# matrix_addon.h

Go to the documentation of this file.

    00001 /**
    00002  * Polylib matrix addons
    00003  * Mainly, deals with polyhedra represented in implicit form (set of
    00004  * constraints).
    00005  * @author Benoit Meister
    00006  */
    00007
    00008 #ifndef __BM_MATRIX_ADDON_H__
    00009 #define __BM_MATRIX_ADDON_H__
    00010
    00011 #include<polylib/polylib.h>
    00012 #include<assert.h>
    00013
    00014 /** Shortcut for Matrix_Print */
    00015 #define show_matrix(M) { printf(#M"= \n"); \
    00016                          if (M!=NULL) { \
    00017                          Matrix_Print(stderr,P_VALUE_FMT,(M));} \
    00018                          else {printf("<NULL>\n");} \
    00019                        }
    00020
    00021 /**
    00022  * Allocates a matrix if it is null, or else asserts that it has at least a
    00023  * certain size */
    00024 #define ensureMatrix(M, r, c) { if (M==NULL) M = Matrix_Alloc(r,c); \
    00025                                 else assert (M->NbRows>=r && M->NbColumns>=c); \
    00026                               }
    00027
    00028 /* Creates a view of the constraints of a polyhedron as a Matrix * */
    00029 Matrix * constraintsView(Polyhedron * P);
    00030
    00031 /* "Frees" a view of the constraints of a polyhedron */
    00032 void constraintsView_Free(Matrix * M);
    00033
    00034 /* splits a matrix of constraints M into a matrix of equalities Eqs and a
    00035    matrix of inequalities Ineqs allocs the new matrices. */
    00036 void split_constraints(Matrix const * M, Matrix ** Eqs, Matrix **Ineqs);
    00037
    00038 /* returns the dim-dimensional identity matrix */
    00039 Matrix * Identity_Matrix(unsigned int dim);
    00040
    00041 void Matrix_identity(unsigned int dim, Matrix **I);
    00042
    00043 /* given a n x n integer transformation matrix transf, compute its inverse M/g,
    00044  where M is a nxn integer matrix.  g is a common denominator for elements of
    00045  (transf^{-1})*/
    00046 void mtransformation_inverse(Matrix * transf, Matrix ** inv, Value * g);
    00047
    00048 /* simplifies a matrix seen as a polyhedron, by dividing its rows by the gcd of
    00049 their elements. */
    00050 void mpolyhedron_simplify(Matrix * polyh);
    00051
    00052 /* inflates a polyhedron (represented as a matrix) P, so that the apx of its
    00053    Ehrhart Polynomial is an upper bound of the Ehrhart polynomial of P WARNING:
    00054    this inflation is supposed to be applied on full-dimensional polyhedra. */
    00055 void mpolyhedron_inflate(Matrix * polyh, unsigned int nb_parms);
    00056
    00057 /* deflates a polyhedron (represented as a matrix) P, so that the apx of its
    00058    Ehrhart Polynomial is a lower bound of the Ehrhart polynomial of P WARNING:
    00059    this deflation is supposed to be applied on full-dimensional polyhedra. */
    00060 void mpolyhedron_deflate(Matrix * polyh, unsigned int nb_parms);
    00061
    00062 /* use an eliminator row to eliminate a variable in a victim row (without
    00063 changing the sign of the victim row -> important if it is an inequality).  */
    00064 void eliminate_var_with_constr(Matrix * Eliminator,
    00065                                unsigned int eliminator_row, Matrix * Victim,
    00066                                unsigned int victim_row,
    00067                                unsigned int var_to_elim);
    00068
    00069
    00070 /* ----- PARTIAL MAPPINGS ----- */
    00071
    00072 /* compresses the last vars/pars of the polyhedron M expressed as a polylib
    00073    matrix
    00074  - adresses the full-rank compressions only
    00075  - modfies M */
    00076 void mpolyhedron_compress_last_vars(Matrix * M, Matrix * compression);
    00077 #define Constraints_compressLastVars(a, b) mpolyhedron_compress_last_vars(a, b)
    00078
    00079 /* uses a set of m equalities Eqs to eliminate m variables in the polyhedron.
    00080  Ineqs represented as a matrix eliminates the m first variables
    00081 - assumes that Eqs allows to eliminate the m equalities
    00082 - modifies Ineqs */
    00083 unsigned int mpolyhedron_eliminate_first_variables(Matrix * Eqs,
    00084                                                    Matrix * Ineqs);
    00085 #define Constraints_eliminateFirstVars(a,b) mpolyhedron_eliminate_first_variables(a,b)
    00086
    00087 /** returns a contiguous submatrix of a matrix. */
    00088 void Matrix_subMatrix(Matrix * M, unsigned int sr, unsigned int sc,
    00089                       unsigned int nbR, unsigned int nbC, Matrix ** sub);
    00090 /**
    00091  * Cloning function. Similar to Matrix_Copy() but allocates the target matrix
    00092  * if it is set to NULL.
    00093  */
    00094 void Matrix_clone(Matrix * M, Matrix ** Cl);
    00095
    00096 /**
    00097  * Copies a contiguous submatrix of M1 into M2, at the indicated position.
    00098  * M1 and M2 are assumed t be allocated already.
    00099  */
    00100 void Matrix_copySubMatrix(Matrix *M1,
    00101                           unsigned int sr1, unsigned int sc1,
    00102                           unsigned int nbR, unsigned int nbC,
    00103                           Matrix * M2,
    00104                           unsigned int sr2, unsigned int sc2);
    00105
    00106 /**
    00107  * given a matrix M into -M
    00108  */
    00109 void Matrix_oppose(Matrix * M);
    00110
    00111 #endif /* __BM_MATRIX_ADDON_H__ */