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

Go to the source code of this file.

Data Structures

struct  sort_ctx_t
 package sc More...
 

Macros

#define ADD_COST   (1)
 
#define MUL_COST   (1)
 
#define AFF_COST   (1)
 
#define DB_RESULT(e)
 for qsort, returns "is simpler than" More...
 
#define RESULT(e)   { return (e); }
 
#define RETURN_HARDER(b)   RESULT(context->complex_first ? (b) : -(b))
 
#define RETURN_ORDER(b)   RESULT(context->inner_first ? (b) : -(b))
 
#define same_sign_p(v, w)    ((value_neg_p(v) && value_neg_p(w)) || (value_pos_p(v) && value_pos_p(w)))
 

Functions

static void set_sort_context (sort_ctx_t *context, Pbase base, Pbase sort_base, bool inner_first, bool complex_first)
 
static void clear_sort_context (sort_ctx_t *context)
 
static int cost_of_constant_operations (Pvecteur v, sort_ctx_t *context)
 
static int compare_the_constraints (const Pcontrainte *pc1, const Pcontrainte *pc2, sort_ctx_t *context)
 compare two constraints with a loop complexity cost in mind? not exactly, some of the choices attempt to avoid large coefs? More...
 
Pvecteur highest_rank_pvector (Pvecteur v, Pbase b, int *prank)
 returns the highest rank pvector of v in b, of rank *prank More...
 
static Pcontrainte constraints_sort_info (Pcontrainte c, Pbase sort_base, constraint_cmp_func_t compare, void *context, two_int_infop info)
 sorts the constraints according to the compare function, and set the number of constraints for each index of the sort base More...
 
Pcontrainte constraints_sort_with_compare (Pcontrainte c, Pbase sort_base, constraint_cmp_func_t compare, void *context)
 
Pcontrainte contrainte_sort (Pcontrainte c, Pbase base, Pbase sort_base, bool inner_first, bool complex_first)
 
Psysteme sc_sort_constraints (Psysteme ps, Pbase base_index)
 
Psysteme sc_triang_elim_redund (Psysteme ps, Pbase base_index)
 sort contrainte c, base b, relatively to sort_base, as defined by the switches. More...
 
void move_n_first_constraints (Pcontrainte *source, Pcontrainte *target, int n)
 void move_n_first_constraints(source, target, n) Pcontrainte *source, *target; int n; More...
 
void sc_triang_elim_redund_n_first (Psysteme s, int n)
 void sc_triang_elim_redund_n_first(s, n) Psysteme s; int n; More...
 
Psysteme sc_build_triang_elim_redund (Psysteme s, Pbase indexes)
 outer to inner More...
 
Psysteme sc_sort_constraints_simplest_first (Psysteme ps, Pbase base_index)
 

Macro Definition Documentation

◆ ADD_COST

#define ADD_COST   (1)

Definition at line 77 of file sc_triang_elim_redond.c.

◆ AFF_COST

#define AFF_COST   (1)

Definition at line 79 of file sc_triang_elim_redond.c.

◆ DB_RESULT

#define DB_RESULT (   e)
Value:
{ \
int result = (e); \
fprintf(stderr, "[compare_the_constraints]\n"); \
vect_debug(v1); vect_debug(v2); \
fprintf(stderr, "%s\n", result==0 ? "=" : (result>0 ? ">" : "<")); \
return(result); \
}
void vect_debug(Pvecteur v)
constraint.c
Definition: constraint.c:43

for qsort, returns "is simpler than"

  • : v1 < v2 0 : v1==v2
  • : v1 > v2

with the following criterion

1/ ranks 2/ coef of comparable ranks, +-1 or simpler... 3/

rational:

  • loop sizes are assumed to be infinite
  • invariant code motion
  • induction variables recognized

Definition at line 120 of file sc_triang_elim_redond.c.

◆ MUL_COST

#define MUL_COST   (1)

Definition at line 78 of file sc_triang_elim_redond.c.

