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

Go to the source code of this file.

Macros

#define HUGE   250
 package sc More...
 
#define level   (2)
 
#define if_debug_sc_minmax_of_variable2   if(false)
 

Functions

static bool huge_system (Psysteme ps)
 
bool sc_value_of_variable (Psysteme ps, Variable var, Value *pval)
 bool sc_value_for_variable(Psysteme ps, Variable var, Value *pval): examine les egalites du systeme ps pour recherche une egalite de la forme: More...
 
bool sc_minmax_of_variable (Psysteme ps, Variable var, Value *pmin, Value *pmax)
 void sc_minmax_of_variable(Psysteme ps, Variable var, Value *pmin, *pmax): examine un systeme pour trouver le minimum et le maximum d'une variable apparaissant dans ce systeme par projection a la Fourier-Motzkin. More...
 
void sc_minmax_of_variables (Psysteme ps1, Psysteme ps2, Pbase b)
 This function uses sc_minmax_of_variable to compute the min and max of each variable belonging to base b. More...
 
void sc_force_variable_to_zero (Psysteme ps, Variable var)
 void sc_force_variable_to_zero(Psysteme ps, Variable var): force la variable var a prendre la valeur 0, i.e. More...
 
bool sc_minmax_of_variable2 (volatile Psysteme ps, Variable var, Value *pmin, Value *pmax)
 void sc_minmax_of_variable2(Psysteme ps, Variable var, Value *pmin, *pmax): examine un systeme pour trouver le minimum et le maximum d'une variable apparaissant dans ce systeme par projection a la Fourier-Motzkin. More...
 

Macro Definition Documentation

◆ HUGE

#define HUGE   250

package sc

Definition at line 45 of file sc_eval.c.

◆ if_debug_sc_minmax_of_variable2

#define if_debug_sc_minmax_of_variable2   if(false)

◆ level

#define level   (2)

Function Documentation

◆ huge_system()

static bool huge_system ( Psysteme  ps)
static

Definition at line 46 of file sc_eval.c.

47 {
48  return(ps->nb_eq>HUGE || ps->nb_ineq>HUGE);
49 }
#define HUGE
package sc
Definition: sc_eval.c:45
int nb_ineq
Definition: sc-local.h:73
int nb_eq
Definition: sc-local.h:72

References HUGE, Ssysteme::nb_eq, and Ssysteme::nb_ineq.

Referenced by sc_minmax_of_variable().

+ Here is the caller graph for this function:

◆ sc_force_variable_to_zero()

void sc_force_variable_to_zero ( Psysteme  ps,
Variable  var 
)

void sc_force_variable_to_zero(Psysteme ps, Variable var): force la variable var a prendre la valeur 0, i.e.

intersection du polyedre defini par ps avec l'hyperplan var=0; on suppose que cette intersection est non vide (la faisabilite n'est pas testee).

le systeme initial ps est transforme par effet de bord.

Definition at line 251 of file sc_eval.c.

254 {
255  Pcontrainte pc, pcs, pcp;
256 
257  pc = ps->egalites;
258  pcp = (Pcontrainte) NULL;
259  while (pc != (Pcontrainte) NULL) {
260  vect_erase_var(&(pc->vecteur), var);
261  pcs = pc->succ;
262  if (contrainte_constante_p(pc)) {
263  if (pcp == (Pcontrainte) NULL) {
264  ps->egalites = pcs;
265  }
266  else {
267  pcp->succ = pcs;
268  }
269  ps->nb_eq -= 1;
270  contrainte_free(pc);
271  }
272  else {
273  pcp = pc;
274  }
275  pc = pcs;
276  }
277 
278  pc = ps->inegalites;
279  pcp = (Pcontrainte) NULL;
280  while (pc != (Pcontrainte) NULL) {
281  vect_erase_var(&(pc->vecteur), var);
282  pcs = pc->succ;
283  if (contrainte_constante_p(pc)) {
284  if (pcp == (Pcontrainte) NULL) {
285  ps->inegalites = pcs;
286  }
287  else {
288  pcp->succ = pcs;
289  }
290  ps->nb_ineq -= 1;
291  contrainte_free(pc);
292  }
293  else {
294  pcp = pc;
295  }
296  pc = pcs;
297  }
298 }
struct Scontrainte * Pcontrainte
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
bool contrainte_constante_p(Pcontrainte)
bool contrainte_constante_p(Pcontrainte c): test de contrainte triviale sans variables (ie du type 0<...
Definition: predicats.c:192
Pvecteur vecteur
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
Pcontrainte egalites
Definition: sc-local.h:70
void vect_erase_var(Pvecteur *ppv, Variable v)
void vect_erase_var(Pvecteur * ppv, Variable v): projection du vecteur *ppv selon la direction v (i....
Definition: unaires.c:106

References contrainte_constante_p(), contrainte_free(), Scontrainte::succ, vect_erase_var(), and Scontrainte::vecteur.

Referenced by loop_bounds_to_tile_bounds(), make_scanning_over_one_tile(), and TestDiVariables().

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

◆ sc_minmax_of_variable()

bool sc_minmax_of_variable ( Psysteme  ps,
Variable  var,
Value pmin,
Value pmax 
)

void sc_minmax_of_variable(Psysteme ps, Variable var, Value *pmin, *pmax): examine un systeme pour trouver le minimum et le maximum d'une variable apparaissant dans ce systeme par projection a la Fourier-Motzkin.

la procedure retourne la valeur false si le systeme est infaisable et true sinon

le systeme ps est detruit.

projection sur toutes les variables sauf var

cette contrainte nous donne une borne max

cette contrainte nous donne une borne min

Definition at line 143 of file sc_eval.c.

147 {
148  Value val;
149  Pcontrainte pc;
150  Pbase b=VECTEUR_NUL;
151 
152  assert(var!=TCST);
153 
154  *pmax = VALUE_MAX;
155  *pmin = VALUE_MIN;
156  if (SC_EMPTY_P(ps)) return false;
157  if (sc_rn_p(ps)) return true;
158 
159  if (sc_value_of_variable(ps, var, &val) == true) {
160  *pmin = val;
161  *pmax = val;
162  return true;
163  }
164 
165  /* projection sur toutes les variables sauf var */
166  for (b = vect_copy(ps->base); !sc_rn_p(ps) && !SC_EMPTY_P(ps) && !VECTEUR_NUL_P(b) ; b = b->succ) {
167  Variable v = vecteur_var(b);
168  if (!sc_rn_p(ps) && !SC_EMPTY_P(ps) && v != var) {
169  ps = sc_projection(ps, v);
170  // if (!sc_rn_p(ps) && !SC_EMPTY_P(ps) && !huge_system(ps))
172  if (!sc_rn_p(ps) && !SC_EMPTY_P(ps) && !huge_system(ps))
173  ps = sc_normalize(ps);
174  }
175  }
176  vect_rm(b);
177  if (SC_EMPTY_P(ps)) return false;
178  if (sc_value_of_variable(ps, var, &val) == true) {
179  *pmin = val;
180  *pmax = val;
181  return true;
182  }
183 
184  for (pc = ps->inegalites; pc != NULL; pc = pc->succ) {
185  Value cv = vect_coeff(var, pc->vecteur);
187 
188  if (value_pos_p(cv)) {
189  /* cette contrainte nous donne une borne max */
190  Value bs = value_pdiv(cc,cv);
191  if (value_lt(bs,*pmax))
192  *pmax = bs;
193  }
194  else if (value_neg_p(cv)) {
195  /* cette contrainte nous donne une borne min */
196  Value bi = value_pdiv(cc,cv);
197  if (value_gt(bi,*pmin))
198  *pmin = bi;
199  }
200  }
201  if (value_lt(*pmax,*pmin))
202  return false;
203 
204  return true;
205 }
#define value_pos_p(val)
#define value_gt(v1, v2)
#define value_pdiv(v1, v2)
#define value_uminus(val)
unary operators on values
#define VALUE_MIN
int Value
#define VALUE_MAX
#define value_lt(v1, v2)
#define value_neg_p(val)
#define assert(ex)
Definition: newgen_assert.h:41
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_elim_double_constraints(Psysteme ps)
Psysteme sc_elim_double_constraints(Psysteme ps): elimination des egalites et des inegalites identiqu...
static bool huge_system(Psysteme ps)
Definition: sc_eval.c:46
bool sc_value_of_variable(Psysteme ps, Variable var, Value *pval)
bool sc_value_for_variable(Psysteme ps, Variable var, Value *pval): examine les egalites du systeme p...
Definition: sc_eval.c:70
Psysteme sc_normalize(Psysteme ps)
Psysteme sc_normalize(Psysteme ps): normalisation d'un systeme d'equation et d'inequations lineaires ...
Pbase base
Definition: sc-local.h:75
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 vecteur_var(v)
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
#define VECTEUR_NUL_P(v)
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
Pbase vect_copy(Pvecteur b)
direct duplication.
Definition: alloc.c:240
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78
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 assert, huge_system(), sc_elim_double_constraints(), sc_normalize(), sc_rn_p(), sc_value_of_variable(), Scontrainte::succ, Svecteur::succ, TCST, value_gt, value_lt, VALUE_MAX, VALUE_MIN, value_neg_p, value_pdiv, value_pos_p, value_uminus, vect_coeff(), vect_copy(), vect_rm(), Scontrainte::vecteur, VECTEUR_NUL, VECTEUR_NUL_P, and vecteur_var.

Referenced by do_solve_hardware_constraints_on_nb_proc(), evaluate_var_to_complexity(), expression_and_precondition_to_integer_interval(), integer_expression_and_precondition_to_integer_interval(), integer_value_and_precondition_to_integer_interval(), loop_nest_to_tile(), main(), make_movements_loop_body_wp65(), make_scanning_over_one_tile(), make_scanning_over_tiles(), precondition_minmax_of_value(), sc_find_equalities(), sc_minmax_of_variable2(), sc_minmax_of_variables(), and set_dimensions_of_local_variable_family().

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

◆ sc_minmax_of_variable2()

bool sc_minmax_of_variable2 ( volatile Psysteme  ps,
Variable  var,
Value pmin,
Value pmax 
)

void sc_minmax_of_variable2(Psysteme ps, Variable var, Value *pmin, *pmax): examine un systeme pour trouver le minimum et le maximum d'une variable apparaissant dans ce systeme par projection a la Fourier-Motzkin.

la procedure retourne la valeur false si le systeme est infaisable et true sinon

Le systeme ps est detruit et desalloue..

L'algorithme utilise est different de celui de sc_minmax_of_variable(). Les equations sont tout d'abord utilisees pour decomposer le systeme en un hyper-espace caracterise par un sous-ensemble des equations (par exemple les equations ayant moins de 2 variables) et un polyedre de cet hyperespace caracterise par les inegalites de ps et les egalites qui n'ont pas ete utilisees lors de la projection.

Note:

  • comme on ne teste pas la faisabilite en entiers, il se peut que cette fonction renvoie true et que les deux valeurs min et max n'existent pas vraiment; il faut donc etre sur de la maniere dont on utilise cette fonction; dans le cas de l'evaluation de la valeur d'une variable en un point d'un programme, cela n'a pas d'importance puisque la non-faisabilite (connue ou non) implique que le code est mort. La substitution d'une variable par une valeur n'a donc pas d'importance.
  • on pourrait verifier que var appartient a la base de ps; comme il est trivial mais pas forcement justifie, ce test est laisse a la charge de l'appelant.

Maximum number of variables in an equation used for the projection

no obvious non-feasibility

&& sc_nbre_egalites(ps) != 0

eq might suffer in the substitution...

eq is redundant

Equalities change because of substitutions. Their dimensions may go under the present required dimension, nvar. Hence the non-equality test between d and nvar.

Automatic variables read in a CATCH block need to be declared volatile as specified by the documentation

Does eq define var's value (and min==max)? Let's keep track of this but go on to check feasibility

remember eq was normalized...

Although the value might have been found, go on to check feasibility. This could be optional because it should not matter for any safe use of this function. See Note in function's header.

do not touch ps any more

sc_rm(new_ps);

keep eq

In fact, new_ps is not needed. we simply modify ps

use eq to eliminate a variable except if var value is still unknown. We then do need this equation in ps.

Let's use a variable with coefficient 1 if possible.

This test is not fully used in the curent version since value_found_p==false here. That would change if feasibility had to be checked better.

because of the !CONTRAINTE_NULLE_P() test and because of value_found_p

eq itself is going to be modified in ps. use a copy!

Print ps after projection. This really generates a lot of output on real life systems! But less than the next debug statement...

too early to use this equation eq

If there any hope to use it in the future? Yes, if its dimension is no more than nvar+1 because one of its variable might be substituted. If more variable are substituted, it's dimension is going to go down and it will be counted later... Well this is not true, it will be lost:-(

to be on the safe side till I find a better idea...

The system is not feasible. Stop

This really generates a lot of output on real life system! This is useless. Use previous debugging statement

Try to exploit the inequalities and the equalities left in ps

Exploit the reduction in size

I'm afraid of sc_minmax_of_variable() behavior... The guard should be useless

Definition at line 330 of file sc_eval.c.

332 {
333 /* Maximum number of variables in an equation used for the projection */
334 #define level (2)
335 
336 #define if_debug_sc_minmax_of_variable2 if(false)
337 
338  volatile bool feasible_p = true;
339 
341  fprintf(stderr, "[sc_minmax_of_variable2]: Begin\n");
342  }
343 
344  if(SC_UNDEFINED_P(ps)) {
346  fprintf(stderr,
347  "[sc_minmax_of_variable2]: Empty system as input\n");
348  }
349  feasible_p = false;
350  }
351  else if(SC_EMPTY_P(ps = sc_normalize(ps))) {
353  fprintf(stderr,
354  "[sc_minmax_of_variable2]:"
355  " Non-feasibility detected by first call to sc_normalize\n");
356  }
357  feasible_p = false;
358  }
359  else { /* no obvious non-feasibility */
363  volatile int nvar;
364  volatile int neq = sc_nbre_egalites(ps);
365 
367  fprintf(stderr,
368  "[sc_minmax_of_variable2]: After call to sc_normalize\n");
369  fprintf(stderr, "[sc_minmax_of_variable2]: Input system %p\n",
370  ps);
371  sc_dump(ps);
372  }
373 
374  /*
375  * Solve the equalities (if any)
376  *
377  * Start with equalities with the smallest number of variables
378  * and stop when all equalities have been used and or when
379  * all equalities left have too many variables.
380  *
381  * Equalities with no variable are checked although nvar starts
382  * with 1.
383  */
384  for(nvar = 1;
385  feasible_p && neq > 0 && nvar <= level /* && sc_nbre_egalites(ps) != 0 */;
386  nvar++) {
387  for(eq = sc_egalites(ps);
388  feasible_p && !CONTRAINTE_UNDEFINED_P(eq);
389  eq = next_eq) {
390 
391  /* eq might suffer in the substitution... */
392  next_eq = contrainte_succ(eq);
393 
394  if(egalite_normalize(eq)) {
395  if(CONTRAINTE_NULLE_P(eq)) {
396  /* eq is redundant */
397  ;
398  }
399  else {
400  /* Equalities change because of substitutions.
401  * Their dimensions may go under the present
402  * required dimension, nvar. Hence the non-equality
403  * test between d and nvar.
404  */
406 
407  if(d<=nvar) {
409  /* Automatic variables read in a CATCH block need
410  * to be declared volatile as
411  * specified by the documentation*/
412  Variable volatile v = TCST;
413  Variable v1 = TCST;
414  Variable v2 = TCST;
415  Variable nv = TCST;
417  bool value_found_p = false;
418 
419  /* Does eq define var's value (and min==max)?
420  * Let's keep track of this but go on to check
421  * feasibility
422  */
423  if(d==1) {
424  if(!VECTEUR_UNDEFINED_P(pv->succ)) {
425  /* remember eq was normalized... */
426  if ((pv->var == var) &&
427  (pv->succ->var == TCST)) {
428  *pmin = value_uminus
430  val_of(pv)));
431  *pmax = *pmin;
432  value_found_p = true;
433  }
434  else if ((pv->succ->var == var) &&
435  (pv->var == TCST)) {
436  *pmin = value_uminus
437  (value_div(val_of(pv),
438  val_of(vecteur_succ(pv))));
439  *pmax = *pmin;
440  value_found_p = true;
441  }
442  else {
443  value_found_p = false;
444  }
445  }
446  else {
447  if (pv->var == var) {
448  *pmin = VALUE_ZERO;
449  *pmax = *pmin;
450  value_found_p = true;
451  }
452  else {
453  value_found_p = false;
454  }
455  }
456  }
457  /* Although the value might have been found, go on to
458  * check feasibility. This could be optional because
459  * it should not matter for any safe use of this
460  * function. See Note in function's header.
461  */
462  if(value_found_p) {
463  /* do not touch ps any more */
464  /* sc_rm(new_ps); */
465  return true;
466  }
467 
468  /* keep eq */
469  /* In fact, new_ps is not needed. we simply modify ps */
470  /*
471  new_eq = contrainte_dup(eq);
472  sc_add_egalite(new_ps, new_eq);
473  */
474 
475  /* use eq to eliminate a variable except if var value
476  * is still unknown. We then do need this equation in ps.
477  */
478 
479  /* Let's use a variable with coefficient 1 if
480  * possible.
481  */
482  v1 = TCST;
483  v2 = TCST;
484  for( pv = contrainte_vecteur(eq);
485  !VECTEUR_NUL_P(pv);
486  pv = vecteur_succ(pv)) {
487  nv = vecteur_var(pv);
488  /* This test is not fully used in the curent
489  * version since value_found_p==false here.
490  * That would change if feasibility had to
491  * be checked better.
492  */
493  if(nv!=TCST && (nv!=var||value_found_p)) {
494  v2 = (v2==TCST)? nv : v2;
495  if(value_one_p(vecteur_val(pv))) {
496  if(v1==TCST) {
497  v1 = nv;
498  break;
499  }
500  }
501  }
502  }
503  v = (v1==TCST)? v2 : v1;
504  /* because of the !CONTRAINTE_NULLE_P() test and because
505  * of value_found_p */
506  assert(v!=TCST);
507  assert(v!=var||value_found_p);
508 
509  /* eq itself is going to be modified in ps.
510  * use a copy!
511  */
512  def = contrainte_dup(eq);
514  ps=sc_elim_var(ps,v);
515  }
516  TRY {
517  ps =
518  sc_simple_variable_substitution_with_eq_ofl_ctrl
519  (ps, def, v, NO_OFL_CTRL);
520  contrainte_rm(def);
522  }
523  /* Print ps after projection.
524  * This really generates a lot of output on real life systems!
525  * But less than the next debug statement...
526  */
527  /*
528  if_debug_sc_minmax_of_variable2 {
529  fprintf(stderr,
530  "Print the two systems at each elimination step:\n");
531  fprintf(stderr, "[sc_minmax_of_variable2]: Input system %x\n",
532  (unsigned int) ps);
533  sc_dump(ps);
534  }
535  */
536  }
537  else {
538  /* too early to use this equation eq */
539  /* If there any hope to use it in the future?
540  * Yes, if its dimension is no more than nvar+1
541  * because one of its variable might be substituted.
542  * If more variable are substituted, it's dimension
543  * is going to go down and it will be counted later...
544  * Well this is not true, it will be lost:-(
545  */
546  if(d<=nvar+1) {
547  neq++;
548  }
549  else {
550  /* to be on the safe side till I find a better idea... */
551  neq++;
552  }
553  }
554  }
555  }
556  else {
557  /* The system is not feasible. Stop */
558  feasible_p = false;
559  break;
560  }
561 
562  /* This really generates a lot of output on real life system!
563  * This is useless. Use previous debugging statement */
564  /*
565  if_debug_sc_minmax_of_variable2 {
566  fprintf(stderr,
567  "Print the two systems at each equation check:\n");
568  fprintf(stderr, "[sc_minmax_of_variable2]: Input system %x\n",
569  (unsigned int) ps);
570  sc_dump(ps);
571  }
572  */
573  }
574 
576  fprintf(stderr,
577  "Print the two systems at each nvar=%d step:\n", nvar);
578  fprintf(stderr, "[sc_minmax_of_variable2]: Input system %p\n",
579  ps);
580  sc_dump(ps);
581  }
582  }
583 
584  assert(!feasible_p ||
586 
587  feasible_p = feasible_p && !SC_EMPTY_P(ps = sc_normalize(ps));
588 
589  if(feasible_p) {
590  /* Try to exploit the inequalities and the equalities left in ps */
591 
592  /* Exploit the reduction in size */
593  base_rm(sc_base(ps));
594  sc_base(ps) = BASE_UNDEFINED;
595  sc_creer_base(ps);
596 
598  fprintf(stderr,
599  "Print System ps after projection and normalization:\n");
600  fprintf(stderr, "[sc_minmax_of_variable2]: Input system ps %p\n",
601  ps);
602  sc_dump(ps);
603  }
604 
605  if(base_contains_variable_p(sc_base(ps), var)) {
606  feasible_p = sc_minmax_of_variable(ps, var, pmin, pmax);
607  ps = SC_UNDEFINED;
608  }
609  else {
610  *pmin = VALUE_MIN;
611  *pmax = VALUE_MAX;
612  }
613  }
614  }
615 
616  if(!feasible_p) {
617  *pmin = VALUE_MIN;
618  *pmax = VALUE_MAX;
619  }
620  else {
621  /* I'm afraid of sc_minmax_of_variable() behavior...
622  * The guard should be useless
623  */
624  if(!SC_UNDEFINED_P(ps)) {
625  sc_rm(ps);
626  }
627  }
628 
630  fprintf(stderr,
631  "[sc_minmax_of_variable2]: feasible=%d, min=", feasible_p);
632  fprint_Value(stderr, *pmin);
633  fprintf(stderr, ", max=");
634  fprint_Value(stderr, *pmax);
635  fprintf(stderr, "\n[sc_minmax_of_variable2]: End\n");
636  }
637 
638  return feasible_p;
639 }
#define CATCH(what)
@ overflow_error
#define UNCATCH(what)
#define TRY
#define VALUE_ZERO
#define value_one_p(val)
#define value_div(v1, v2)
void fprint_Value(FILE *, Value)
Definition: io.c:42
bool base_contains_variable_p(Pbase b, Variable v)
bool base_contains_variable_p(Pbase b, Variable v): returns true if variable v is one of b's elements...
Definition: base.c:136
#define CONTRAINTE_UNDEFINED_P(c)
#define CONTRAINTE_NULLE_P(c)
contrainte nulle (non contrainte 0 == 0 ou 0 <= 0)
#define contrainte_succ(c)
#define contrainte_vecteur(c)
passage au champ vecteur d'une contrainte "a la Newgen"
#define CONTRAINTE_UNDEFINED
#define contrainte_rm(c)
the standard xxx_rm does not return a value
Pcontrainte contrainte_dup(Pcontrainte c_in)
Pcontrainte contrainte_dup(Pcontrainte c_in): allocation d'une contrainte c_out prenant la valeur de ...
Definition: alloc.c:132
bool egalite_normalize(Pcontrainte)
bool egalite_normalize(Pcontrainte eg): reduction d'une equation diophantienne par le pgcd de ses coe...
Definition: normalize.c:136
int vect_dimension(Pvecteur v)
int vect_dimension(Pvecteur v): calcul du nombre de composantes non nulles et non constantes d'un vec...
Definition: reductions.c:64
void sc_creer_base(Psysteme ps)
void sc_creer_base(Psysteme ps): initialisation des parametres dimension et base d'un systeme lineair...
Definition: sc_alloc.c:129
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
#define if_debug_sc_minmax_of_variable2
bool sc_minmax_of_variable(Psysteme ps, Variable var, Value *pmin, Value *pmax)
void sc_minmax_of_variable(Psysteme ps, Variable var, Value *pmin, *pmax): examine un systeme pour tr...
Definition: sc_eval.c:143
#define level
Pcontrainte eq
element du vecteur colonne du systeme donne par l'analyse
Definition: sc_gram.c:108
void sc_dump(Psysteme sc)
void sc_dump(Psysteme sc): dump to stderr
Definition: sc_io.c:142
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
Psysteme sc_elim_var(Psysteme sc, Variable v)
package sur les systemes de contraintes sc
Definition: sc_unaires.c:49
Variable var
Definition: vecteur-local.h:90
#define vecteur_val(v)
#define val_of(varval)
#define NO_OFL_CTRL
#define vecteur_succ(v)
#define base_rm(b)
#define BASE_UNDEFINED
#define VECTEUR_UNDEFINED_P(v)

