1 /******************************************************************************
2 * PIP : Parametric Integer Programming *
3 ******************************************************************************
5 ******************************************************************************
7 * Copyright Paul Feautrier, 1988, 1993, 1994, 1996, 2002 *
9 * This is free software; you can redistribute it and/or modify it under the *
10 * terms of the GNU General Public License as published by the Free Software *
11 * Foundation; either version 2 of the License, or (at your option) any later *
14 * This software is distributed in the hope that it will be useful, but *
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
19 * You should have received a copy of the GNU General Public License along *
20 * with software; if not, write to the Free Software Foundation, Inc., *
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
23 * Written by Cedric Bastoul *
25 ******************************************************************************/
27 /* Premiere version du 18 septembre 2002. */
30 #if !defined(LINEAR_VALUE_IS_LONGLONG) && !defined(LINEAR_VALUE_IS_INT)
31 #if !defined(LINEAR_VALUE_IS_MP)
32 # error Please define LINEAR_VALUE_IS_* or #include polylib32.h or polylib64.h
36 #if defined(LINEAR_VALUE_IS_LONGLONG)
37 # define Entier long long
38 # define FORMAT "%lld"
41 #elif defined(LINEAR_VALUE_IS_INT)
42 # define Entier long int
46 #elif defined(LINEAR_VALUE_IS_MP)
49 # define FORMAT "%lld"
52 # include <piplib/type.h>
53 # include <piplib/sol.h>
54 # include <piplib/tab.h>
55 # include <piplib/funcall.h>
58 /* Structure PipMatrix :
59 * Structure de matrice au format PolyLib. Le premier element d'une ligne
60 * indique quand il vaut 1 que la ligne decrit une inequation de la forme
61 * p(x)>=0 et quand il vaut 0, que la ligne decrit une egalite de la forme
62 * p(x)=0. Le dernier element de chaque ligne correspond au coefficient
66 { unsigned NbRows
, NbColumns
;
70 typedef struct pipmatrix PipMatrix
;
73 /* Structure PipVector :
74 * Cette structure contient un Vector de 'nb_elements' la ieme composante de
75 * ce vecteur vaut the_vector[i]/the_deno[i].
78 { int nb_elements
; /* Nombre d'elements du vecteur. */
79 Entier
* the_vector
; /* Numerateurs du vecteur. */
80 Entier
* the_deno
; /* Denominateurs du vecteur. */
82 typedef struct pipvector PipVector
;
85 /* Structure PipNewparm :
86 * Liste chainee de Newparm, les informations d'un newparm etant son rang, un
87 * vecteur de coefficients et un denominateur. Le newparm est egal a la division
88 * du vecteur par le denominateur.
91 { int rank
; /* Rang du 'newparm'. */
92 PipVector
* vector
; /* Le vector decrivant le newparm. */
93 Entier deno
; /* Denominateur du 'newparm'. */
94 struct pipnewparm
* next
; /* Pointeur vers le newparm suivant. */
96 typedef struct pipnewparm PipNewparm
;
99 /* Structure PipList :
100 * Liste chainee de Vector.
103 { PipVector
* vector
; /* Le vector contenant la partie de solution. */
104 struct piplist
* next
; /* Pointeur vers l'element suivant. */
106 typedef struct piplist PipList
;
109 /* Structure pipquast :
110 * Arbre binaire. Conformement a la grammaire de sortie (voir mode d'emploi), un
111 * noeud de l'arbre des solutions debute par une liste de 'newparm'. Il continue
112 * ensuite soit par une 'list' (alors condition vaut null), soit par un 'if'
113 * (alors le champ condition contient la condition).
116 { PipNewparm
* newparm
; /* Les 'newparm'. */
117 PipList
* list
; /* La 'list' si pas de 'if'. */
118 PipVector
* condition
; /* La condition si 'if'. */
119 struct pipquast
* next_then
; /* Noeud si condition et si verifiee. */
120 struct pipquast
* next_else
; /* Noeud si condition et si non verifiee. */
121 struct pipquast
* father
; /* Pointeur vers le quast pere. */
123 typedef struct pipquast PipQuast
;
126 /* Prototypes des fonctions d'affichages des structures de la PipLib. */
127 void pip_matrix_print(FILE *, PipMatrix
*) ;
128 void pip_vector_print(FILE *, PipVector
*) ;
129 void pip_newparm_print(FILE * foo
, PipNewparm
*, int indent
) ;
130 void pip_list_print(FILE * foo
, PipList
*, int indent
) ;
131 void pip_quast_print(FILE *, PipQuast
*, int) ;
134 /* Prototypes des fonctions de liberation memoire des structures de la PipLib.*/
135 void pip_matrix_free(PipMatrix
*) ;
136 void pip_vector_free(PipVector
*) ;
137 void pip_newparm_free(PipNewparm
*) ;
138 void pip_list_free(PipList
*) ;
139 void pip_quast_free(PipQuast
*) ;
142 /* Prototypes des fonctions d'acquisition de matrices de contraintes.*/
143 PipMatrix
* pip_matrix_alloc(unsigned, unsigned) ;
144 PipMatrix
* pip_matrix_read(FILE *) ;
147 /* Prototype de la fonction de resolution :
148 * pip_solve resoud le probleme qu'on lui passe en parametre, suivant les
149 * options elles aussi en parametre. Elle renvoie la solution sous forme
150 * d'un arbre de PipQuast. Parametres :
152 * 1 PipMatrix : systeme des inequations definissant le domaine des inconnues,
153 * 2 PipMatrix : systeme des inequations satisfaites par les parametres,
154 * 3 int : Bg le bignum,
156 * 4 int : Nq pour savoir si on cherche une solution entiere.
157 * 5 int : Verbose pour savoir si on veut creer un fichier de tracage.
158 * 6 int : Simplify pour demander a Pip de simplifier sa solution.
159 * 7 int : Max encore inutilise, doit etre mis a 0.
161 PipQuast
* pip_solve(PipMatrix
*, PipMatrix
*, int, int, int, int, int) ;
163 /* Ced : ajouts specifiques a la PipLib pour funcall. */
164 Tableau
* tab_Matrix2Tableau(PipMatrix
*, int, int, int) ;
165 PipQuast
* sol_quast_edit(int *, PipQuast
*) ;