◆ RESULT

#define RESULT (   e)    { return (e); }

Definition at line 129 of file sc_triang_elim_redond.c.

◆ RETURN_HARDER

#define RETURN_HARDER (   b)    RESULT(context->complex_first ? (b) : -(b))

Definition at line 131 of file sc_triang_elim_redond.c.

◆ RETURN_ORDER

#define RETURN_ORDER (   b)    RESULT(context->inner_first ? (b) : -(b))

Definition at line 132 of file sc_triang_elim_redond.c.

◆ same_sign_p

#define same_sign_p (   v,
 
)     ((value_neg_p(v) && value_neg_p(w)) || (value_pos_p(v) && value_pos_p(w)))

Definition at line 134 of file sc_triang_elim_redond.c.

Function Documentation

◆ clear_sort_context()

static void clear_sort_context ( sort_ctx_t context)
static

Definition at line 70 of file sc_triang_elim_redond.c.

71 {
72  assert(context != NULL);
73  base_rm(context->rbase), context->rbase = BASE_NULLE;
74  base_rm(context->others), context->others = BASE_NULLE;
75 }
#define assert(ex)
Definition: newgen_assert.h:41
Definition: delay.c:253
#define base_rm(b)
#define BASE_NULLE
MACROS SUR LES BASES.

References assert, BASE_NULLE, and base_rm.

Referenced by contrainte_sort(), sc_build_triang_elim_redund(), and sc_triang_elim_redund().

+ Here is the caller graph for this function:

◆ compare_the_constraints()

static int compare_the_constraints ( const Pcontrainte pc1,
const Pcontrainte pc2,
sort_ctx_t context 
)
static

compare two constraints with a loop complexity cost in mind? not exactly, some of the choices attempt to avoid large coefs?

returns -1: c1<c2, 0: c1==c2, +1: c1>c2

Definition at line 142 of file sc_triang_elim_redond.c.

146 {
147  Pvecteur v1 = (*pc1)->vecteur, v2 = (*pc2)->vecteur;
148  bool null_1, null_2;
149  int i, irank = 0, cost_1, cost_2;
150  Value val_1 = VALUE_ZERO, val_2 = VALUE_ZERO,
151  val = VALUE_ZERO, val_p = VALUE_ZERO;
152  Pbase b, high = NULL;
153 
154  // for each inner first indexes, the first constraint with a null coeff
155  // while the other one is not is the simplest
156  for (i=1, b=context->rbase; !BASE_NULLE_P(b); i++, b=b->succ)
157  {
158  val_1 = vect_coeff(var_of(b), v1);
159  null_1 = value_zero_p(val_1);
160  val_2 = vect_coeff(var_of(b), v2);
161  null_2 = value_zero_p(val_2);
162 
163  // first loop index with something
164  // BUG too early
165  if (irank == 0 && !same_sign_p(val_1, val_2))
166  // BUG: condition is always false?
167  RETURN_ORDER(value_neg_p(val_1) && value_neg_p(val_2) ?
168  value_compare(val_2, val_1):
169  value_compare(val_1 ,val_2));
170 
171  // *one* coef is zero and the other *not*, we can conclude
172  if (null_1 ^ null_2)
173  {
174  if (irank == 0) // ???
175  { RETURN_ORDER(value_compare(null_1, null_2)); }
176  else
177  { RETURN_HARDER(value_compare(null_1, null_2)); }
178  }
179 
180  // keep track of first inner loop with non zero values?
181  if (irank == 0 && (!null_1 || !null_2))
182  val=val_1, val_p=val_2, irank=i, high=b;
183  }
184 
185  // BUG?
186  // why conclude now on these values, and not on the cost below first?
187  if (value_ne(val_p, val))
188  RETURN_HARDER(value_neg_p(val_1) && value_neg_p(val_2) ?
189  value_compare(val_2, val_1):
190  value_compare(val_1, val_2));
191 
192  // constant operations
193  cost_1 = cost_of_constant_operations(v1, context);
194  cost_2 = cost_of_constant_operations(v2, context);
195 
196  if (cost_1 != cost_2) RETURN_HARDER(cost_2-cost_1);
197 
198  // the depth & cost are equal, we need another criterion base on values
199  // compare the coefficients for the base, starting from the first after
200  // the first non null.
201  for (b=high==NULL ? NULL : high->succ; !BASE_NULLE_P(b); b=b->succ)
202  {
203  val_1 = vect_coeff(var_of(b), v1);
204  val_2 = vect_coeff(var_of(b), v2);
205 
206  if (value_ne(val_1, val_2))
207  RETURN_HARDER(value_neg_p(val_1) && value_neg_p(val_2)?
208  value_compare(val_1, val_2):
209  value_compare(val_2, val_1));
210  }
211 
212  // all equals, do it for the for the parameters
213  for (b=context->others; !BASE_NULLE_P(b); b=b->succ)
214  {
215  val_1 = vect_coeff(var_of(b), v1);
216  val_2 = vect_coeff(var_of(b), v2);
217 
218  if (value_ne(val_1, val_2))
219  RETURN_HARDER(value_compare(val_2,val_1));
220  }
221 
222  // at last the constant
223  val_1 = vect_coeff(TCST, v1);
224  val_2 = vect_coeff(TCST, v2);
225 
226  // the sign is needed so that equalities are normalized...
227  // here we have val==val_p
229  value_compare(val_2, val_1):
230  value_compare(val_1, val_2));
231 }
#define value_pos_p(val)
#define VALUE_ZERO
#define value_ne(v1, v2)
#define value_zero_p(val)
#define value_compare(v1, v2)
int Value
#define value_neg_p(val)
#define same_sign_p(v, w)
#define RETURN_HARDER(b)
#define RETURN_ORDER(b)
static int cost_of_constant_operations(Pvecteur v, sort_ctx_t *context)
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
struct Svecteur * succ
Definition: vecteur-local.h:92
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define var_of(varval)
#define BASE_NULLE_P(b)
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228

