PIPS
sc_cmp.c
Go to the documentation of this file.
1 /*
2 
3  $Id: sc_cmp.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 whether two systems are equivalent
26  */
27 
28 #ifdef HAVE_CONFIG_H
29  #include "config.h"
30 #endif
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include "linear_assert.h"
36 
37 #include "linear.h"
38 
39 /* show how s differs from r */
40 static void show_nredund(const char *msg, Psysteme s, Psysteme r)
41 {
42  fprintf(stdout, "%s specific constraints:\n", msg);
43  for (Pcontrainte c = s->egalites; c; c = c->succ)
44  if (!eq_redund_with_sc_p(r, c))
45  contrainte_fprint(stdout, c, false, *variable_default_name);
46  for (Pcontrainte c = s->inegalites; c; c = c->succ)
47  if (!ineq_redund_with_sc_p(r, c))
48  contrainte_fprint(stdout, c, true, *variable_default_name);
49 }
50 
51 int main(int argc, const char **argv)
52 {
53  if (argc != 3) {
54  fprintf(stderr, "Usage: %s sc1 sc2\n", argv[0]);
55  exit(1);
56  }
57 
58  const char *n1 = argv[1], *n2 = argv[2];
59 
60  // open input files
61  FILE *f1;
62  if ((f1 = fopen(n1,"r")) == NULL) {
63  fprintf(stderr, "cannot open file: %s\n", n1);
64  exit(4);
65  }
66 
67  FILE *f2;
68  if ((f2 = fopen(n2, "r")) == NULL) {
69  fprintf(stderr, "cannot open file: %s\n", n2);
70  exit(4);
71  }
72 
73  Psysteme s1 = sc_new();
74  if (sc_fscan(f1, &s1)) {
75  fprintf(stderr,"file syntax is ok: %s\n", n1);
78  }
79  else {
80  fprintf(stderr, "syntax error in file: %s\n", n1);
81  exit(1);
82  }
83 
84  Psysteme s2 = sc_new();
85  if (sc_fscan(f2, &s2)) {
86  fprintf(stderr,"file syntax is ok: %s\n", n2);
87  sc_fprint(stdout, s2, *variable_default_name);
89  }
90  else {
91  fprintf(stderr, "syntax error in file: %s\n", n2);
92  exit(2);
93  }
94 
95  if (sc_equal_p_ofl(s1, s2))
96  {
97  fprintf(stdout, "%s & %s are equivalent\n", n1, n2);
98  }
99  else
100  {
101  fprintf(stdout, "%s & %s are NOT equivalent\n", n1, n2);
102  if (sc_inclusion_p_ofl(s1, s2))
103  {
104  fprintf(stdout, "%s is strictly included in %s\n", n1, n2);
105  show_nredund(n1, s1, s2);
106  }
107  else if (sc_inclusion_p_ofl(s2, s1))
108  {
109  fprintf(stdout, "%s is strictly included in %s\n", n2, n1);
110  show_nredund(n2, s2, s1);
111  }
112  else
113  {
114  fprintf(stdout, "no inclusion\n");
115  show_nredund(n1, s1, s2);
116  show_nredund(n2, s2, s1);
117  }
118  }
119 
120  return 0;
121 }
void contrainte_fprint(FILE *, Pcontrainte, bool, char *(*)(Variable))
io.c
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
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
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 ineq_redund_with_sc_p(Psysteme sc, Pcontrainte ineq)
This function returns true if the inequation ineq is redundant for the system ps and false otherwise.
bool eq_redund_with_sc_p(Psysteme sc, Pcontrainte eq)
bool eq_redund_with_sc_p(sc, eq) Psysteme sc; Pcontrainte eq;
static void show_nredund(const char *msg, Psysteme s, Psysteme r)
Test whether two systems are equivalent.
Definition: sc_cmp.c:40
int main(int argc, const char **argv)
Definition: sc_cmp.c:51
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 ...
s1
Definition: set.c:247
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
Pcontrainte egalites
Definition: sc-local.h:70
#define sc_inclusion_p_ofl(ps1, ps2)
Definition: union-local.h:81
#define sc_equal_p_ofl(ps1, ps2)
Definition: union-local.h:84