PIPS
sc_var.c
Go to the documentation of this file.
1 /*
2 
3  $Id: sc_var.c 1669 2019-06-26 17:24:57Z 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 sc */
26 
27 #ifdef HAVE_CONFIG_H
28  #include "config.h"
29 #endif
30 
31 #include <string.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 
35 #include "linear_assert.h"
36 
37 #include "boolean.h"
38 #include "arithmetique.h"
39 #include "vecteur.h"
40 #include "contrainte.h"
41 #include "sc.h"
42 
43 #define MALLOC(s,t,f) malloc(s)
44 #define FREE(p,t,f) free(p)
45 
46 /* char * noms_var(int i):
47  * cette fonction convertit un numero de variable en chaine de caracteres
48  *
49  * resultat retourne par la fonction :
50  *
51  * char * : chaine de caracteres associee au numero de variable
52  *
53  * Les parametres de la fonction :
54  *
55  * int i : numero de variable du systeme
56  *
57  * FI: a regarder et a commenter et a transferer dans base.dir; pourrait-etre
58  * un variable_default_name()? Ou integer_default_name()?
59  *
60  * FI: suppression avec le passage a char * du type Variable
61  */
62 /*
63  * char *noms_var(i)
64  * int i;
65  * {
66  * char *ch1,*ch2,*ch3;
67  * char c;
68  *
69  * ch1 = (char *) MALLOC (sizeof(char),CHAINE,"noms_var");
70  * ch1[0] = '\0';
71  * while (i>=1) {
72  * ch3=(char *) MALLOC(2*sizeof(char),CHAINE,"noms_var");
73  * c = ((i-1)%27)+ 'a';
74  * ch3[0]=c;
75  * ch3[1]='\0';
76  * ch2 = (char *) MALLOC((unsigned int) ((strlen(ch1)+2) * sizeof(char)),
77  * CHAINE,"noms_var");
78  * (void) strcpy(ch2,ch3);
79  * (void) strcat(ch2,ch1);
80  * ch1 = (char *) MALLOC((unsigned int) ((strlen(ch2) +1)*sizeof(char)),
81  * CHAINE,"noms_var");
82  * (void) strcpy(ch1,ch2);
83  * i = (i - (i%27))/27;
84  *
85  * }
86  * return (ch1);
87  * }
88  */
89 
90 /* Variable creat_new_var(Psysteme ps):
91  * creation d'une nouvelle variable v pour le systeme ps; les champs "base"
92  * et "dimension" sont mis a jour et la nouvelle variable est renvoyee.
93  *
94  * Le nom de la nouvelle variable v est de la forme "Xnnn" ou nnn represente
95  * son rang dans la base "ps->base"
96  *
97  * Auteur: Corinne Ancourt
98  *
99  * Modifications:
100  * - remplacement du champ num_var par le champ base
101  */
103 Psysteme ps;
104 {
105  Variable v;
106  int d;
107  static char name[4];
108 
109  assert(ps != NULL);
110 
111  d = ps->dimension++;
112  assert(0 <= d && d <= 99);
113  name[0] = 'X';
114  (void) sprintf(&name[1],"%d",d);
115  v = variable_make(name);
116  return v;
117 }
118 
119 
120 /* Check if variable var appears in at least on of the constraints in
121  constraint list pc with a non-zero coefficient */
123 Pcontrainte pc;
124 Variable var;
125 {
126  bool find = false;
127  Pcontrainte pc1;
128 
129  for (pc1 = pc; !CONTRAINTE_UNDEFINED_P(pc1) && !find; pc1=pc1->succ)
130  find = find || vect_coeff(var,pc1->vecteur);
131 
132  return (find);
133 }
134 
135 /* bool var_in_sc_p(Psysteme sc, Variable var)
136  * Cette fonction teste si la variable est contrainte par les egalites
137  * ou les inegalites
138 */
139 bool var_in_sc_p(sc,var)
140 Psysteme sc;
141 Variable var;
142 {
143 
144  bool find = false;
145 
146  find = find || var_in_lcontrainte_p(sc->egalites,var)
147  || var_in_lcontrainte_p(sc->inegalites,var);
148 
149  return(find);
150 }
#define CONTRAINTE_UNDEFINED_P(c)
Variable variable_make(char *name)
Variable variable_make(char * name): defines a new variable of a given name.
Definition: variable.c:129
#define assert(ex)
Definition: newgen_assert.h:41
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
bool var_in_lcontrainte_p(Pcontrainte pc, Variable var)
Check if variable var appears in at least on of the constraints in constraint list pc with a non-zero...
Definition: sc_var.c:122
Variable creat_new_var(Psysteme ps)
char * noms_var(int i): cette fonction convertit un numero de variable en chaine de caracteres
Definition: sc_var.c:102
Pvecteur vecteur
struct Scontrainte * succ
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