References BASE_NULLE_P, cost_of_constant_operations(), RETURN_HARDER, RETURN_ORDER, same_sign_p, Svecteur::succ, TCST, value_compare, value_ne, value_neg_p, value_pos_p, VALUE_ZERO, value_zero_p, var_of, and vect_coeff().

Referenced by contrainte_sort(), sc_build_triang_elim_redund(), and sc_triang_elim_redund().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constraints_sort_info()

static Pcontrainte constraints_sort_info ( Pcontrainte  c,
Pbase  sort_base,
constraint_cmp_func_t  compare,
void *  context,
two_int_infop  info 
)
static

sorts the constraints according to the compare function, and set the number of constraints for each index of the sort base

the constraints are put in the table and info is set.

the list of constraints is generated again

clean!

Definition at line 275 of file sc_triang_elim_redond.c.

281 {
282  Pcontrainte pc, *tc;
283  Pvecteur phrank;
284  int i, rank,
285  nb_of_sort_vars = vect_size(sort_base),
286  nb_of_constraints = nb_elems_list(c);
287 
288  if (nb_of_constraints<=1) return c;
289 
290  tc = (Pcontrainte*) malloc(sizeof(Pcontrainte)*nb_of_constraints);
291 
292  for (i=0; i<=nb_of_sort_vars; i++)
293  info[i][0]=0, info[i][1]=0;
294 
295  /* the constraints are put in the table
296  * and info is set.
297  */
298  for (i=0, pc=c; pc!=NULL; i++, pc=pc->succ)
299  {
300  tc[i] = pc;
301  if (!BASE_NULLE_P(sort_base))
302  {
303  phrank = highest_rank_pvector(pc->vecteur, sort_base, &rank);
304  info[rank==-1?0:rank][rank==-1?0:value_pos_p(val_of(phrank))]++;
305  }
306  }
307 
308  qsort_r(tc, nb_of_constraints, sizeof(Pcontrainte),
309  (int(*)(const void *,const void *, void *)) compare,
310  (void *) context);
311 
312  /* the list of constraints is generated again
313  */
314  for (i=0; i<nb_of_constraints-1; i++)
315  {
316  tc[i]->succ = tc[i+1];
317  }
318  tc[nb_of_constraints-1]->succ=NULL;
319  c = tc[0];
320 
321  /* clean!
322  */
323  free(tc);
324  return c;
325 }
int nb_elems_list(Pcontrainte)
int nb_elems_list(Pcontrainte list): nombre de contraintes se trouvant dans une liste de contraintes
Definition: listes.c:129
void * malloc(YYSIZE_T)
void free(void *)
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
static entity rank
char * info(char *about)
Definition: pypips.c:278
static int tc
Internal variables
Definition: reindexing.c:107
Pvecteur highest_rank_pvector(Pvecteur v, Pbase b, int *prank)
returns the highest rank pvector of v in b, of rank *prank
struct Scontrainte * succ
#define val_of(varval)

