polylib: matrix_addon.h Source File

- Main Page
- Classes
- Files

- File List
- File Members

# matrix_addon.h

Go to the documentation of this file.

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