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

Go to the source code of this file.

Functions

bool sc_elim_simple_redund_with_eq (Psysteme ps, Pcontrainte eg)
 package sc More...
 
bool sc_elim_simple_redund_with_ineq (Psysteme ps, Pcontrainte ineg)
 bool sc_elim_simple_redund_with_ineq(Psysteme ps, Pcontrainte ineg): elimination des contraintes redondantes de ps avec une inegalite ineg (FI: qui doit appartenir a ps; verifier qu'on ne fait pas de comparaisons inutiles; apparemment pas parce qu'on modifie froidement ineg) More...
 
int sc_check_inequality_redundancy (Pcontrainte ineq, Psysteme ps)
 int sc_check_inequality_redundancy(Pcontrainte ineq, Psysteme ps) Check if an inequality ineq, possibly part of ps, is trivially infeasible (return 2), redundant (return 1), potentially useful (return 0) with respect to inequalities in ps. More...
 
void sc_elim_empty_constraints (Psysteme ps, bool process_equalities)
 void sc_elim_empty_constraints(Psysteme ps, bool process_equalities): elimination des "fausses" contraintes du systeme ps, i.e. More...
 
Psysteme sc_elim_db_constraints (Psysteme ps)
 Psysteme sc_elim_db_constraints(Psysteme ps): elimination des egalites et des inegalites identiques ou inutiles dans le systeme; plus precisemment: More...
 
Psysteme sc_safe_elim_db_constraints (Psysteme ps)
 The returned value must be used because they argument is freed when the system is not feasible. More...
 
Psysteme sc_elim_double_constraints (Psysteme ps)
 Psysteme sc_elim_double_constraints(Psysteme ps): elimination des egalites et des inegalites identiques ou inutiles dans le systeme apres reduction par le gcd; plus precisemment: More...
 

Function Documentation

◆ sc_check_inequality_redundancy()

int sc_check_inequality_redundancy ( Pcontrainte  ineq,
Psysteme  ps 
)

int sc_check_inequality_redundancy(Pcontrainte ineq, Psysteme ps) Check if an inequality ineq, possibly part of ps, is trivially infeasible (return 2), redundant (return 1), potentially useful (return 0) with respect to inequalities in ps.

Neither ps nor ineq are modified. ineq may be one of ps constraints.

c is redundant with ineq

ineq is redundant with c

c and ineq define a non-empty interval

ineq and c are incompatible

Definition at line 175 of file sc_elim_simple_redund.c.

176 {
178  int code = 0;
179 
180  for(c = sc_inegalites(ps);
181  code ==0 && !CONTRAINTE_UNDEFINED_P(c);
182  c = contrainte_succ(c)) {
183 
184  if(c!=ineq) {
185  Value b;
186 
187  if(eq_smg(c, ineq)) {
188  b = eq_diff_const(c, ineq);
189  if(value_neg_p(b)) {
190  /* c is redundant with ineq */
191  ;
192  }
193  else {
194  /* ineq is redundant with c */
195  code = 1;
196  }
197  }
198  else if (inequalities_opposite_p(c, ineq)) {
199  b = eq_sum_const(c, ineq);
200  if(value_negz_p(b)) {
201  /* c and ineq define a non-empty interval */
202  ;
203  }
204  else {
205  /* ineq and c are incompatible */
206  code = 2;
207  }
208  }
209  }
210  }
211  return code;
212 }
#define value_negz_p(val)
int Value
#define value_neg_p(val)
#define CONTRAINTE_UNDEFINED_P(c)
#define contrainte_succ(c)
#define CONTRAINTE_UNDEFINED
Value eq_diff_const(Pcontrainte c1, Pcontrainte c2)
Value eq_diff_const(Pcontrainte c1, Pcontrainte c2): calcul de la difference des deux termes constant...
Definition: binaires.c:218
Value eq_sum_const(Pcontrainte c1, Pcontrainte c2)
Value eq_sum_const(Pcontrainte c1, Pcontrainte c2): calcul de la somme des deux termes constants des ...
Definition: binaires.c:243
bool inequalities_opposite_p(Pcontrainte, Pcontrainte)
bool inequalities_opposite_p(Pcontrainte c1, Pcontrainte c2): True if the non-constant part of c1 is ...
Definition: predicats.c:71
bool eq_smg(Pcontrainte, Pcontrainte)
predicats.c
Definition: predicats.c:52
struct _newgen_struct_code_ * code
Definition: ri.h:79