References BASE_NULLE_P, free(), highest_rank_pvector(), info(), malloc(), nb_elems_list(), rank, Scontrainte::succ, tc, val_of, value_pos_p, vect_size(), and Scontrainte::vecteur.

Referenced by constraints_sort_with_compare(), sc_build_triang_elim_redund(), and sc_triang_elim_redund().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constraints_sort_with_compare()

Pcontrainte constraints_sort_with_compare ( Pcontrainte  c,
Pbase  sort_base,
constraint_cmp_func_t  compare,
void *  context 
)

Definition at line 327 of file sc_triang_elim_redond.c.

332 {
333  int n = vect_size(sort_base)+1;
334  two_int_infop info;
335 
336  info = (two_int_infop) malloc(sizeof(two_int_info)*n);
337 
338  c = constraints_sort_info(c, sort_base, compare, context, info);
339 
340  free(info);
341  return c;
342 }
static Pcontrainte constraints_sort_info(Pcontrainte c, Pbase sort_base, constraint_cmp_func_t compare, void *context, two_int_infop info)
sorts the constraints according to the compare function, and set the number of constraints for each i...

References constraints_sort_info(), free(), info(), malloc(), and vect_size().

Referenced by contrainte_sort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ contrainte_sort()

Pcontrainte contrainte_sort ( Pcontrainte  c,
Pbase  base,
Pbase  sort_base,
bool  inner_first,
bool  complex_first 
)

Definition at line 344 of file sc_triang_elim_redond.c.

350 {
352  set_sort_context(&context, base, sort_base, inner_first, complex_first);
354  (c, sort_base, (constraint_cmp_func_t) compare_the_constraints, &context);
356  return c;
357 }
bdt base
Current expression.
Definition: bdt_read_paf.c:100
static void set_sort_context(sort_ctx_t *context, Pbase base, Pbase sort_base, bool inner_first, bool complex_first)
static int compare_the_constraints(const Pcontrainte *pc1, const Pcontrainte *pc2, sort_ctx_t *context)
compare two constraints with a loop complexity cost in mind? not exactly, some of the choices attempt...
Pcontrainte constraints_sort_with_compare(Pcontrainte c, Pbase sort_base, constraint_cmp_func_t compare, void *context)
static void clear_sort_context(sort_ctx_t *context)

References base, clear_sort_context(), compare_the_constraints(), constraints_sort_with_compare(), and set_sort_context().

Referenced by movement_computation(), sc_sort(), sc_sort_constraints(), and sc_sort_constraints_simplest_first().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cost_of_constant_operations()

static int cost_of_constant_operations ( Pvecteur  v,
sort_ctx_t context 
)
static

Definition at line 80 of file sc_triang_elim_redond.c.

81 {
82  int cost = AFF_COST;
83  Pbase b;
84  Value val;
85 
86  // constant
88  cost += ADD_COST;
89 
90  // other variables
91  for (b=context->others; b!=(Pvecteur)NULL; b=b->succ)
92  {
93  val = vect_coeff(var_of(b), v);
94  val = value_abs(val);
95 
96  if (value_notzero_p(val))
97  cost+=value_one_p(val)? ADD_COST: (MUL_COST+ADD_COST);
98  }
99 
100  return cost;
101 }
#define value_notzero_p(val)
#define value_one_p(val)
#define value_abs(val)
#define AFF_COST
#define MUL_COST
#define ADD_COST

References ADD_COST, AFF_COST, MUL_COST, Svecteur::succ, TCST, value_abs, value_notzero_p, value_one_p, var_of, and vect_coeff().

Referenced by compare_the_constraints().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ highest_rank_pvector()

Pvecteur highest_rank_pvector ( Pvecteur  v,
Pbase  b,
int prank 
)

returns the highest rank pvector of v in b, of rank *prank

Definition at line 246 of file sc_triang_elim_redond.c.

247 {
248  Pbase pb;
249  Pvecteur pv, result=(Pvecteur) NULL;
250  Variable var;
251  int rank;
252 
253  for (*prank=-1, rank=1, pb=b;
254  !BASE_NULLE_P(pb);
255  pb=pb->succ, rank++)
256  {
257  var = var_of(pb);
258 
259  for (pv=v; pv!=NULL; pv=pv->succ)
260  if (var_of(pv)==var)
261  {
262  result=pv;
263  *prank=rank;
264  continue;
265  }
266  }
267 
268  return result;
269 }
struct Svecteur * Pvecteur
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

References BASE_NULLE_P, rank, Svecteur::succ, and var_of.

Referenced by constraints_sort_info().

+ Here is the caller graph for this function:

◆ move_n_first_constraints()

void move_n_first_constraints ( Pcontrainte source,
Pcontrainte target,
int  n 
)

void move_n_first_constraints(source, target, n) Pcontrainte *source, *target; int n;

moves the n first constraints from source to target, in order.

nothing to be done

nth points to the nth constraint.

Definition at line 498 of file sc_triang_elim_redond.c.

499 {
500  Pcontrainte tmp, nth;
501 
502  if (n==0) return; /* nothing to be done */
503 
504  /* nth points to the nth constraint.
505  */
506  for (nth=*source; n>1; n--, nth=nth->succ);
507 
508  tmp = *target, *target = *source, *source = nth->succ, nth->succ = tmp;
509 }

References Scontrainte::succ.

Referenced by sc_build_triang_elim_redund().

+ Here is the caller graph for this function:

◆ sc_build_triang_elim_redund()

Psysteme sc_build_triang_elim_redund ( Psysteme  s,
Pbase  indexes 
)

outer to inner

sort outer first and complex first

remove the redundancy on others then triangular clean of what remains.

what if s is empty or null ???

build the non redundant triangular system for each level and side.

clean!

Definition at line 541 of file sc_triang_elim_redond.c.

