PIPS
sc_integer_analyze.c
Go to the documentation of this file.
1 /*
2 
3  $Id: sc_integer_analyze.c 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 #ifdef HAVE_CONFIG_H
26  #include "config.h"
27 #endif
28 
29 #include <stdio.h>
30 
31 #include "boolean.h"
32 #include "arithmetique.h"
33 #include "vecteur.h"
34 #include "contrainte.h"
35 #include "sc.h"
36 
39 
40 /* This function returns true:
41  * if all positive OR all negative coefficients of the variable
42  * var in the system are equal to 1.
43  * That's mean that the FM projection can be used without problem on
44  * integer domain
45 */
47 Psysteme sc;
48 Variable var;
49 {
50  register Pcontrainte pc;
51 
52  if (!var_in_sc_p(sc,var))
53  return false;
54 
55  for (pc = sc->inegalites; !CONTRAINTE_UNDEFINED_P(pc); pc = pc->succ)
56  {
57  Value coeff = vect_coeff(var,pc->vecteur);
58  if (value_gt(coeff, VALUE_ONE) ||
59  value_lt(coeff, VALUE_MONE))
60  return false;
61  }
62  for (pc = sc->egalites; !CONTRAINTE_UNDEFINED_P(pc); pc = pc->succ)
63  {
64  Value coeff = vect_coeff(var,pc->vecteur);
65  if (value_gt(coeff, VALUE_ONE) ||
66  value_lt(coeff, VALUE_MONE))
67  return false;
68  }
69 
70  return true;
71 }
72 
73 /* This function gives information about the variables and the constraints of
74  * the system. These informations are stored in the array sc_info.
75  *
76  * the first information: if the variable must be kept as loop index
77  * then sc_info[rank of the variable][1] is greater than 1.
78  *
79  * the second information: sc_info[rank of the variable][2] is the number
80  * of constraints constraining the variable as upper bound.
81  *
82  * ths third information: sc_info[rank of the variable][3] is the number
83  * of constraints constraining the variable as lower bound.
84  *
85 */
86 
88  Psysteme sc,
89  Pbase index_base,
90  int sc_info[][4],
91  int dim_h,
92  int n)
93 {
94 
95  Pcontrainte ineq,pc;
96  Variable var_hr,hvr1,hvr2,right_var,left_var;
97  int rank_hr,right_rank,left_rank;
98  int sign1,sign2;
99  Value coeff1,coeff2,right_coeff,left_coeff;
100  bool find_one = false;
101  register int i;
102  register int j;
103 
104  /* Initialisation of the array sc_info */
105  // ??? should it be from 0 to n-1
106  for (i=1; i<=n; i++)
107  for (j=2; j<=3; j++)
108  sc_info[i][j]=0;
109 
110  for (i=1; i<=dim_h; i++)
111  sc_info[i][1]=1;
112 
113  for (i=dim_h+1; i<=n; i++)
114  sc_info[i][1]=0;
115 
116  /* Computation of variables that must be kept as loop indices. */
117 
118  for (ineq = sc->inegalites;
119  !CONTRAINTE_UNDEFINED_P(ineq); ineq=ineq->succ) {
120 
121  find_one=false;
122  if ((rank_hr= search_higher_rank(ineq->vecteur,index_base)) >dim_h) {
123 
124  /* if the variable rank is greater than n, the constraints may be
125  eliminated if they do not appear in constraints of higher
126  rank and having to be keept */
127 
128  var_hr=variable_of_rank(index_base,rank_hr);
129  coeff1 = vect_coeff(var_hr,ineq->vecteur);
130  sign1 = value_sign(coeff1);
131 
132  for (pc = ineq;
133  !CONTRAINTE_UNDEFINED_P(pc) && !find_one;
134  pc = pc->succ) {
135 
136  coeff2 = vect_coeff(var_hr,pc->vecteur);
137  sign2 = value_sign(coeff2);
138  if (value_notzero_p(coeff2) && sign1 == -sign2) {
140  index_base,var_hr);
142  index_base,var_hr);
143  if ((hvr1 ==hvr2) &&
144  (rank_of_variable(index_base,hvr1) >dim_h)) {
145  sc_info[rank_of_variable(index_base,hvr1)][1] ++;
146  find_one = true;
147  }
148  }
149  }
150  }
151  }
152 
153 
154  /* Computation of the number of constraints contraining a variable
155  either as lower bound or upper bound */
156 
157  for (ineq = sc->inegalites;
158  !CONTRAINTE_UNDEFINED_P(ineq); ineq=ineq->succ) {
159  if ((rank_hr= search_higher_rank(ineq->vecteur,index_base))>0) {
160  var_hr=variable_of_rank(index_base,rank_hr);
161  coeff1 = vect_coeff(var_hr,ineq->vecteur);
162 
163  if (rank_hr >dim_h) {
164  if (sc_info[rank_hr][1]) {
165 
166  /* If the variable is a loop index then the constraint
167  ineq gives an upper or a lower bound directly */
168 
169  if (value_pos_p(coeff1)) sc_info[rank_hr][2] ++;
170  else sc_info[rank_hr][3] ++;
171  }
172  else {
173 
174  /* If the variable is not a loop index then the constraint
175  ineq combined with another constraint pc gives an upper
176  or a lower bound for another variable */
177 
178  for (pc = ineq;
180  pc = pc->succ) {
181 
182  coeff2 = vect_coeff(var_hr,pc->vecteur);
183  sign2 = value_sign(coeff2);
184  sign1 = value_sign(coeff1);
185 
186  if (value_notzero_p(coeff2) && sign1 == -sign2) {
188  (index_base, ineq, pc, rank_hr,
189  &right_var, &right_rank, &right_coeff,
190  &left_var, &left_rank, &left_coeff);
191  if (right_rank>left_rank) {
192  if (value_pos_p(right_coeff))
193  sc_info[right_rank][2]++;
194  else
195  sc_info[right_rank][3]++;
196  }
197  else if (right_rank<left_rank){
198  if (value_pos_p(left_coeff))
199  sc_info[left_rank][2]++;
200  else
201  sc_info[left_rank][3]++;
202  }
203  }
204  }
205  }
206  }
207  else
208  /* If the variable is a loop index then the constraint
209  ineq gives an upper or a lower bound directly */
210 
211  if (value_neg_p(vect_coeff(var_hr,ineq->vecteur)))
212  sc_info[rank_hr][3] ++;
213  else
214  sc_info[rank_hr][2] ++;
215 
216  }
217  }
218 }
219 
220 
221 /* This function computes the coefficients of the constraint resulting
222  * from the elimination of the variable of rank "rank" from the 2
223  * inequalities ineq1 and ineq2.
224  * Assuming that:
225  * ineq1 is the constraint a0 X2 + + E0 + b0 <= 0
226  * ineq2 is the constraint - a1 X2 + E1 + b1 <=0
227  * where E1 contains X1, E0 contains X0 and a0,a1 >0
228  * then the result of the fonction will be:
229  * right_var = X0, right_rank=rank(X0), right_ceoff=ceofficient of X0 in E0
230  * left_var = X1, left_rank=rank(X10, left_coeff=coefficient of X1 in E1
231 */
232 
233 void
235  Pbase index_base,
236  Pcontrainte ineq1,
237  Pcontrainte ineq2,
238  int rank,
239  Variable *right_var, /* RIGHT */
240  int *right_rank,
241  Value *right_coeff,
242  Variable *left_var, /* LEFT */
243  int *left_rank,
244  Value *left_coeff)
245 {
246 
247 
248  Pcontrainte right_ineg= CONTRAINTE_UNDEFINED;
249  Pcontrainte left_ineg = CONTRAINTE_UNDEFINED;
250  Variable el_var= variable_of_rank(index_base,rank);
251 
252  if (value_pos_p(vect_coeff(el_var,ineq1->vecteur))) {
253  right_ineg = ineq1;
254  left_ineg = ineq2;
255  }
256  else {
257  if (value_pos_p(vect_coeff(el_var,ineq2->vecteur))) {
258  right_ineg = ineq2;
259  left_ineg = ineq1;
260  }
261  }
262  *right_var = search_var_of_higher_rank(right_ineg->vecteur,
263  index_base,
264  el_var);
265  *left_var = search_var_of_higher_rank(left_ineg->vecteur,
266  index_base,
267  el_var);
268  *right_rank = rank_of_variable(index_base,*right_var);
269  *left_rank = rank_of_variable(index_base,*left_var);
270  *right_coeff = vect_coeff(*right_var,right_ineg->vecteur);
271  *left_coeff = vect_coeff(*left_var,left_ineg->vecteur);
272 
273 }
#define value_pos_p(val)
#define value_sign(v)
trian operators on values
#define value_gt(v1, v2)
#define value_notzero_p(val)
#define VALUE_MONE
int Value
#define VALUE_ONE
#define value_lt(v1, v2)
#define value_neg_p(val)
int rank_of_variable(Pbase base, Variable var)
this function returns the rank of the variable var in the base 0 encodes TCST, but I do not know why,...
Definition: base.c:497
int search_higher_rank(Pvecteur vect, Pbase base)
int search_higher_rank(): this fonction returns the rank of the variable of higher rank in the vecteu...
Definition: base.c:541
#define CONTRAINTE_UNDEFINED_P(c)
#define CONTRAINTE_UNDEFINED
static entity rank
void sc_integer_projection_information(Psysteme sc, Pbase index_base, int sc_info[][4], int dim_h, int n)
This function gives information about the variables and the constraints of the system.
Variable search_var_of_higher_rank()
Variable variable_of_rank()
bool var_with_unity_coeff_p(Psysteme sc, Variable var)
This function returns true: if all positive OR all negative coefficients of the variable var in the s...
void constraint_integer_combination(Pbase index_base, Pcontrainte ineq1, Pcontrainte ineq2, int rank, Variable *right_var, int *right_rank, Value *right_coeff, Variable *left_var, int *left_rank, Value *left_coeff)
This function computes the coefficients of the constraint resulting from the elimination of the varia...
bool var_in_sc_p(Psysteme sc, Variable var)
bool var_in_sc_p(Psysteme sc, Variable var) Cette fonction teste si la variable est contrainte par le...
Definition: sc_var.c:139
Pvecteur vecteur
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
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
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228