PIPS
time_sg_union.c
Go to the documentation of this file.
1 /*
2 
3  $Id: time_sg_union.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 
26 #ifdef HAVE_CONFIG_H
27  #include "config.h"
28 #endif
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 extern int fprintf();
33 extern int printf();
34 extern char * strdup();
35 
36 #include "boolean.h"
37 #include "arithmetique.h"
38 #include"linear_assert.h"
39 #include "vecteur.h"
40 #include "contrainte.h"
41 #include "ray_dte.h"
42 #include "sommet.h"
43 #include "sc.h"
44 #include "sg.h"
45 #include "types.h"
46 #include "polyedre.h"
47 
48 
49 
50 
51 main(argc, argv)
52  int argc;
53  char **argv;
54 {
55  FILE * f1;
56  FILE * f2;
57  char * filename = "stdin";
58  Psysteme sc1=sc_new();
59  Psysteme sc2=sc_new();
60  Psysteme sc=sc_new();
61  Ptsg sg = sg_new();
62  Ptsg sg1 = sg_new();
63  Ptsg sg2 = sg_new();
64 
65  if(argc!=3) {
66  fprintf(stdout,"Usage: %s sc1 sc2\n",argv[0]);
67  exit(1);
68  }
69 
70  if((f1 = fopen(argv[1],"r")) == NULL) {
71  fprintf(stdout,"Ouverture du fichier %s impossible\n",
72  argv[1]);
73  exit(4);
74  }
75 
76  if((f2 = fopen(argv[2],"r")) == NULL) {
77  fprintf(stdout,"Ouverture du fichier %s impossible\n",
78  argv[2]);
79  exit(4);
80  }
81 
82  /* lecture du premier systeme */
83  if(sc_fscan(f1,&sc1)) {
84  fprintf(stderr,"syntaxe correcte dans %s\n",argv[1]);
85  sc_fprint(stdout, sc1, *variable_default_name);
86  }
87  else {
88  fprintf(stderr,"erreur de syntaxe dans %s\n",argv[1]);
89  exit(1);
90  }
91 
92  /* lecture du deuxieme systeme */
93  if(sc_fscan(f2,&sc2)) {
94  fprintf(stderr,"syntaxe correcte dans %s\n",argv[2]);
95  sc_fprint(stdout, sc2, *variable_default_name);
96  }
97  else {
98  fprintf(stderr,"erreur de syntaxe dans %s\n",argv[2]);
99  exit(1);
100  }
101 
102  /* Homogeneiser les bases des systemes */
103  assert(vect_size(sc1->base) == vect_size(sc2->base));
104  sc2 = sc_translate(sc2,sc1->base, *variable_default_name);
105 
106  assert(!SC_UNDEFINED_P(sc1) && !SC_UNDEFINED_P(sc2));
107 
108  if (SC_RN_P(sc2) || sc_rn_p(sc2) || sc_dimension(sc2)==0
109  || sc_empty_p(sc1) || !sc_faisabilite(sc1)) {
110  Psysteme sc3 = sc_dup(sc2);
111  sc3 = sc_elim_redond(sc3);
112  sc = (SC_UNDEFINED_P(sc3)) ? sc_empty(base_dup(sc_base(sc2))) : sc3;
113  }
114  else if (SC_RN_P(sc1) ||sc_rn_p(sc1) || sc_dimension(sc1)==0
115  || sc_empty_p(sc2) || !sc_faisabilite(sc2)) {
116  Psysteme sc4 = sc_dup(sc1);
117  sc4 = sc_elim_redond(sc4);
118  sc = (SC_UNDEFINED_P(sc4)) ? sc_empty(base_dup(sc_base(sc1))) : sc4;
119  }
120  else {
121  /* conversion en systemes generateurs */
122  /* printf("systemes initiaux \n");
123  sc_dump(sc1);
124  sc_dump(sc2); */
125  sg1 = sc_to_sg_chernikova(sc1);
126  sg2 = sc_to_sg_chernikova(sc2);
127 
128  /* calcul de l'enveloppe convexe */
129  sg = sg_union(sg1, sg2);
130  /*printf("union des systemes generateurs\n");
131  sg_fprint(stdout,sg,variable_dump_name);
132  */
133  sc = sg_to_sc_chernikova(sg);
134  /* printf("systeme final \n");
135  sc_dump(s); */
136  }
137 
138  printf("systeme correspondant \n");
139  sc_fprint(stdout, sc, *variable_default_name);
140 } /* main */
Psysteme sg_to_sc_chernikova(Ptsg sg)
Definition: chernikova.c:58
Ptsg sc_to_sg_chernikova(Psysteme sc)
chernikova_mulprec.c
Definition: chernikova.c:42
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_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
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
Ptsg sg_new()
Ptsg sg_new(): allocation d'un systeme generateur et initialisation a la valeur ensemble vide.
Definition: sg.c:55
Ptsg sg_union(Ptsg sg1, Ptsg sg2)
Definition: sg.c:552
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
main(int argc, char **argv)
Definition: time_sg_union.c:51
int fprintf()
char * strdup()
int printf()
Pbase base_dup(Pbase b)
Pbase base_dup(Pbase b) Note: this function changes the value of the pointer.
Definition: alloc.c:268