PIPS
vecteur-local.h
Go to the documentation of this file.
1 /*
2 
3  $Id: vecteur-local.h 1641 2016-03-02 08:20:19Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of Linear/C3 Library.
8 
9  Linear/C3 Library is free software: you can redistribute it and/or modify it
10  under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  Linear/C3 Library is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with Linear/C3 Library. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 /* package sur les vecteurs creux et les bases
26  *
27  * Malik Imadache, Corinne Ancourt, Neil Butler, Francois Irigoin,
28  * Remi Triolet
29  *
30  * Modifications:
31  * - les fonctions d'interface avec GenPgm dont les noms commencent par
32  * "_gC_" ont ete deplacees dans _gC_lib
33  * - passage a "char *" pour le type Variable au lieu de "int" (Linear-C3)
34  * et de "entity *" (Linear/C3 Library); le package n'est pas independant de la
35  * definition du type "Variable"; il faudrait ameliorer ca avec un
36  * package "Variable"
37  * - ajout des fonctions d'interface avec Newgen: (RT, 27/11/89)
38  * - ajout de la notion de base, comme cas particulier de vecteur
39  * (FI, 27/11/89) ou le champ "Value" n'a pas de signification
40  * - suppression de l'include de vecteur-basic-types.h; la fusion entre
41  * les versions C3 et Linear/C3 Library ne necessite plus cette distinction; il y a
42  * tellement peu de code a ecrire pour les variables et les valeurs
43  * qu'il est inutile d'avoir une directory differente pour lui
44  * - rapatriement de la definition du terme constant TCST et de la macro
45  * term_cst (du package contrainte) (PB, 06/06/90)
46  *
47  * - trop creux a mon avis. il faudrait une liste de petits tableaux ? FC.
48  */
49 
50 #ifndef NEWGEN
51 #define VECTEUR 1006 /* constante associee a un vecteur */
52 #endif
53 
54 /* arithmetique is a requirement for vecteur, but I do not want
55  * to inforce it in all pips files... thus here it is
56  */
57 #include "arithmetique.h"
58 
59 /* le type des variables (ou coordonnees) dans les vecteurs */
60 typedef void * Variable;
61 // The method type that return the name of a variable:
62 typedef char * (*get_variable_name_t)(Variable);
63 
64 #define VARIABLE_UNDEFINED ((Variable) 0)
65 #define VARIABLE_UNDEFINED_P(v) ((v)==VARIABLE_UNDEFINED)
66 #define VARIABLE_DEFINED_P(v) ((v)!=VARIABLE_UNDEFINED)
67 
68 /* le type des coefficients dans les vecteurs:
69  * Value est defini dans le package arithmetique
70  */
71 
72 /* STRUCTURE D'UN VECTEUR
73  *
74  * Un vecteur est defini par une suite de couples Variable (i.e. element
75  * de la base) et Valeur (valeur du coefficient correspondant). Les
76  * coordonnees nulles ne sont pas representees et n'existe qu'implicitement
77  * par rapport a une base (hypothetique) definie via la package "variable".
78  *
79  * En consequence, le vecteur nul est (malencontreusement) represente par
80  * NULL. Cela gene toutes les procedures succeptibles de retourner une
81  * valeur vecteur nul par effet de bord. Il faut alors passer en argument
82  * un POINTEUR vers un Pvecteur. En general, nous avons prefere retourner
83  * explicitement le vecteur calcule, a la maniere de ce qui est fait
84  * dans string.h
85  *
86  * Il n'existe pas non plus de VECTEUR_UNDEFINED, puisque sa valeur devrait
87  * logiquement etre NULL.
88  */
89 typedef struct Svecteur {
92  struct Svecteur *succ;
94 
95 /* STRUCTURE D'UNE BASE
96  *
97  * Une base est definie par son vecteur diagonal
98  *
99  * Les tests d'appartenance sont effectues par comparaison des pointeurs
100  * et non par des strcmp.
101  *
102  * Rien ne contraint les coefficients a valoir 1 et le package plint
103  * mais meme certains coefficients a 0, ce qui devrait revenir a faire
104  * disparaitre la variable (i.e. la coordonnee) correspondante de la
105  * base.
106  */
107 typedef struct Svecteur Sbase, * Pbase;
108 
109 /* DEFINITION DU VECTEUR NUL */
110 #define VECTEUR_NUL ((Pvecteur) 0)
111 #define VECTEUR_NUL_P(v) ((v)==VECTEUR_NUL)
112 #define VECTEUR_UNDEFINED ((Pvecteur) 0)
113 #define VECTEUR_UNDEFINED_P(v) ((v)==VECTEUR_UNDEFINED)
114 
115 /* definition de la valeur de type PlinX==Pvecteur qui correspond a un
116  * vecteur indefini parce que l'expression correspondante n'est pas
117  * lineaire (Malik Imadache, Jean Goubault ?)
118  */
119 #define PlinX Pvecteur
120 #define NONEXPLIN ((PlinX)-1)
121 
122 /* MACROS SUR LES VECTEURS */
123 #define print_vect(s) vect_fprint(stdout,(s))
124 #define var_of(varval) ((varval)->var)
125 #define val_of(varval) ((varval)->val)
126 #define vecteur_var(v) ((v)->var)
127 #define vecteur_val(v) ((v)->val)
128 #define vecteur_succ(v) ((v)->succ)
129 
130 /* VARIABLE REPRESENTANT LE TERME CONSTANT */
131 #define TCST ((Variable) 0)
132 #define term_cst(varval) ((varval)->var == TCST)
133 
134 /* MACROS SUR LES BASES */
135 #define BASE_NULLE VECTEUR_NUL
136 #define BASE_NULLE_P(b) ((b)==VECTEUR_NUL)
137 #define BASE_UNDEFINED ((Pbase) 0)
138 #define BASE_UNDEFINED_P(b) ((b)==BASE_UNDEFINED)
139 #define base_dimension(b) vect_size((Pvecteur)(b))
140 #define base_add_dimension(b,v) vect_chg_coeff((Pvecteur *)(b),(v),VALUE_ONE)
141 #define base_rm(b) (vect_rm((Pvecteur)(b)), (b)=BASE_NULLE)
142 #define BASE_FOREACH(v, b) \
143  Pbase v ## _base = b; \
144  Variable v = v ## _base? v ## _base->var: NULL; \
145  for(; v ## _base != BASE_NULLE; v ## _base = v ## _base->succ, v = v ## _base? v ## _base->var: NULL)
146 
147 /* I do thing that overflows are managed in a very poor manner. FC.
148  * It should be all or not, as provided by any os that would raise
149  * integer overflows. Thus we should have thought of a sofware
150  * mecanism compatible with such a hardware and os approach.
151  * maybe by defining a mult_Value macro to check explicitely for
152  * overflows if needed, and defined to a simple product if not.
153  * functions would have an additional argument for returning a
154  * conservative answer in case of overflow. Maybe some global
155  * variable could count the number of overflow that occured so that
156  * some caller could check whether sg got wrong and thus could
157  * warn about the result and this fact.
158  * then we would have either the library compiled for these soft checks
159  * or for none, but without any difference or explicite requirements
160  * from the user of these functions.
161  *
162  * instead of that, we have the two versions at the same time with explicite
163  * control required from the user. I heard that for some functions
164  * this is not used... thus allowing good performance (each time some
165  * result is false someone tracks down the not checked function and
166  * checks overflow explicitely, thus it is not a very good approach).
167  * moreover the most costly functions (simplexe, chernikova) are also
168  * those in which the exceptions occurs thus they are all checked.
169  * the the impact on performances is definitely low.
170  * as far as software engineering is concerned, the current solution
171  * adds low level switch for calling different versions (controled or not)
172  * of pieces of code... this will have to be removed if some good os
173  * is to host this software...
174  */
175 
176 /* OVERFLOW CONTROL
177  */
178 #if (defined(LINEAR_NO_OVERFLOW_CONTROL))
179 #define OFL_CTRL 0
180 #define FWD_OFL_CTRL 0
181 #define NO_OFL_CTRL 0
182 #else /* some OVERFLOW CONTROL is allowed */
183 #define OFL_CTRL 2 /* overflows are treated in the called procedure */
184 #define FWD_OFL_CTRL 1 /* overflows are treated by the calling procedure */
185 #define NO_OFL_CTRL 0 /* overflows are not trapped at all (dangerous !) */
186 #endif /* LINEAR_NO_OVERFLOW_CONTROL */
187 
188 /* internal hash table for variable sets. */
189 struct linear_hashtable_st;
191 
192 /* end of vecteur-local.h */
int Value
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
Value val
Definition: vecteur-local.h:91
Variable var
Definition: vecteur-local.h:90
struct Svecteur * succ
Definition: vecteur-local.h:92
hidden structure to store the hashtable.
Definition: hashpointer.c:66
struct linear_hashtable_st * linear_hashtable_pt
struct Svecteur * Pbase
struct Svecteur * Pvecteur
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
struct Svecteur Svecteur
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique