PIPS
sc_env.c
Go to the documentation of this file.
1 /*
2 
3  $Id: sc_env.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  /* Test de l'enveloppe convexe de deux systemes. L'enveloppe convexe
26  * est faite par traduction des systemes lineaires en systemes
27  * generateurs (par chernikova), puis par union des systemes
28  * generateurs, enfin par la traduction du systeme generateur
29  * resultant en systeme lineaire (toujours par chernikovva). Cette
30  * fonction utilise la bibliotheque fournie par l'IRISA. On suppose
31  * que les deux systemes fournis en entree ont la meme base
32  */
33 
34 #ifdef HAVE_CONFIG_H
35  #include "config.h"
36 #endif
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include "linear_assert.h"
42 
43 #include "boolean.h"
44 #include "arithmetique.h"
45 #include "matrix.h"
46 #include "vecteur.h"
47 #include "contrainte.h"
48 #include "ray_dte.h"
49 #include "sommet.h"
50 #include "sc.h"
51 #include "sg.h"
52 #include "polyedre.h"
53 
54 
55 main(argc, argv)
56  int argc;
57  char **argv;
58 {
59  FILE * f1;
60  FILE * f2;
61  char * filename = "stdin";
62  Psysteme s1=sc_new();
63  Psysteme s2=sc_new();
64  Psysteme s=sc_new();
65  Ptsg sg = sg_new();
66  Ptsg sg1,sg2 ;
67  Matrix *a;
68  Polyhedron *A;
69  if(argc!=3) {
70  fprintf(stdout,"Usage: %s sc1 sc2\n",argv[0]);
71  exit(1);
72  }
73 
74  if((f1 = fopen(argv[1],"r")) == NULL) {
75  fprintf(stdout,"Ouverture du fichier %s impossible\n",
76  argv[1]);
77  exit(4);
78  }
79 
80  if((f2 = fopen(argv[2],"r")) == NULL) {
81  fprintf(stdout,"Ouverture du fichier %s impossible\n",
82  argv[2]);
83  exit(4);
84  }
85 
86  /* lecture du premier systeme */
87  if(sc_fscan(f1,&s1)) {
88  fprintf(stderr,"syntaxe correcte dans %s\n",argv[1]);
91 
92  }
93  else {
94  fprintf(stderr,"erreur de syntaxe dans %s\n",argv[1]);
95  exit(1);
96  }
97 
98 
99  /* lecture du deuxieme systeme */
100  if(sc_fscan(f2,&s2)) {
101  fprintf(stderr,"syntaxe correcte dans %s\n",argv[2]);
102  sc_fprint(stdout, s2, *variable_default_name);
104  }
105  else {
106  fprintf(stderr,"erreur de syntaxe dans %s\n",argv[2]);
107  exit(1);
108  }
109 
110  /* FI: commented out because prevents tests with empty systems */
111  /*
112  s1 = sc_normalize(s1);
113  s2 = sc_normalize(s2);
114  sc_fprint(stdout, s1, *variable_default_name);
115  sc_fprint(stdout, s2, *variable_default_name);
116  */
117 
118  assert(vect_size(s1->base) == vect_size(s2->base));
119 
120  s2 = sc_translate(s2,s1->base, *variable_default_name);
121  if (SC_RN_P(s2) || sc_rn_p(s2) || sc_dimension(s2)==0
122  || sc_empty_p(s1) || !sc_faisabilite_ofl(s1)) {
123  Psysteme sc2 = sc_dup(s2);
124  sc2 = sc_elim_redond(sc2);
125  s = (SC_UNDEFINED_P(sc2)) ? sc_empty(base_dup(sc_base(s2))) : sc2;
126  }
127  else if (SC_RN_P(s1) ||sc_rn_p(s1) || sc_dimension(s1)==0
128  || sc_empty_p(s2) || !sc_faisabilite_ofl(s2)) {
129  Psysteme sc1 = sc_dup(s1);
130  sc1 = sc_elim_redond(sc1);
131  s = (SC_UNDEFINED_P(sc1)) ? sc_empty(base_dup(sc_base(s1))) : sc1;
132  }
133  else {
134  /* calcul de l'enveloppe convexe */
135  /* s = sc_new(); */
136  /* s = sc_convex_hull(s1,s2); */
137  s = sc_common_projection_convex_hull(s1,s2);
138  }
139 
140  printf("systeme correspondant \n");
141  sc_fprint(stdout, s, *variable_default_name);
142  exit(0);
143 } /* main */
#define A(i, j)
comp_matrice.c
Definition: comp_matrice.c:63
Ptsg sg
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
char * variable_default_name(Variable v)
char * variable_default_name(Variable v): returns the name of variable v
Definition: variable.c:81
#define exit(code)
Definition: misc-local.h:54
#define assert(ex)
Definition: newgen_assert.h:41
int f2(int off1, int off2, int w, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:1
Psysteme sc_translate(Psysteme s, Pbase b, char *(*variable_name)())
Psysteme sc_translate(Psysteme s, Pbase b, char * (*variable_name)()): reecriture du systeme s dans l...
Definition: sc.c:99
bool sc_weak_consistent_p(Psysteme sc)
check that sc is well defined, that the numbers of equalities and inequalities are consistent with th...
Definition: sc.c:362
bool sc_rn_p(Psysteme sc)
bool sc_rn_p(Psysteme sc): check if the set associated to sc is the whole space, rn
Definition: sc_alloc.c:369
Psysteme sc_empty(Pbase b)
Psysteme sc_empty(Pbase b): build a Psysteme with one unfeasible constraint to define the empty subsp...
Definition: sc_alloc.c:319
Psysteme sc_new(void)
Psysteme sc_new(): alloue un systeme vide, initialise tous les champs avec des valeurs nulles,...
Definition: sc_alloc.c:55
bool sc_empty_p(Psysteme sc)
bool sc_empty_p(Psysteme sc): check if the set associated to sc is the constant sc_empty or not.
Definition: sc_alloc.c:350
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
main(int argc, char **argv)
Test de l'enveloppe convexe de deux systemes.
Definition: sc_env.c:55
void sc_fprint(FILE *fp, Psysteme ps, get_variable_name_t nom_var)
void sc_fprint(FILE * f, Psysteme ps, char * (*nom_var)()): cette fonction imprime dans le fichier po...
Definition: sc_io.c:220
bool sc_fscan(FILE *f, Psysteme *ps)
bool sc_fscan(FILE * f, Psysteme * ps): construit un systeme d'inegalites et d'egalites lineaires a p...
Definition: sc_io.c:121
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
int printf()
s1
Definition: set.c:247
Ptsg sg_new()
Ptsg sg_new(): allocation d'un systeme generateur et initialisation a la valeur ensemble vide.
Definition: sg.c:55
Pbase base
Definition: sc-local.h:75
Representation d'un systeme generateur par trois ensembles de sommets de rayons et de droites.
Definition: sg-local.h:66
Pbase base_dup(Pbase b)
Pbase base_dup(Pbase b) Note: this function changes the value of the pointer.
Definition: alloc.c:268