References assert, base_contains_variable_p(), base_rm, BASE_UNDEFINED, CATCH, contrainte_dup(), CONTRAINTE_NULLE_P, contrainte_rm, contrainte_succ, CONTRAINTE_UNDEFINED, CONTRAINTE_UNDEFINED_P, contrainte_vecteur, egalite_normalize(), eq, fprint_Value(), fprintf(), if_debug_sc_minmax_of_variable2, level, NO_OFL_CTRL, overflow_error, sc_creer_base(), sc_dump(), sc_elim_var(), sc_minmax_of_variable(), sc_normalize(), sc_rm(), Svecteur::succ, TCST, TRY, UNCATCH, val_of, value_div, VALUE_MAX, VALUE_MIN, value_one_p, value_uminus, VALUE_ZERO, Svecteur::var, vect_dimension(), VECTEUR_NUL_P, vecteur_succ, VECTEUR_UNDEFINED_P, vecteur_val, and vecteur_var.

Referenced by partial_eval_reference().

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

◆ sc_minmax_of_variables()

void sc_minmax_of_variables ( Psysteme  ps1,
Psysteme  ps2,
Pbase  b 
)

This function uses sc_minmax_of_variable to compute the min and max of each variable belonging to base b.

If constraints on the variable are found, they are added to the systeme ps2.

