PIPS
sc_insert_eq.c
Go to the documentation of this file.
1 /*
2 
3  $Id: sc_insert_eq.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 
37 /* This function inserts the constraint ineq at the beginning of the
38  * system of inequalities of sc
39  */
40 void insert_ineq_begin_sc(sc,ineq)
41 Psysteme sc;
42 Pcontrainte ineq;
43 {
44  Pcontrainte ineg;
45  ineg = contrainte_dup(ineq);
46  ineg->succ = sc->inegalites;
47  sc->inegalites = ineg;
48  sc->nb_ineq ++;
49 }
50 
51 /* This function inserts two constraints ineq and ineq->succ at the
52  * end of the system of inequalities of sc
53  */
54 void insert_2ineq_end_sc(sc,ineq)
55 Psysteme sc;
56 Pcontrainte ineq;
57 {
58  Pcontrainte pc;
59 
60  if (CONTRAINTE_UNDEFINED_P(sc->inegalites)){
61  sc->inegalites=contrainte_dup(ineq);
62  (sc->inegalites)->succ = contrainte_dup(ineq->succ);
63  }
64  else {
65  for (pc = sc->inegalites;
67  pc=pc->succ);
68  pc->succ = contrainte_dup(ineq);
69  pc = pc->succ;
70  pc->succ = contrainte_dup(ineq->succ);
71  }
72  sc->nb_ineq +=2;
73 }
74 
75 
76 
77 /* This function inserts one constraint ineq at the
78  * end of the system of inequalities of sc
79 */
80 
81 void insert_ineq_end_sc(sc,ineq)
82 Psysteme sc;
83 Pcontrainte ineq;
84 {
85  Pcontrainte pc;
86 
87  if (CONTRAINTE_UNDEFINED_P(sc->inegalites)){
88  sc->inegalites=contrainte_dup(ineq);
89  }
90  else {
91  for (pc = sc->inegalites;
93  pc=pc->succ);
94  pc->succ = contrainte_dup(ineq);
95  }
96  sc->nb_ineq ++;
97 }
98 ␌
99 /* The basis of the constraint system is updated. If not, see sc_add_egalite() */
100 Psysteme
102 {
103  sc = sc_constraint_add(sc, c, true);
104  return sc;
105 }
106 
107 Psysteme
109 {
110  sc = sc_constraint_add(sc, c, false);
111  return sc;
112 }
113 
114 Psysteme
116 {
117  Pbase old_basis;
118  Pbase new_basis;
119 
120  if(equality)
121  sc_add_egalite(sc,c);
122  else
123  sc_add_inegalite(sc,c);
124 
125  /* maintain consistency, although it's expensive; how about a
126  sc_update_base function? Or a proper sc_add_inegalite function? */
127  old_basis = sc->base;
128  sc->base = (Pbase) VECTEUR_NUL;
129  sc_creer_base(sc);
130  new_basis = sc->base;
131  sc->base = base_union(old_basis, new_basis);
132  sc->dimension = base_dimension(sc->base);
133  base_rm(new_basis);
134  base_rm(old_basis);
135 
136  return sc;
137 }
Pbase base_union(Pbase b1, Pbase b2)
Pbase base_union(Pbase b1, Pbase b2): compute a new basis containing all elements of b1 and all eleme...
Definition: base.c:428
#define CONTRAINTE_UNDEFINED_P(c)
Pcontrainte contrainte_dup(Pcontrainte c_in)
Pcontrainte contrainte_dup(Pcontrainte c_in): allocation d'une contrainte c_out prenant la valeur de ...
Definition: alloc.c:132
void sc_creer_base(Psysteme ps)
void sc_creer_base(Psysteme ps): initialisation des parametres dimension et base d'un systeme lineair...
Definition: sc_alloc.c:129
void sc_add_egalite(Psysteme p, Pcontrainte e)
void sc_add_egalite(Psysteme p, Pcontrainte e): macro ajoutant une egalite e a un systeme p; la base ...
Definition: sc_alloc.c:389
void sc_add_inegalite(Psysteme p, Pcontrainte i)
void sc_add_inegalite(Psysteme p, Pcontrainte i): macro ajoutant une inegalite i a un systeme p; la b...
Definition: sc_alloc.c:406
Psysteme sc_inequality_add(Psysteme sc, Pcontrainte c)
Definition: sc_insert_eq.c:108
Psysteme sc_equation_add(Psysteme sc, Pcontrainte c)
The basis of the constraint system is updated.
Definition: sc_insert_eq.c:101
void insert_ineq_end_sc(Psysteme sc, Pcontrainte ineq)
This function inserts one constraint ineq at the end of the system of inequalities of sc.
Definition: sc_insert_eq.c:81
void insert_ineq_begin_sc(Psysteme sc, Pcontrainte ineq)
This function inserts the constraint ineq at the beginning of the system of inequalities of sc.
Definition: sc_insert_eq.c:40
void insert_2ineq_end_sc(Psysteme sc, Pcontrainte ineq)
This function inserts two constraints ineq and ineq->succ at the end of the system of inequalities of...
Definition: sc_insert_eq.c:54
Psysteme sc_constraint_add(Psysteme sc, Pcontrainte c, bool equality)
Definition: sc_insert_eq.c:115
struct Scontrainte * succ
Pbase base
Definition: sc-local.h:75
int dimension
Definition: sc-local.h:74
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
struct Svecteur * Pbase
#define base_rm(b)
#define base_dimension(b)