References contrainte_succ, CONTRAINTE_UNDEFINED, CONTRAINTE_UNDEFINED_P, eq_diff_const(), eq_smg(), eq_sum_const(), inequalities_opposite_p(), value_neg_p, and value_negz_p.

Referenced by efficient_sc_check_inequality_feasibility(), expression_less_than_in_context(), sc_strong_normalize_and_check_feasibility(), and top_down_abc_dimension().

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

◆ sc_elim_db_constraints()

Psysteme sc_elim_db_constraints ( Psysteme  ps)

Psysteme sc_elim_db_constraints(Psysteme ps): elimination des egalites et des inegalites identiques ou inutiles dans le systeme; plus precisemment:

Pour les egalites, on elimine une equation si on a un systeme d'egalites de la forme :

a1/ Ax - b == 0, ou b1/ Ax - b == 0,
Ax - b == 0, b - Ax == 0,

ou c1/ 0 == 0

Pour les inegalites, on elimine une inequation si on a un systeme d'inegalites de la forme :

a2/ Ax - b <= c, ou b2/ 0 <= const (avec const >=0) Ax - b <= c

resultat retourne par la fonction :

Psysteme : Le systeme initial est modifie (si necessaire) et renvoye Si le systeme est non faisable (0 <= const <0 ou 0 = b), il est desalloue et NULL est renvoye.

Attention, on ne teste pas les proportionalites: 2*i=2 est different de i = 1. Il faut reduire le systeme par gcd avant d'appeler cette fonction sc_elim_db_constraints()

Notes:

  • le temps d'execution doit pouvoir etre divise par deux en prenant en compte la symetrie des comparaisons et en modifiant l'initialisation des boucles internes pour les "triangulariser superieurement".
  • la representation interne des vecteurs est utilisee pour les tests; il faudrait tester la colinearite au vecteur de base representatif du terme constant

so called triangular version, FC 28/09/94

b = 0

0 <= b < 0

Definition at line 317 of file sc_elim_simple_redund.c.

319 {
321  eq1 = NULL,
322  eq2 = NULL;
323 
324  if (SC_UNDEFINED_P(ps))
325  return(NULL);
326 
327  for (eq1 = ps->egalites; eq1 != NULL; eq1 = eq1->succ)
328  {
329  if ((vect_size(eq1->vecteur) == 1) &&
330  (eq1->vecteur->var == 0) && (eq1->vecteur->val != 0))
331  {
332  /* b = 0 */
333  sc_rm(ps);
334  return(NULL);
335  }
336 
337  for (eq2 = eq1->succ; eq2 != NULL;eq2 = eq2->succ)
338  if (egalite_equal(eq1, eq2))
339  eq_set_vect_nul(eq2);
340  }
341 
342  for (eq1 = ps->inegalites; eq1 != NULL;eq1 = eq1->succ) {
343  if ((vect_size(eq1->vecteur) == 1) && (eq1->vecteur->var == 0)) {
344  if (value_negz_p(val_of(eq1->vecteur))) {
345  vect_rm(eq1->vecteur);
346  eq1->vecteur = NULL;
347  }
348  else {
349  /* 0 <= b < 0 */
350  sc_rm(ps);
351  return(NULL);
352  }
353  }
354  for (eq2 = eq1->succ;eq2 != NULL;eq2 = eq2->succ)
355  if (contrainte_equal(eq1,eq2))
356  eq_set_vect_nul(eq2);
357  }
358 
359  sc_elim_empty_constraints(ps, true);
360  sc_elim_empty_constraints(ps, false);
361 
362  return (ps);
363 }
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
bool contrainte_equal(Pcontrainte, Pcontrainte)
bool contrainte_equal(Pcontrainte c1, Pcontrainte c2): test d'egalite des contraintes c1 et c2; elles...
Definition: predicats.c:128
bool egalite_equal(Pcontrainte, Pcontrainte)
bool egalite_equal(Pcontrainte eg1, Pcontrainte eg2): teste l'equivalence de deux egalites; leurs coe...
Definition: predicats.c:98
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
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
void sc_elim_empty_constraints(Psysteme ps, bool process_equalities)
void sc_elim_empty_constraints(Psysteme ps, bool process_equalities): elimination des "fausses" contr...
Pvecteur vecteur
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
Pcontrainte egalites
Definition: sc-local.h:70
Value val
Definition: vecteur-local.h:91
Variable var
Definition: vecteur-local.h:90
#define val_of(varval)
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78

