PIPS
sc_proj.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "linear_assert.h"
#include <getopt.h>
#include "arithmetique.h"
#include "vecteur.h"
#include "contrainte.h"
#include "sc.h"
+ Include dependency graph for sc_proj.c:

Go to the source code of this file.

Functions

char * sc_internal_symbol_table (char *)
 
int main (int argc, char *const argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *const  argv[] 
)

Definition at line 37 of file sc_proj.c.

38 {
39  // option management
40  bool reverse = false, bound = false;
41  int debug = 0, opt;
42  while ((opt = getopt(argc, argv, "bhrD")) != -1) {
43  switch (opt) {
44  case 'r': reverse = true; break;
45  case 'b': bound = true; break;
46  case 'D': debug++; break;
47  case 'h':
48  fprintf(stdout,
49  "usage: %s [-r or -b] variables... < system\n"
50  "\tdefault: project listed variables\n"
51  "\t-r: project all but the listed variables\n"
52  "\t-b: show bounds on listed variables\n",
53  argv[0]);
54  exit(0);
55  default: exit(1);
56  }
57  }
58  // only one of -r and -b
59  assert(!(reverse && bound));
60 
61  // get system from stdin
62  Psysteme s;
63  bool ok = sc_fscan(stdin, &s);
64  assert(ok);
65  if (debug >= 2) sc_fprint(stderr, s, *variable_default_name);
66 
67  // get command arguments as a base
68  Pbase arg_base = BASE_NULLE;
69  for (int i = optind; i < argc; i++)
70  arg_base = base_add_variable(arg_base, sc_internal_symbol_table(argv[i]));
71 
72  Pbase proj_base;
73  if (reverse || bound) {
74  proj_base = vect_copy(sc_base(s));
75  for (Pbase b = arg_base; b != BASE_NULLE; b = vecteur_succ(b))
76  proj_base = base_remove_variable(proj_base, vecteur_var(b));
77  }
78  else {
79  proj_base = vect_copy(arg_base);
80  }
81 
82  // project all "proj_base" variables
83  for (Pbase b = proj_base; b != BASE_NULLE; b = vecteur_succ(b))
84  s = sc_projection(s, vecteur_var(b));
85 
86  // cleanup
87  sc_nredund(&s);
88 
89  if (debug) sc_fprint(stderr, s, *variable_default_name);
90 
91  // print out result
92  if (bound) {
93  // we must bound each remaining variables
94  for (Pbase b = arg_base; b != BASE_NULLE; b = vecteur_succ(b)) {
96  Psysteme sb = sc_copy(s);
97  // YES, we use *s* base
98  for (Pbase c = sc_base(s); c != BASE_NULLE; c = vecteur_succ(c)) {
99  if (vecteur_var(c) != keep)
100  sb = sc_projection(sb, vecteur_var(c));
101  }
102  sc_nredund(&sb);
104  sc_rm(sb);
105  }
106  }
107  else
108  sc_fprint(stdout, s, *variable_default_name);
109 
110  base_rm(arg_base);
111  base_rm(proj_base);
112  sc_rm(s);
113  return 0;
114 }
Pbase base_add_variable(Pbase b, Variable var)
Pbase base_add_variable(Pbase b, Variable v): add variable v as a new dimension to basis b at the end...
Definition: base.c:88
Pbase base_remove_variable(Pbase b, Variable v)
Pbase base_remove_variable(b, v): remove basis vector relative to v from b; abort if v is not in b;.
Definition: base.c:122
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
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
#define assert(ex)
Definition: newgen_assert.h:41
void sc_rm(Psysteme ps)
void sc_rm(Psysteme ps): liberation de l'espace memoire occupe par le systeme de contraintes ps;
Definition: sc_alloc.c:277
Psysteme sc_copy(Psysteme ps)
Psysteme sc_copy(Psysteme ps): duplication d'un systeme (allocation et copie complete des champs sans...
Definition: sc_alloc.c:230
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 ...
char * sc_internal_symbol_table(char *)
static bool ok
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
Definition: statement.c:4047
int optind
@ keep
bj > b1 -> h1/hj = h1
Definition: union-local.h:61
#define vecteur_var(v)
#define vecteur_succ(v)
#define base_rm(b)
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
#define BASE_NULLE
MACROS SUR LES BASES.
Pbase vect_copy(Pvecteur b)
direct duplication.
Definition: alloc.c:240

References assert, base_add_variable(), BASE_NULLE, base_remove_variable(), base_rm, debug(), exit, fprintf(), keep, ok, optind, sc_copy(), sc_fprint(), sc_fscan(), sc_internal_symbol_table(), sc_rm(), variable_default_name(), vect_copy(), vecteur_succ, and vecteur_var.

+ Here is the call graph for this function:

◆ sc_internal_symbol_table()

char* sc_internal_symbol_table ( char *  )

Referenced by main().

+ Here is the caller graph for this function: