PIPS
normalize.c
Go to the documentation of this file.
1 /*
2 
3  $Id: normalize.c 1671 2019-06-26 19:14:11Z 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 contrainte - NORMALISATION D'UN CONTRAINTE
26  */
27 
28 /*LINTLIBRARY*/
29 
30 #ifdef HAVE_CONFIG_H
31  #include "config.h"
32 #endif
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include "linear_assert.h"
37 
38 #include "boolean.h"
39 #include "arithmetique.h"
40 #include "vecteur.h"
41 #include "contrainte.h"
42 
43 /* bool contrainte_normalize(Pcontrainte c, bool is_egalite): reduction
44  * par le pgcd de ses coefficients d'une egalite (is_egalite==true) ou
45  * d'une inegalite (is_egalite==false)
46  *
47  * Dans le cas des egalites, la faisabilite est testee et retournee
48  *
49  * Modifications:
50  * - double changement du signe du terme constant pour le traitement
51  * des inegalites (Francois Irigoin, 30 octobre 1991)
52  * - ajout d'un test pour les egalites du type 0 == k et les
53  * inegalites 0 <= -k quand k est une constante numerique entiere
54  * strictement positive (Francois Irigoin, 15 novembre 1995)
55  */
57  Pcontrainte c,
58  bool is_egalite)
59 {
60  /* is_c_norm: si is_egalite=true, equation faisable */
61  bool is_c_norm = true;
62  /* pgcd des termes non constant de c */
63  Value a;
64  /* modulo(abs(b0),a) */
65  Value nb0 = VALUE_ZERO;
66 
67  if(c!=NULL && (c->vecteur != NULL))
68  {
70  if (value_notzero_p(a)) {
71  Pvecteur v;
72 
73  nb0 = value_abs(vect_coeff(TCST,c->vecteur));
74  nb0 = value_mod(nb0,a);
75 
76  if (is_egalite) {
77  if (value_zero_p(nb0)) {
78  (void) vect_div(c->vecteur,value_abs(a));
79 
80  /* si le coefficient du terme constant est inferieur
81  * a ABS(a), on va obtenir un couple (TCST,coeff) avec
82  * un coefficient qui vaut 0, ceci est contraire a nos
83  * conventions
84  */
85  c->vecteur = vect_clean(c->vecteur);
86  }
87  else
88  is_c_norm= false;
89  }
90 
91  else {
94  (void) vect_div(c->vecteur,value_abs(a));
95  c->vecteur= vect_clean(c->vecteur);
96  vect_chg_coeff(&(c->vecteur), TCST,
98  /* mise a jour du resultat de la division C
99  * if ( b0 < 0 && nb0 > 0)
100  * vect_add_elem(&(c->vecteur),0,-1);
101  * On n'en a plus besoin parce que vect_div utilise la
102  * division a reste toujours positif dont on a besoin
103  */
104  }
105  v=c->vecteur;
106  if(is_c_norm
107  && !VECTEUR_NUL_P(v)
108  && (vect_size(v) == 1)
109  && term_cst(v)) {
110  if(is_egalite) {
112  is_c_norm = false;
113  }
114  else { /* is_inegalite */
115  is_c_norm = value_negz_p(vecteur_val(v)) ;
116  }
117  }
118  }
119  }
120 
121  return is_c_norm;
122 }
123 
124 /* bool egalite_normalize(Pcontrainte eg): reduction d'une equation
125  * diophantienne par le pgcd de ses coefficients; l'equation est infaisable si
126  * le terme constant n'est pas divisible par ce pgcd
127  *
128  * Soit eg == sum ai xi = b
129  * i
130  * Soit k = pgcd ai
131  * i
132  * eg := eg/k
133  *
134  * return b % k == 0 || all ai == 0 && b != 0;
135  */
137 Pcontrainte eg;
138 {
139  return(contrainte_normalize(eg, true));
140 }
141 
142 /* bool inegalite_normalize(Pcontrainte ineg): normalisation
143  * d'une inegalite a variables entieres; voir contrainte_normalize;
144  * retourne presque toujours true car une inegalite n'ayant qu'un terme
145  * constant est toujours faisable a moins qu'il ne reste qu'un terme
146  * constant strictement positif.
147  *
148  * Soit eg == sum ai xi <= b
149  * i
150  * Soit k = pgcd ai
151  * i
152  * eg := eg/k
153  *
154  * return true unless all ai are 0 and b < 0
155  */
157 Pcontrainte ineg;
158 {
159  return(contrainte_normalize(ineg ,false));
160 }
#define VALUE_ZERO
#define value_notzero_p(val)
#define value_uminus(val)
unary operators on values
#define value_negz_p(val)
#define value_zero_p(val)
int Value
#define value_abs(val)
#define value_mod(v1, v2)
bool egalite_normalize(Pcontrainte eg)
bool egalite_normalize(Pcontrainte eg): reduction d'une equation diophantienne par le pgcd de ses coe...
Definition: normalize.c:136
bool inegalite_normalize(Pcontrainte ineg)
bool inegalite_normalize(Pcontrainte ineg): normalisation d'une inegalite a variables entieres; voir ...
Definition: normalize.c:156
bool contrainte_normalize(Pcontrainte c, bool is_egalite)
package contrainte - NORMALISATION D'UN CONTRAINTE
Definition: normalize.c:56
Value vect_pgcd_except(Pvecteur v, Variable var)
Value vect_pgcd_except(Pvecteur v, Variable var): calcul du pgcd de tous les coefficients non nul d'u...
Definition: reductions.c:130
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
#define assert(ex)
Definition: newgen_assert.h:41
Pvecteur vect_clean(Pvecteur v)
Pvecteur vect_clean(Pvecteur v): elimination de tous les couples dont le coefficient vaut 0 dans le v...
Definition: scalaires.c:80
Pvecteur vect_div(Pvecteur v, Value x)
Pvecteur vect_div(Pvecteur v, Value x): division du vecteur v par le scalaire x, si x est different d...
Definition: scalaires.c:52
Pvecteur vecteur
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_val(v)
#define VECTEUR_NUL_P(v)
#define term_cst(varval)
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
void vect_chg_coeff(Pvecteur *ppv, Variable var, Value val)
void vect_chg_coeff(Pvecteur *ppv, Variable var, Value val): mise de la coordonnee var du vecteur *pp...
Definition: unaires.c:143