References contrainte_equal(), egalite_equal(), eq_set_vect_nul(), sc_elim_empty_constraints(), sc_rm(), Scontrainte::succ, Svecteur::val, val_of, value_negz_p, Svecteur::var, vect_rm(), vect_size(), and Scontrainte::vecteur.

Referenced by elim_var_with_eg(), my_sc_normalize(), and sc_transform_eg_in_ineg().

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

◆ sc_elim_double_constraints()

Psysteme sc_elim_double_constraints ( Psysteme  ps)

Psysteme sc_elim_double_constraints(Psysteme ps): elimination des egalites et des inegalites identiques ou inutiles dans le systeme apres reduction par le gcd; plus precisemment:

Pour les egalites, on elimine une equation si on a un systeme d'egalites de la forme :

a1/ Ax - b == 0, ou b1/ Ax - b == 0,
Ax - b == 0, b - Ax == 0,

ou c1/ 0 == 0

Si on a A=0 et b!=0, on detecte une non-faisabilite.

Si on a Ax - b == 0 et Ax - b' == 0 et b!=b', on detecte une non-faisabilite.

Pour les inegalites, on elimine une inequation si on a un systeme d'inegalites de la forme :

a2/ Ax - b <= 0, ou b2/ 0 <= const (avec const >=0) Ax - b <= 0

Une inegalite peut etre redondante ou incompatible avec une egalite:

a3/ Ax - b == 0, ou b3/ b - Ax == 0, Ax - c <= 0, Ax - c <= 0 b - c <= 0 b - c <= 0

on detecte une non-faisabilite si b - c > 0.

Une paire d'inegalites est remplacee par une egalite:

a4/ Ax - b <= 0 -Ax + b <=0

donne Ax - b == 0

resultat retourne par la fonction :

Psysteme : Le systeme initial est modifie (si necessaire) et renvoye Si le systeme est non faisable (0 <= const <0 ou 0 = b), il est desalloue et NULL est renvoye.

Notes:

  • la representation interne des vecteurs est utilisee pour les tests; il faudrait tester la colinearite au vecteur de base representatif du terme constant

Normalization by gcd's

Detection of inconsistant equations: incompatible constant term

b = 0

deux equations ne differant que par leurs termes constants

Check redundancy and inconsistency between pair of inequalities

Detection of inconsistant or redundant inequalities: incompatible or useless constant term

0 <= b < 0

Equal inequalities, redundant inequalities, equality detection

opposite STRICT inequality or contrainte_equal() would have caught it

inequalities eq1 and eq2 define an equality

No need to update the basis since it used to be an inequality

These inequalities are incompatible and the system is not satisfiable

Check redundancies and inconsistencies between equalities and inequalities

0 < b <= 0

0 < b <= 0

Definition at line 529 of file sc_elim_simple_redund.c.

531 {
533  eq1 = NULL,
534  ineq1 = NULL,
535  eq2 = NULL;
536 
537  if (SC_UNDEFINED_P(ps))
538  return(SC_UNDEFINED);
539 
540  /* Normalization by gcd's */
541 
542  for (eq1 = ps->egalites; eq1 != NULL; eq1 = eq1->succ) {
543  vect_normalize(eq1->vecteur);
544  }
545 
546  for (ineq1 = ps->inegalites; ineq1 != NULL;ineq1 = ineq1->succ) {
547  (void) contrainte_normalize(ineq1, false);
548  }
549 
550  /* Detection of inconsistant equations: incompatible constant term */
551 
552  for (eq1 = ps->egalites; eq1 != NULL; eq1 = eq1->succ) {
553  if ((vect_size(eq1->vecteur) == 1) &&
554  (eq1->vecteur->var == 0) && (eq1->vecteur->val != 0)) {
555  /* b = 0 */
556  sc_rm(ps);
557  return(SC_EMPTY);
558  }
559 
560  for (eq2 = eq1->succ; eq2 != NULL;eq2 = eq2->succ) {
561  if (egalite_equal(eq1, eq2))
562  eq_set_vect_nul(eq2);
563  else if(vect_equal_except(eq1->vecteur,eq2->vecteur, TCST)) {
564  /* deux equations ne differant que par leurs termes constants */
565  sc_rm(ps);
566  return(SC_EMPTY);
567  }
568  }
569  }
570 
571  /* Check redundancy and inconsistency between pair of inequalities */
572 
573  for (eq1 = ps->inegalites; eq1 != NULL;eq1 = eq1->succ) {
574 
575  /* Detection of inconsistant or redundant inequalities: incompatible or
576  useless constant term */
577 
578  if ((vect_size(eq1->vecteur) == 1) && (eq1->vecteur->var == TCST)) {
579  if (value_negz_p(val_of(eq1->vecteur))) {
580  vect_rm(eq1->vecteur);
581  eq1->vecteur = NULL;
582  }
583  else {
584  /* 0 <= b < 0 */
585  sc_rm(ps);
586  return(SC_EMPTY);
587  }
588  }
589 
590  /* Equal inequalities, redundant inequalities, equality detection */
591 
592  for (eq2 = eq1->succ;eq2 != NULL;eq2 = eq2->succ) {
593  if (contrainte_equal(eq1,eq2)) {
594  eq_set_vect_nul(eq2);
595  }
596  else if(eq_smg(eq1,eq2)) {
599  eq_set_vect_nul(eq2);
600  else
601  /* opposite STRICT inequality or contrainte_equal() would have
602  caught it */
603  eq_set_vect_nul(eq1);
604  }
605  else {
607  contrainte_vecteur(eq2));
608 
609  if(VECTEUR_NUL_P(sum)) {
610  /* inequalities eq1 and eq2 define an equality */
612 
613  /* No need to update the basis since it used to be an inequality */
614  sc_add_egalite(ps, eq);
615  eq_set_vect_nul(eq1);
616  eq_set_vect_nul(eq2);
617  }
618  else if(vect_constant_p(sum)) {
619  if(value_pos_p(vect_coeff(TCST, sum))) {
620  /* These inequalities are incompatible and the system is not satisfiable */
621  vect_rm(sum);
622  sc_rm(ps);
623  return(SC_EMPTY);
624  }
625  }
626  vect_rm(sum);
627  }
628  }
629  }
630 
631  /* Check redundancies and inconsistencies between equalities and
632  inequalities */
633 
634  for (ineq1 = ps->inegalites; ineq1 != NULL;ineq1 = ineq1->succ) {
635  for (eq2 = ps->egalites; eq2 != NULL; eq2 = eq2->succ) {
637 
638  if (VECTEUR_NUL_P(diff1)) {
639  vect_rm(ineq1->vecteur);
640  ineq1->vecteur = NULL;
641  }
642  else if(vect_constant_p(diff1)) {
643  if (value_neg_p(vecteur_val(diff1))) {
644  vect_rm(ineq1->vecteur);
645  ineq1->vecteur = NULL;
646  }
647  else {
648  /* 0 < b <= 0 */
649  vect_rm(diff1);
650  sc_rm(ps);
651  return(SC_EMPTY);
652  }
653  }
654  else {
656 
657  if (vect_constant_p(diff2)) {
658  if (VECTEUR_NUL_P(diff2) || value_neg_p(vecteur_val(diff2))) {
659  vect_rm(ineq1->vecteur);
660  ineq1->vecteur = NULL;
661  }
662  else {
663  /* 0 < b <= 0 */
664  vect_rm(diff2);
665  sc_rm(ps);
666  return(SC_EMPTY);
667  }
668  }
669  vect_rm(diff2);
670  }
671  vect_rm(diff1);
672  }
673  }
674  sc_elim_empty_constraints(ps, true);
675  sc_elim_empty_constraints(ps, false);
676 
677  return (ps);
678 }
#define value_pos_p(val)
#define contrainte_vecteur(c)
passage au champ vecteur d'une contrainte "a la Newgen"
Pcontrainte contrainte_make(Pvecteur pv)
Pcontrainte contrainte_make(Pvecteur pv): allocation et initialisation d'une contrainte avec un vecte...
Definition: alloc.c:73
bool vect_constant_p(Pvecteur)
bool vect_constant_p(Pvecteur v): v contains only a constant term, may be zero
Definition: predicats.c:211
bool contrainte_normalize(Pcontrainte, bool)
normalize.c
Definition: normalize.c:56
bool vect_equal_except(Pvecteur v1, Pvecteur v2, Variable var)
bool vect_equal_except(Pvecteur v1, Pvecteur v2, Variable var): test a egalite des projections selon ...
Definition: reductions.c:319
void sc_add_egalite(Psysteme p, Pcontrainte e)
void sc_add_egalite(Psysteme p, Pcontrainte e): macro ajoutant une egalite e a un systeme p; la base ...
Definition: sc_alloc.c:389
Pcontrainte eq
element du vecteur colonne du systeme donne par l'analyse
Definition: sc_gram.c:108
t_real sum(int n1, int n2, int n3, t_real u[n1][n2][n3])
Definition: stencil.c:57
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_val(v)
#define VECTEUR_NUL_P(v)
Pbase vect_copy(Pvecteur b)
direct duplication.
Definition: alloc.c:240
Pvecteur vect_add(Pvecteur v1, Pvecteur v2)
package vecteur - operations binaires
Definition: binaires.c:53
Pvecteur vect_substract(Pvecteur v1, Pvecteur v2)
Pvecteur vect_substract(Pvecteur v1, Pvecteur v2): allocation d'un vecteur v dont la valeur est la di...
Definition: binaires.c:75
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
void vect_normalize(Pvecteur v)
void vect_normalize(Pvecteur v): division de tous les coefficients de v par leur pgcd; "normalisation...
Definition: unaires.c:59

