PIPS
plsomvb-test.c
Go to the documentation of this file.
1 /*
2 
3  $Id: plsomvb-test.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 /*
44  * Cette fonction teste si l'un des termes constants des contraintes est negatif
45  *
46  * resultat retourne par la fonction :
47  *
48  * bool : == true si l'un des termes constants est negatif
49  * == false sinon
50  *
51  * Les parametres de la fonction :
52  *
53  * Psommet som : systeme lineaire
54  *
55  */
56 
57 bool const_negative(som)
58 Psommet som;
59 {
60  Psommet ps;
61  bool result = false;
62 
63  for (ps = som;
64  ps!= NULL && value_negz_p(vect_coeff(TCST,ps->vecteur));
65  ps= ps->succ);
66  result = (ps == NULL) ? false : true;
67  return (result);
68 }
69 
70 
71 
72 /*
73  * Si la partie constante d'une contrainte est negative, il faut que l'un des
74  * coefficients des variables de la contrainte le soit aussi pour que le systeme
75  * reste borne.
76  *
77  * resultat retourne par la fonction :
78  *
79  * bool : false si la contrainte montre que le systeme est non borne
80  * true sinon
81  *
82  * Les parametres de la fonction :
83  *
84  * Psommet eq : contrainte du systeme
85  */
86 
88 Psommet eq;
89 {
90  Pvecteur pv = NULL;
91  bool result= false;
92 
93  if (eq) {
94  pv = eq->vecteur;
95  if (value_pos_p(vect_coeff(TCST,pv)))
96  {
97  for (pv= eq->vecteur;pv!= NULL
98  && ((pv->var ==NULL) || value_pos_p(pv->val))
99  ;pv= pv->succ);
100  result = (pv==NULL) ? false : true;
101  }
102  else result = true;
103  }
104  return (result);
105 
106 }
107 
108 
109 
110 
111 
112 /*
113  * Cette fonction teste s'il existe une variable hors base de cout nul
114  * dans le systeme
115  *
116  * resultat retourne par la fonction :
117  *
118  * bool : true s'il existe une variable hors base de cout
119  * nul
120  *
121  * Les parametres de la fonction :
122  *
123  * Psommet fonct : fonction economique du programme lineaire
124  * Pvecteur lvbase: liste des variables de base du systeme
125  */
126 
127 bool cout_nul(fonct,lvbase,nbvars,b)
128 Psommet fonct;
129 Pvecteur lvbase;
130 int nbvars;
131 Pbase b;
132 {
133  Pvecteur liste1 = NULL; /* liste des variables h.base de cout nul */
134  Pvecteur pv=NULL;
135  Pvecteur pv2=VECTEUR_NUL;
136  register int i;
137  bool result= false;
138 
139 #ifdef TRACE
140  printf(" ** Gomory - existe-t-il une var. h.base de cout nul \n");
141 #endif
142 
143  liste1 = vect_new(vecteur_var(b),VALUE_ONE);
144  for (i = 1 ,pv2 = b->succ;
145  i< nbvars && !VECTEUR_NUL_P(pv2);
146  i++, pv2=pv2->succ)
147  vect_add_elem (&(liste1),vecteur_var(pv2),VALUE_ONE);
148  if (fonct != NULL)
149  for (pv = fonct->vecteur;pv != NULL;pv=pv->succ)
150  if (value_notzero_p(pv->val))
151  vect_chg_coeff(&liste1,pv->var,0);
152 
153  for (pv = lvbase;pv != NULL;pv=pv->succ)
154  if (value_notzero_p(pv->val))
155  vect_chg_coeff(&liste1,pv->var,0);
156  result = (liste1 != NULL) ? true : false;
157 
158  vect_rm(liste1);
159  return (result);
160 
161 }
162 
#define value_pos_p(val)
#define value_notzero_p(val)
#define value_negz_p(val)
#define VALUE_ONE
bool cout_nul(Psommet fonct, Pvecteur lvbase, int nbvars, Pbase b)
Definition: plsomvb-test.c:127
bool const_negative(Psommet som)
Definition: plsomvb-test.c:57
char * malloc()
bool test_borne(Psommet eq)
Definition: plsomvb-test.c:87
Pcontrainte eq
element du vecteur colonne du systeme donne par l'analyse
Definition: sc_gram.c:108
int printf()
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
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_var(v)
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
#define VECTEUR_NUL_P(v)
Pvecteur vect_new(Variable var, Value coeff)
Pvecteur vect_new(Variable var,Value coeff): allocation d'un vecteur colineaire au vecteur de base va...
Definition: alloc.c:110
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78
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