544 {
545  Pcontrainte old;
546  int level, side, n_other_constraints, n = vect_size(indexes)+1;
547  two_int_infop info;
549 
550  s = sc_normalize(s);
551  if (s==NULL || sc_nbre_inegalites(s)==0) return s;
552 
553  info = (two_int_infop) malloc(sizeof(int)*2*n);
554 
555  /* sort outer first and complex first
556  */
557  set_sort_context(&context, s->base, indexes, false, true);
558  s->inegalites =
559  constraints_sort_info(s->inegalites, indexes,
560  (constraint_cmp_func_t) compare_the_constraints,
561  &context, info);
563 
564  /* remove the redundancy on others
565  * then triangular clean of what remains.
566  */
567 
568  n_other_constraints = info[0][0]+info[0][1];
569  old = sc_inegalites(s), sc_inegalites(s) = NULL, sc_nbre_inegalites(s) = 0;
570 
571  move_n_first_constraints(&old, &s->inegalites, n_other_constraints);
572  sc_nbre_inegalites(s) = n_other_constraints;
573  s = sc_elim_redund(s);
574 
575  /* what if s is empty or null ???
576  */
577 
578  /* build the non redundant triangular system for each level and side.
579  */
580  for (level=1; level<n; level++)
581  {
582  for (side=0; side<=1; side++)
583  if (info[level][side])
584  {
585  move_n_first_constraints(&old, &sc_inegalites(s), info[level][side]);
586  sc_nbre_inegalites(s)+=info[level][side];
588  }
589  }
590 
591  assert(old==NULL);
592 
593  /* clean!
594  */
596  s = sc_kill_db_eg(s);
597  free(info);
598 
599  return s;
600 }
Psysteme sc_kill_db_eg(Psysteme ps)
Psysteme sc_kill_db_eg(Psysteme ps): elimination des egalites et des inegalites identiques ou inutile...
Definition: sc_elim_eq.c:133
Psysteme sc_elim_redund(Psysteme ps)
Psysteme sc_elim_redund(Psysteme ps): elimination des contraintes lineaires redondantes dans le syste...
void sc_elim_empty_constraints(Psysteme ps, bool process_equalities)
void sc_elim_empty_constraints(Psysteme ps, bool process_equalities): elimination des "fausses" contr...
#define level
Psysteme sc_normalize(Psysteme ps)
Psysteme sc_normalize(Psysteme ps): normalisation d'un systeme d'equation et d'inequations lineaires ...
void sc_triang_elim_redund_n_first(Psysteme s, int n)
void sc_triang_elim_redund_n_first(s, n) Psysteme s; int n;
void move_n_first_constraints(Pcontrainte *source, Pcontrainte *target, int n)
void move_n_first_constraints(source, target, n) Pcontrainte *source, *target; int n;
Pcontrainte inegalites
Definition: sc-local.h:71
Pbase base
Definition: sc-local.h:75

References assert, Ssysteme::base, clear_sort_context(), compare_the_constraints(), constraints_sort_info(), free(), Ssysteme::inegalites, info(), level, malloc(), move_n_first_constraints(), sc_elim_empty_constraints(), sc_elim_redund(), sc_kill_db_eg(), sc_normalize(), sc_triang_elim_redund_n_first(), set_sort_context(), and vect_size().

+ Here is the call graph for this function:

◆ sc_sort_constraints()

Psysteme sc_sort_constraints ( Psysteme  ps,
Pbase  base_index 
)

Definition at line 359 of file sc_triang_elim_redond.c.

360 {
361  // equalities???
362  ps->inegalites =
363  contrainte_sort(ps->inegalites, ps->base, base_index, true, true);
364  return ps;
365 }
Pcontrainte contrainte_sort(Pcontrainte c, Pbase base, Pbase sort_base, bool inner_first, bool complex_first)

References Ssysteme::base, contrainte_sort(), and Ssysteme::inegalites.

Referenced by algorithm_row_echelon_generic(), and constraints_to_loop_bound().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_sort_constraints_simplest_first()

Psysteme sc_sort_constraints_simplest_first ( Psysteme  ps,
Pbase  base_index 
)

Definition at line 602 of file sc_triang_elim_redond.c.

603 {
604  ps->inegalites =
605  contrainte_sort(ps->inegalites, ps->base, base_index, false, false);
606  return ps;
607 }

References Ssysteme::base, contrainte_sort(), and Ssysteme::inegalites.

+ Here is the call graph for this function:

◆ sc_triang_elim_redund()

Psysteme sc_triang_elim_redund ( Psysteme  ps,
Pbase  base_index 
)

sort contrainte c, base b, relatively to sort_base, as defined by the switches.

inner_first: innermost first complex_first: the more complex the likely to be put earlier Psysteme sc_triang_elim_redond(Psysteme ps, Pbase base_index): elimination des contraintes lineaires redondantes dans le systeme ps par test de faisabilite de contrainte inversee; cette fonction est utilisee pour calculer des bornes de boucles, c'est pourquoi il peut etre necessaire de garder des contraintes redondantes afin d'avoit toujours au moins une borne inferieure et une borne superieure pour chaque indice.