References contrainte_equal(), contrainte_make(), contrainte_normalize(), contrainte_vecteur, egalite_equal(), eq, eq_set_vect_nul(), eq_smg(), sc_add_egalite(), sc_elim_empty_constraints(), sc_rm(), Scontrainte::succ, sum(), TCST, Svecteur::val, val_of, value_neg_p, value_negz_p, value_pos_p, Svecteur::var, vect_add(), vect_coeff(), vect_constant_p(), vect_copy(), vect_equal_except(), vect_normalize(), vect_rm(), vect_size(), vect_substract(), Scontrainte::vecteur, VECTEUR_NUL_P, and vecteur_val.

Referenced by sc_minmax_of_variable(), sc_normalize2(), and sc_transform_ineg_in_eg().

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

◆ sc_elim_empty_constraints()

void sc_elim_empty_constraints ( Psysteme  ps,
bool  process_equalities 
)

void sc_elim_empty_constraints(Psysteme ps, bool process_equalities): elimination des "fausses" contraintes du systeme ps, i.e.

les contraintes ne comportant plus de couple (variable,valeur), i.e. les contraintes qui ont ete eliminees par la fonction 'eq_set_vect_nul', i.e. 0 = 0 ou 0 <= 0

resultat retourne par la fonction: le systeme initial ps est modifie.

parametres de la fonction: !Psysteme ps: systeme lineaire bool egalite: true s'il faut traiter la liste des egalites false s'il faut traiter la liste des inegalites

Modifications:

  • the number of equalities was always decremented, regardless of the process_equalities parameter; Francois Irigoin, 30 October 1991

Definition at line 232 of file sc_elim_simple_redund.c.