Definition at line 212 of file sc_eval.c.

215 {
216  Pvecteur pv;
217  assert(ps2);
218 
219  for (pv = b; !VECTEUR_NUL_P(pv); pv = pv->succ) {
220  Variable var1 = vecteur_var(pv);
221  Psysteme sc = sc_dup(ps1);
222  Value min, max;
223  bool faisable = sc_minmax_of_variable(sc, var1, &min, &max);
224  Pcontrainte pc;
225 
226  if (faisable) {
227  if (value_ne(min,VALUE_MIN))
228  {
230  VECTEUR_NUL, var1, VALUE_MONE, TCST, min));
231  sc_add_ineg(ps2, pc);
232  }
233  if (value_ne(max,VALUE_MAX))
234  {
237  sc_add_ineg(ps2, pc);
238  }
239  }
240  }
241 }
#define VALUE_MONE
#define value_ne(v1, v2)
#define VALUE_ONE
Pcontrainte contrainte_make(Pvecteur pv)
Pcontrainte contrainte_make(Pvecteur pv): allocation et initialisation d'une contrainte avec un vecte...
Definition: alloc.c:73
#define min(a, b)
#define max(a, b)
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
Pvecteur vect_make(Pvecteur v, Variable var, Value val,...)
Pvecteur vect_make(v, [var, val,]* 0, val) Pvecteur v; // may be NULL, use assigne anyway Variable va...
Definition: alloc.c:165