resultat retourne par la fonction :

Psysteme : Le systeme initial est modifie. Il est egal a NULL si le systeme initial est non faisable.

Les parametres de la fonction :

Psysteme ps : systeme lineaire

Attention: pour chaque indice dans base_index, il doit rester au moins deux contraintes correspondantes (une positive et une negative). C'est la seule difference avec la fonction sc_elim_redond().

contrainte_reverse() is used. Rational points may be added by this procedure.

Yi-Qing YANG

Modifications:

  • add a normalization step for inequalities; if they are not normalized, i.e. if the GCD of the variable coefficients is not 1, the constant term of the inverted constraint should be carefully updated using the GCD?!? (Francois Irigoin, 30 October 1991)
  • the variables are sorted in order to get a deterministic result (FC 26 Sept 94)
  • the feasible overflow function is called, and only if the constraint is not the last one (performance bug of the previous version) (FC 27 Sept 94)
  • a warning is displayed if many inequalities are to be dealt with, instead of returning the system as is. (FC 28 Sept 94)
  • sc_normalize inserted, in place of many loop that were doing nearly the same. (FC 29/09/94) extern char *entity_local_name();

only the variables that have more than one constraints on a given size and that deal with the variables of base_index are tested.

an old comment suggested that keeping contraints on variables out of base_index would help find redundancy on the base_index contraints, but this should not be true anymore, since the variables are sorted... just help to deal with larger systems...

FC 28/09/94

inversion du sens de l'inegalite par multiplication par -1 du coefficient de chaque variable

test de sc_faisabilite avec la nouvelle inegalite

restore the initial constraint

Definition at line 418 of file sc_triang_elim_redond.c.

419 {
420  Pcontrainte ineq, ineq1;
421  int level, n = vect_size(base_index)+1;
422  two_int_infop info;
424 
425  ps = sc_normalize(ps);
426 
427  if (ps==NULL)
428  return NULL;
429 
430  if (ps->nb_ineq > NB_INEQ_MAX1)
431  fprintf(stderr,
432  "[sc_triang_elim_redund] warning, %d inequalities\n",
433  ps->nb_ineq);
434 
436  {
437  sc_rm(ps), ps=NULL;
438  return NULL;
439  }
440 
441  info = malloc(sizeof(int)*2*n);
442 
443  set_sort_context(&context, ps->base, base_index, true, true);
444  ps->inegalites =
445  constraints_sort_info(ps->inegalites, base_index,
446  (constraint_cmp_func_t) compare_the_constraints,
447  &context, info);
449 
450  for (ineq = ps->inegalites; ineq != NULL; ineq = ineq1)
451  {
452  ineq1 = ineq->succ;
453  level = level_contrainte(ineq, base_index);
454 
455  /* only the variables that have more than one
456  * constraints on a given size and that deal with
457  * the variables of base_index are tested.
458  *
459  * an old comment suggested that keeping contraints on variables
460  * out of base_index would help find redundancy on the base_index
461  * contraints, but this should not be true anymore, since the
462  * variables are sorted... just help to deal with larger systems...
463  *
464  * FC 28/09/94
465  */
466  if (level!=0 && info[abs(level)][level<0?0:1]>1)
467  {
468  /* inversion du sens de l'inegalite par multiplication
469  * par -1 du coefficient de chaque variable
470  */
471  contrainte_reverse(ineq);
472 
473  /* test de sc_faisabilite avec la nouvelle inegalite
474  */
476  /* restore the initial constraint */
477  contrainte_reverse(ineq);
478  else
479  {
480  eq_set_vect_nul(ineq);
481  info[abs(level)][level<0?0:1]--;
482  }
483  }
484  }
486  ps = sc_kill_db_eg(ps);
487 
488  free(info);
489  return ps;
490 }
void eq_set_vect_nul(Pcontrainte)
void_eq_set_vect_nul(Pcontrainte c): transformation d'une contrainte en une contrainte triviale 0 == ...
Definition: unaires.c:84
int level_contrainte(Pcontrainte, Pbase)
int level_contrainte(Pcontrainte pc, Pbase base_index) compute the level (rank) of the constraint pc ...
Definition: unaires.c:292
void contrainte_reverse(Pcontrainte)
void contrainte_reverse(Pcontrainte eq): changement de signe d'une contrainte, i.e.
Definition: unaires.c:67
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
bool sc_integer_feasibility_ofl_ctrl(Psysteme sc, int ofl_ctrl, bool ofl_res)
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
int nb_ineq
Definition: sc-local.h:73
#define abs(v)
Definition: syntax-local.h:48
#define OFL_CTRL
I do thing that overflows are managed in a very poor manner.