235 {
236  Pcontrainte pc, ppc;
237 
238  if (!SC_UNDEFINED_P(ps)) {
239  if (process_equalities) {
240  pc = ps->egalites;
241  ppc = NULL;
242  while (pc != NULL) {
243  if (contrainte_vecteur(pc) == NULL) {
244  Pcontrainte p = pc;
245  if (ppc == NULL) ps->egalites = pc = pc->succ;
246  else
247  ppc->succ = pc = pc->succ;
248  contrainte_free(p);
249  ps->nb_eq--;
250  }
251  else {
252  ppc = pc;
253  pc = pc->succ;
254  }
255  }
256  }
257  else {
258  pc = ps->inegalites;
259  ppc = NULL;
260  while (pc != NULL) {
261  if (contrainte_vecteur(pc) == NULL) {
262  Pcontrainte p = pc;
263  if (ppc == NULL) ps->inegalites = pc = pc->succ;
264  else
265  ppc->succ = pc = pc->succ;
266  contrainte_free(p);
267  ps->nb_ineq--;
268  }
269  else {
270  ppc = pc;
271  pc = pc->succ;
272  }
273  }
274  }
275  }
276 }
Pcontrainte contrainte_free(Pcontrainte c)
Pcontrainte contrainte_free(Pcontrainte c): liberation de l'espace memoire alloue a la contrainte c a...
Definition: alloc.c:184
int nb_ineq
Definition: sc-local.h:73
int nb_eq
Definition: sc-local.h:72

References contrainte_free(), contrainte_vecteur, and Scontrainte::succ.

Referenced by my_sc_normalize(), sc_bounded_normalization(), sc_build_triang_elim_redund(), sc_elim_db_constraints(), sc_elim_double_constraints(), sc_normalize(), sc_normalize2(), sc_safe_elim_db_constraints(), sc_strong_normalize_and_check_feasibility2(), sc_triang_elim_redund(), and transform_in_ineq().

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

◆ sc_elim_simple_redund_with_eq()

bool sc_elim_simple_redund_with_eq ( Psysteme  ps,
Pcontrainte  eg 
)

package sc

bool sc_elim_simple_redund_with_eq(Psysteme ps, Pcontrainte eg): elimination en place des contraintes d'un systeme ps, qui sont redondantes avec une egalite eg

  • si une autre egalite a le meme membre gauche (equation sans le terme constant) :
    • si les termes constants sont egaux ==> elimination d'une egalite
    • sinon ==> systeme infaisable
  • si une inegalite a le meme membre gauche que l'egalite :
    • si l'egalite est compatible avec inegalite
      ==> elimination de l'inegalite
    • sinon ==> systeme infaisable

resultat retourne par la fonction :

boolean: false si l'equation a permis de montrer que le systeme etait non faisable true sinon

Les parametres de la fonction :

!Psysteme ps : systeme Pcontrainte eg : equation du systeme

cas des egalites

les deux egalites sont redondantes ==> elimination de eq

cas des inegalites

Definition at line 69 of file sc_elim_simple_redund.c.

72 {
73  Pcontrainte eq = NULL;
74 
75  if (SC_UNDEFINED_P(ps) || sc_rn_p(ps))
76  return(true);
77 
78  /* cas des egalites */
79  for (eq = ps->egalites; eq != NULL; eq = eq->succ) {
80  if (eq != eg && eq->vecteur != NULL && eq_smg(eq,eg)) {
81  if (eq_diff_const(eq,eg) == 0)
82  /* les deux egalites sont redondantes
83  ==> elimination de eq */
85  else
86  return(false);
87  }
88  }
89 
90  /* cas des inegalites */
91  for (eq = ps->inegalites; eq != NULL; eq = eq->succ) {
92  if (eq_smg(eq,eg) && eq->vecteur!= NULL) {
93  if (value_negz_p(eq_diff_const(eq, eg)))
95  else
96  return(false);
97  }
98  }
99  return(true);
100 }
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

References eq, eq_diff_const(), eq_set_vect_nul(), eq_smg(), sc_rn_p(), Scontrainte::succ, value_negz_p, and Scontrainte::vecteur.

Referenced by sc_add_normalize_eq(), and sc_normalize().

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

◆ sc_elim_simple_redund_with_ineq()

bool sc_elim_simple_redund_with_ineq ( Psysteme  ps,
Pcontrainte  ineg 
)

bool sc_elim_simple_redund_with_ineq(Psysteme ps, Pcontrainte ineg): elimination des contraintes redondantes de ps avec une inegalite ineg (FI: qui doit appartenir a ps; verifier qu'on ne fait pas de comparaisons inutiles; apparemment pas parce qu'on modifie froidement ineg)

  • si deux inegalites ont le meme membre gauche (contrainte sans le
    terme constant) :

    ==> elimination de l'inegalite ayant le terme constant le plus
    grand

  • si une egalite a le meme membre gauche que l'inegalite :
    • si l'egalite est compatible avec inegalite
      ==> elimination de l'inegalite
    • sinon ==> systeme infaisable

resultat retourne par la fonction :

boolean: false si l'inequation a permis de montrer que le systeme etait non faisable true sinon

Les parametres de la fonction :

Psysteme ps : systeme Pcontrainte ineg : inequation du systeme

cas des egalites

inegalite redondante avec l'egalite
==> elimination de inegalite

cas des inegalites

Definition at line 130 of file sc_elim_simple_redund.c.

133 {
134  Pcontrainte eq=NULL;
135  bool result = true;
136  Value b = VALUE_ZERO;
137 
138  if (SC_UNDEFINED_P(ps) || sc_rn_p(ps))
139  return(true);
140 
141  /* cas des egalites */
142  for (eq = ps->egalites; eq != NULL && ineg->vecteur != NULL;
143  eq = eq->succ)
144  if (eq_smg(eq,ineg)) {
145  b = eq_diff_const(ineg,eq);
146  if (value_negz_p(b))
147  /* inegalite redondante avec l'egalite
148  ==> elimination de inegalite */
149  eq_set_vect_nul(ineg);
150  else result = false;
151  }
152 
153  /* cas des inegalites */
154  for (eq = ps->inegalites;eq !=NULL && ineg->vecteur != NULL;
155  eq = eq->succ) {
156  if (eq != ineg)
157  if (eq_smg(eq,ineg)) {
158  b = eq_diff_const(eq,ineg);
159  if(value_negz_p(b))
161  else
162  eq_set_vect_nul(ineg);
163  }
164  }
165  return (result);
166 }
#define VALUE_ZERO

References eq, eq_diff_const(), eq_set_vect_nul(), eq_smg(), sc_rn_p(), Scontrainte::succ, value_negz_p, VALUE_ZERO, and Scontrainte::vecteur.

Referenced by sc_add_normalize_ineq(), and sc_normalize().

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

◆ sc_safe_elim_db_constraints()

Psysteme sc_safe_elim_db_constraints ( Psysteme  ps)

The returned value must be used because they argument is freed when the system is not feasible.

FI: I added an elimination and check of the colinear constraints.

b = 0

0 <= b < 0

Use rational simplification

The constraints are opposed. Their constant terms must be compatible

The constraint system is not feasible

ps should be replaced by sc_empty

The signs of a1 and a2 are different

get rid of the first constraint

FI: it would be safer to keep *ps and to change each field

I thought there was a function to remove the useless stuff from a Psystem and to make it an empty one, but I could not find it.

Definition at line 370 of file sc_elim_simple_redund.c.