References assert, contrainte_make(), max, min, sc_dup(), sc_minmax_of_variable(), Svecteur::succ, TCST, VALUE_MAX, VALUE_MIN, VALUE_MONE, value_ne, VALUE_ONE, value_uminus, vect_make(), VECTEUR_NUL, VECTEUR_NUL_P, and vecteur_var.

Referenced by movement_computation().

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

◆ sc_value_of_variable()

bool sc_value_of_variable ( Psysteme  ps,
Variable  var,
Value pval 
)

bool sc_value_for_variable(Psysteme ps, Variable var, Value *pval): examine les egalites du systeme ps pour recherche une egalite de la forme:

coeff*var - cste == 0

Si une telle equation est trouvee et si elle est faisable, sc_value_for_variable calcule la valeur de var pour ce systeme et la retourne par pval. Sinon, la procedure renvoie la valeur false.

Notes:

  • le vecteur representant l'equation est suppose correct: une variable dont le coefficient est nul ne doit pas etre materialisee
  • ce n'est pas une fonction sur les systemes mais sur les listes d'egalites
  • la valeur false peut signifer que le systeme d'egalites de ps n'est pas faisable ou qu'il n'y a pas d'equation satisfaisante; l'arret par sc_error() en cas de non-faisabilite n'etait pas satisfaisant pour les procedures appelantes

equation de la forme: k*var == 0

equation de la forme: k*var - c == 0

equation de la forme: c - k*var == 0

Definition at line 70 of file sc_eval.c.

74 {
75  Pcontrainte pc;
76 
77  if (SC_UNDEFINED_P(ps))
78  return(false);
79 
80  for (pc = ps->egalites; pc != NULL; pc = pc->succ)
81  {
82  Pvecteur pv = pc->vecteur;
83 
84  if (! VECTEUR_NUL_P(pv))
85  {
86  if (pv->succ == NULL)
87  {
88  if (pv->var == var)
89  {
90  /* equation de la forme: k*var == 0 */
91  *pval = 0;
92  return(true);
93  }
94  }
95  else if (pv->succ->succ == NULL)
96  {
97  if ((pv->var == var) && (pv->succ->var == TCST))
98  {
99  Value vs = val_of(pv->succ), v = val_of(pv);
100  /* equation de la forme: k*var - c == 0 */
101  if(value_zero_p(value_mod(vs,v)))
102  {
103  *pval = value_uminus(value_div(vs,v));
104  return(true);
105  }
106  else
107  {
108  return(false);
109  }
110  }
111  else
112  {
113  if ((pv->var == TCST) && (pv->succ->var == var))
114  {
115  Value vs = val_of(pv->succ), v = val_of(pv);
116  /* equation de la forme: c - k*var == 0 */
117  if(value_zero_p(value_mod(v,vs))) {
118  *pval = value_uminus(value_div(v,vs));
119  return(true);
120  }
121  else
122  {
123  return(false);
124  }
125  }
126  }
127  }
128  }
129  }
130 
131  return(false);
132 }
#define value_zero_p(val)
#define value_mod(v1, v2)

References Scontrainte::succ, Svecteur::succ, TCST, val_of, value_div, value_mod, value_uminus, value_zero_p, Svecteur::var, Scontrainte::vecteur, and VECTEUR_NUL_P.

Referenced by sc_minmax_of_variable(), sc_minmax_of_variable_optim(), TestDependence(), and TestDiCnst().

+ Here is the caller graph for this function: