PIPS
plpivoter.c
Go to the documentation of this file.
1 /*
2 
3  $Id: plpivoter.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 #include "boolean.h"
31 #include "arithmetique.h"
32 #include "vecteur.h"
33 #include "contrainte.h"
34 #include "sc.h"
35 #include "sommet.h"
36 #include "matrix.h"
37 
38 #include "plint.h"
39 
40 #define MALLOC(s,t,f) malloc(s)
41 char * malloc();
42 
43 #define TRACE
44 
45 /*
46  * Remplacement de la variable VAR dans la contrainte EQ par sa valeur dans
47  * la contrainte LIGNE.
48  *
49  * resultat retourne par la fonction :
50  *
51  * La contrainte EQ est modifiee.
52  *
53  * Les parametres de la fonction :
54  *
55  * Psommet eq : contrainte du systeme
56  * Psommet ligne : contrainte du systeme ( ligne pivot)
57  * int var : variable pivot
58  */
59 
60 
61 void pivoter_pas(eq,ligne,var)
62 Psommet eq;
63 Psommet ligne;
64 Variable var;
65 {
66 
67 
68  Pvecteur pvec = NULL;
69  Pvecteur ligne2;
70 
71  Value c1 = VALUE_ZERO;
72  Value den;
73  bool cst = false;
74 #ifdef TRACE
75  printf(" --- pas - pivoter \n");
76 #endif
77  if (ligne && eq) {
78  Pvecteur pv3 = vect_dup(eq->vecteur);
79 
80  den = ligne->denominateur;
81  cst = false;
82  if ((eq != ligne) && value_notzero_p(c1 = vect_coeff(var,pv3))) {
83 
84  ligne2 = vect_dup(ligne->vecteur);
85  value_product(eq->denominateur,den);
86  for (pvec =pv3;pvec!= NULL; pvec=pvec->succ) {
87  Value tmp;
88  if (pvec->var == NULL) cst = true;
89 
90  value_product(pvec->val,den);
91  tmp = vect_coeff(pvec->var,ligne->vecteur);
92  value_product(tmp,c1);
93  value_substract(pvec->val,tmp);
94 
95  vect_chg_coeff(&ligne2,pvec->var,VALUE_ZERO);
96  }
97 
98  for (pvec=ligne2;pvec!= NULL;pvec = pvec->succ)
99  if (pvec->var != TCST)
100  {
101  Value tmp = vect_coeff(pvec->var,ligne2);
102  value_product(tmp,c1);
103  vect_add_elem(&pv3,pvec->var,value_uminus(tmp));
104  }
105  if (!cst)
106  {
107  Value tmp = vect_coeff(TCST,ligne->vecteur);
108  value_product(tmp,c1);
109  vect_add_elem(&pv3,TCST,value_uminus(tmp));
110  }
111  }
112  eq->vecteur = pv3;
113  }
114 }
115 
116 /*
117  * Operation "pivot" avec VAR comme variable pivot et LIGNE comme ligne
118  * pivot.
119  *
120  * resultat retourne par la fonction :
121  *
122  * Le systeme initial est modifie.
123  *
124  * Les parametres de la fonction :
125  *
126  * Psommet sys : systeme lineaire
127  * Psommet fonct : fonction economique du programme lineaire
128  * Psommet ligne : ligne pivot
129  * int var : variable pivot
130  */
131 void pivoter(sys,ligne,var,fonct)
132 Psommet sys;
133 Psommet ligne;
134 Variable var;
135 Psommet fonct;
136 
137 {
138 
139  Psommet sys1 = fonct;
140  Psommet ps1 = NULL;
141  int sgn_den = 1;
142  Value den,tmp;
143 #ifdef TRACE
144  printf(" *** on effectue le pivot \n");
145 #endif
146  if (ligne) {
147 
148  den = vect_coeff(var,ligne->vecteur);
149  if (value_neg_p(den))
150  {
151  sgn_den = -1;
152  value_oppose(den);
153  }
154  if (fonct != NULL)
155  fonct->succ = sys;
156  else sys1 = sys;
157 
158  /* mise a jour du denominateur */
159  tmp = ligne->denominateur;
160  if (sgn_den==-1) value_oppose(tmp);
161  (void) vect_multiply(ligne->vecteur,tmp);
162  value_product(ligne->denominateur,den);
163  den = ligne->denominateur;
164  for (ps1 = sys1; ps1!= NULL; ps1=ps1->succ)
165  pivoter_pas(ps1,ligne,var);
166  sommets_normalize(sys1);
167 
168  }
169  if (fonct)
170  fonct->succ = NULL;
171 
172 }
173 
#define VALUE_ZERO
#define value_oppose(ref)
#define value_notzero_p(val)
#define value_uminus(val)
unary operators on values
int Value
#define value_product(v, w)
#define value_substract(ref, val)
#define value_neg_p(val)
void pivoter(Psommet sys, Psommet ligne, Variable var, Psommet fonct)
Definition: plpivoter.c:131
void pivoter_pas(Psommet eq, Psommet ligne, Variable var)
Definition: plpivoter.c:61
char * malloc()
Pcontrainte eq
element du vecteur colonne du systeme donne par l'analyse
Definition: sc_gram.c:108
int printf()
Pvecteur vect_multiply(Pvecteur v, Value x)
Pvecteur vect_multiply(Pvecteur v, Value x): multiplication du vecteur v par le scalaire x,...
Definition: scalaires.c:123
void sommets_normalize(Psommet)
void sommets_normalize(som) Normalisation des elements d'une liste de sommets i.e.
Definition: sommets.c:108
Pvecteur vecteur
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
structure de donnees Sommet
Definition: sommet-local.h:64
struct typ_som * succ
Definition: sommet-local.h:68
Pvecteur vecteur
Definition: sommet-local.h:66
Value denominateur
Definition: sommet-local.h:67
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
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
Pvecteur vect_dup(Pvecteur v_in)
Pvecteur vect_dup(Pvecteur v_in): duplication du vecteur v_in; allocation de et copie dans v_out;.
Definition: alloc.c:51
void vect_add_elem(Pvecteur *pvect, Variable var, Value val)
void vect_add_elem(Pvecteur * pvect, Variable var, Value val): addition d'un vecteur colineaire au ve...
Definition: unaires.c:72
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