371 {
373  eq1 = NULL,
374  eq2 = NULL;
375  bool empty_p = false; // The system is empty
376 
377  if (SC_UNDEFINED_P(ps))
378  return(NULL);
379 
380  for (eq1 = ps->egalites; eq1 != NULL; eq1 = eq1->succ)
381  {
382  if ((vect_size(eq1->vecteur) == 1) &&
383  (eq1->vecteur->var == 0) && (eq1->vecteur->val != 0))
384  {
385  /* b = 0 */
386  Pbase base_tmp = ps->base;
387  ps->base = BASE_UNDEFINED;
388  sc_rm(ps);
389  ps =sc_empty(base_tmp);
390  return(ps);
391  }
392 
393  for (eq2 = eq1->succ; eq2 != NULL;eq2 = eq2->succ)
394  if (egalite_equal(eq1, eq2))
395  eq_set_vect_nul(eq2);
396  }
397 
398  for (eq1 = ps->inegalites; eq1 != NULL && !empty_p; eq1 = eq1->succ) {
399  if ((vect_size(eq1->vecteur) == 1) && (eq1->vecteur->var == 0)) {
400  if (value_negz_p(val_of(eq1->vecteur))) {
401  vect_rm(eq1->vecteur);
402  eq1->vecteur = NULL;
403  }
404  else {
405  /* 0 <= b < 0 */
406  Pbase base_tmp = ps->base;
407  ps->base = BASE_UNDEFINED;
408  sc_rm(ps);
409  ps =sc_empty(base_tmp);
410  return(ps);
411  }
412  }
413 
414  for (eq2 = eq1->succ;eq2 != NULL;eq2 = eq2->succ) {
415  if (contrainte_equal(eq1,eq2))
416  eq_set_vect_nul(eq2);
417  else if(false) {
418  /* Use rational simplification */
419  Value a1, a2;
420  if(contrainte_parallele(eq1, eq2, &a1, &a2)) {
421  Pvecteur v1 = contrainte_vecteur(eq1);
422  Pvecteur v2 = contrainte_vecteur(eq2);
423  if(a1<0 && a2<0) {
424  a1 = -a1;
425  a2 = -a2;
426  }
427  if(a1>0 && a2>0) {
428  /* The constraints are opposed. Their constant terms must be compatible */
429  Value k1 = vect_coeff(TCST, v1);
430  Value k2 = vect_coeff(TCST, v2);
431  Value k = value_mult(a2,k1) + value_mult(a1,k2);
432  if(k>0) {
433  /* The constraint system is not feasible */
434  /* ps should be replaced by sc_empty */
435  empty_p = true;
436  break;
437  }
438  }
439  else {
440  /* The signs of a1 and a2 are different */
441  if(a1<0) a1 = -a1;
442  if(a2<0) a2 = -a2;
443  Value k1 = vect_coeff(TCST, v1);
444  Value k2 = vect_coeff(TCST, v2);
445  Value nk1 = value_product(a2,k1);
446  Value nk2 = value_product(a1,k2);
447  if(nk1<nk2) {
448  /* get rid of the first constraint */
449  eq_set_vect_nul(eq1);
450  }
451  else {
452  eq_set_vect_nul(eq2);
453  }
454  }
455  }
456  }
457  }
458  }
459 
460  if(empty_p) {
461  /* FI: it would be safer to keep *ps and to change each field
462  *
463  * I thought there was a function to remove the useless stuff from
464  * a Psystem and to make it an empty one, but I could not find it.
465  */
466  Pbase b = sc_base(ps);
467  sc_base(ps) = BASE_NULLE;
468  sc_rm(ps);
469  ps = sc_empty(b);
470  }
471  else {
472  sc_elim_empty_constraints(ps, true);
473  sc_elim_empty_constraints(ps, false);
474  }
475 
476  return (ps);
477 }
#define value_product(v, w)
#define value_mult(v, w)
whether the default is protected or not this define makes no sense any more...
bool contrainte_parallele(Pcontrainte, Pcontrainte, Value *, Value *)
Les deux contraintes c1 et c2 sont paralleles s'il existe deux coefficients a1 et a2 tels que a1 c1 +...
Definition: predicats.c:145
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
Pbase base
Definition: sc-local.h:75
static int k2
static int k1
#define BASE_UNDEFINED
#define BASE_NULLE
MACROS SUR LES BASES.

References Ssysteme::base, BASE_NULLE, BASE_UNDEFINED, contrainte_equal(), contrainte_parallele(), contrainte_vecteur, egalite_equal(), Ssysteme::egalites, eq_set_vect_nul(), Ssysteme::inegalites, k1, k2, sc_elim_empty_constraints(), sc_empty(), sc_rm(), Scontrainte::succ, TCST, Svecteur::val, val_of, value_mult, value_negz_p, value_product, Svecteur::var, vect_coeff(), vect_rm(), vect_size(), and Scontrainte::vecteur.

Referenced by sc_fourier_motzkin_feasibility_ofl_ctrl().

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