References abs, Ssysteme::base, clear_sort_context(), compare_the_constraints(), constraints_sort_info(), contrainte_reverse(), eq_set_vect_nul(), fprintf(), free(), Ssysteme::inegalites, info(), level, level_contrainte(), malloc(), Ssysteme::nb_ineq, OFL_CTRL, sc_elim_empty_constraints(), sc_integer_feasibility_ofl_ctrl(), sc_kill_db_eg(), sc_normalize(), sc_rm(), set_sort_context(), Scontrainte::succ, and vect_size().

Referenced by algorithm_row_echelon_generic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_triang_elim_redund_n_first()

void sc_triang_elim_redund_n_first ( Psysteme  s,
int  n 
)

void sc_triang_elim_redund_n_first(s, n) Psysteme s; int n;

tries a triangular redundancy elimination on the n first constraints, which must all deal with the same side of the same index. if n is 0, nothing is done, but nothing is reported.

contrainte_reverse() is used and rational points may be added

nothing to be done

restore

remove

Definition at line 521 of file sc_triang_elim_redond.c.

522 {
523  int tested, removed;
524  Pcontrainte ineq;
525 
526  if (n<=1) return; /* nothing to be done */
527 
528  for (ineq=sc_inegalites(s), tested=0, removed=0;
529  removed<n-1 && tested<n;
530  tested++, ineq=ineq->succ)
531  {
532  contrainte_reverse(ineq);
533 
535  contrainte_reverse(ineq); /* restore */
536  else
537  eq_set_vect_nul(ineq), removed++; /* remove */
538  }
539 }

References contrainte_reverse(), eq_set_vect_nul(), OFL_CTRL, sc_integer_feasibility_ofl_ctrl(), and Scontrainte::succ.

Referenced by sc_build_triang_elim_redund().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_sort_context()

static void set_sort_context ( sort_ctx_t context,
Pbase  base,
Pbase  sort_base,
bool  inner_first,
bool  complex_first 
)
static

Definition at line 52 of file sc_triang_elim_redond.c.

58 {
59  Pbase btmp = BASE_NULLE;
60  assert(context != NULL);
61 
62  // the base is reversed! inner indexes first!!
63  context->rbase = base_normalize(base_reversal(sort_base));
64  btmp = base_difference(base, sort_base);
65  context->others = base_normalize(btmp);
66  context->inner_first = inner_first;
67  context->complex_first = complex_first;
68 }
Pbase base_difference(Pbase b1, Pbase b2)
Pbase base_difference(Pbase b1, Pbase b2): allocate b; b = b1 - b2 – with the set meaning return b;.
Definition: base.c:621
Pbase base_normalize(Pbase b)
Definition: base.c:594
Pbase base_reversal(Pbase b_in)
Pbase base_reversal(Pbase b_in): produces a basis b_out, having the same basis vectors as b_in,...
Definition: base.c:221

References assert, base, base_difference(), base_normalize(), BASE_NULLE, and base_reversal().

Referenced by contrainte_sort(), sc_build_triang_elim_redund(), and sc_triang_elim_redund().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: