58 #define PTR_NIL (INTPTR_MIN+767)
59 #define INFINI (INTPTR_MAX-767)
60 #define NB_INEQ sc->nb_ineq
61 #define NONTCST (vect_coeff(pv->var,sc_base(sc)))
62 #define SIMPL(A,B) {if(A!=1 && B!=1){long I1,J1,K;I1=A,J1=B;while((K=I1%J1)!=0)I1=J1,J1=K;A=A/J1;B=B/J1;if(B<0)A=-A,B=-B;}}
63 #define G(J1,A,B) {long I1,K;if(B>1){I1=A,J1=B;while((K=I1%J1)!=0)I1=J1,J1=K;if(J1<0)J1=-J1;}else J1=B;}
64 #define SIMPLIFIE(FRAC) SIMPL(FRAC.num,FRAC.den)
65 #define NB_EQ sc->nb_eq
66 #define DIMENSION sc->dimension
67 #define NUMERO hashtable[h].numero
70 #define SOLUBLE(N) soluble=N;goto FINSIMPLEX ;
71 #define EGAL1(x) (x.num==x.den)
72 #define EGAL0(x) (x.num==0)
73 #define EGAL(x,y) (x.num==0 && y.num==0 ||x.den!=0 && y.den!=0 && x.num*y.den==x.den*y.num)
74 #define NEGATIF(x) (x.num<0&&x.den>0||x.num>0&&x.den<0)
75 #define POSITIF(x) (x.num>0&&x.den>0||x.num<0&&x.den<0)
76 #define SUP1(x) ((x.num>0) && (x.den>0) && (x.num>x.den)||(x.num<0) && (x.den<0) && (x.den>x.num))
77 #define INF(x,y) (x.num*y.den<x.den*y.num)
78 #define NUL(x) (x.num==0)
79 #define AFF(x,y) {x.num=y.num;x.den=y.den;}
80 #define METINFINI(x) {x.num=INFINI;x.den=1;}
81 #define DIV(x,y,z) {if(y.num==0)x.num=0,x.den=1;else{x.num=y.num*z.den;x.den=y.den*z.num;SIMPLIFIE(x);}}
82 #define MUL(x,y,z) {if(y.num==0||z.num==0)x.num=0,x.den=1;else{x.num=y.num*z.num;x.den=y.den*z.den;SIMPLIFIE(x);}}
84 #define PIVOT(X,A,B,C,D) {if(A.num==0){if(B.num==0||C.num==0||D.den==0)X.num=0, X.den=1;else if(B.den<MAXVAL && C.den<MAXVAL && D.num<MAXVAL){X.num=-B.num*C.num*D.den;X.den=B.den*C.den*D.num;SIMPLIFIE(X);}else{frac uu;if(DEBUG2)printf("++ %d/%d %d/%d %d/%d %d/%d \n",A.num,A.den,B.num,B.den,C.num,C.den,D.num,D.den);MUL(uu,B,C);DIV(X,uu,D);X.num=-X.num;if(DEBUG2)printf("%d/%d\n",X.num,X.den);}} \
85 else if(B.num==0||C.num==0||D.den==0)X.num=A.num,X.den=A.den; \
86 else if(D.num==1&&A.den==1&&B.den==1&&C.den==1)X.den=1,X.num=A.num-B.num*C.num*D.den; \
87 else if(A.den<MAXVAL && B.den<MAXVAL && C.den<MAXVAL && D.num<MAXVAL){X.num=A.num*B.den*C.den*D.num-A.den*B.num*C.num*D.den;X.den=A.den*B.den*C.den*D.num;SIMPLIFIE(X);} \
88 else{frac uu,vv,ww;if(DEBUG2)printf("%d/%d %d/%d %d/%d %d/%d \n",A.num,A.den,B.num,B.den,C.num,C.den,D.num,D.den); \
89 uu.num=B.num;vv.num=C.num;ww.num=D.den;uu.den=B.den;vv.den=C.den;ww.den=D.num; \
90 SIMPL(uu.num,vv.den);SIMPL(uu.num,ww.den);SIMPL(vv.num,uu.den);SIMPL(vv.num,ww.den);SIMPL(ww.num,uu.den);SIMPL(ww.num,vv.den); \
91 vv.num*=uu.num*ww.num;vv.den*=uu.den*ww.den; \
92 SUB(X,A,vv);if(DEBUG2)printf("%d/%d\n",X.num,X.den);}\
94 #define SUB(X,A,B) { \
95 if(A.num==0)X.num=-B.num,X.den=B.den; \
96 else if(B.num==0)X.num=A.num,X.den=A.den; \
97 else if(A.den==1&&B.den==1)X.num=A.num-B.num,X.den=1; \
98 else{long GDEN,AD,BD;AD=A.den,BD=B.den; \
99 if(A.den>B.den)G(GDEN,AD,BD) \
100 else G(GDEN,BD,AD); \
101 if(GDEN!=1)AD=AD/GDEN,BD=BD/GDEN; \
102 X.num=A.num*BD-B.num*AD;X.den=AD*BD; \
103 if(GDEN!=1){SIMPLIFIE(X);SIMPL(X.num,GDEN);X.den=X.den*GDEN;} \
112 typedef struct {
int numero ;
int nature ; } rangee ;
113 typedef struct {
long num ;
long den ; }
f ;
115 rangee ligne[
MAX_VAR] ;
int taille ;
118 f frac0={0,1}, frac1={1,1} ;
123 static struct {
Variable nom;
int numero;
int hash ;
int val ;
int succ ; } hashtable[
MAX_VAR] ;
130 frac rapport1, rapport2, min1, min2,
pivot, quot1, quot2, cc ;
132 long valeur,i,j,k,h, numeroligne ;
135 printf(
" %3.1d/%-3.1d",
x.num,
x.den) ;
141 printf(
"Taille=%2.1d\n",taille) ;
143 for(i=0;i<taille;i++) {
printf(
" %4.1d(%1.1d)",colonne[i].numero,colonne[i].nature) ; }
145 for(i=0;i<taille;i++) {
printf(
" %4.1d(%1.1d)",ligne[i].numero,ligne[i].nature) ;
146 for(j=0;j<taille;j++)
printfrac(t[i][j]) ;
166 while (hashtable[h].nom != 0) {
167 if (hashtable[h].nom==pv->
var) {
174 hashtable[h].succ=premier_hash ;
177 hashtable[h].numero=compteur++ ;
178 hashtable[h].nom=pv->
var ;
183 void pivoter(
int taille, rangee ligne[], rangee colonne[],
f *t[],
192 for(i1=0; i1<taille;i1++)
193 if((i1 != i) && (j1 != j)) {
194 PIVOT(
x,t[i1][j1],t[i1][j],t[i][j1],t[i][j])
196 }
else if((i1 != i) && (j1 == j)) {
199 }
else if(i1==i)
AFF(t[i][j],frac1) ;
201 i1=colonne[j].numero ;
202 colonne[j].numero=ligne[i].numero ;
204 i1=colonne[j].nature ;
205 colonne[j].nature=ligne[i].nature ;
217 if(
NONTCST) { h=entree() ; j++ ; }
220 if(j==1) { ligne[i].nature =
VIDE ;
221 if(hashtable[h].val ==
PTR_NIL)
222 hashtable[h].val =
valeur ;
223 else if(hashtable[h].val !=
valeur)
230 for(pc=sc->
egalites, numeroligne=1 ; pc!=0 ; pc=pc->
succ, numeroligne++ ) {
231 if( ligne[numeroligne].nature==
VIDE ) continue ;
235 t[numeroligne][
NUMERO].den=1 ;
237 else t[numeroligne][0].num= - pv->
val,t[numeroligne][
NUMERO].den=1;
240 dump_table(compteur, ligne, colonne, t) ;
248 t[numeroligne][
NUMERO].den=1 ;
250 else t[numeroligne][0].num= - pv->
val,t[numeroligne][
NUMERO].den=1;
267 if(argc>=2)
for(i=1;i<argc;i++){
268 if((f1 = fopen(argv[i],
"r")) == NULL) {
269 fprintf(stdout,
"Ouverture fichier %s impossible\n",
273 printf(
"systeme initial \n");
275 fprintf(stdout,
"syntaxe correcte dans %s\n",argv[i]);
277 printf(
"Nb_eq %d , Nb_ineq %d, dimension %d\n",
280 printf(
"Systeme infaisable (insoluble) en rationnels\n") ;
281 else {
printf(
"Systeme minimum :\n");
287 fprintf(stderr,
"erreur syntaxe dans %s\n",argv[1]);
295 printf(
"systeme initial \n");
297 fprintf(stdout,
"syntaxe correcte dans %s\n",argv[1]);
299 printf(
"Nb_eq %d , Nb_ineq %d, dimension %d\n",
302 printf(
"Systeme infaisable (insoluble) en rationnels\n") ;
303 else {
printf(
"Systeme minimum :\n");
310 fprintf(stderr,
"erreur syntaxe dans %s\n",argv[1]);
char * variable_default_name(Variable v)
char * variable_default_name(Variable v): returns the name of variable v
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
void pivoter(Psommet sys, Psommet ligne, Variable var, Psommet fonct)
Psysteme sc_empty(Pbase b)
Psysteme sc_empty(Pbase b): build a Psysteme with one unfeasible constraint to define the empty subsp...
Psysteme sc_new(void)
Psysteme sc_new(): alloue un systeme vide, initialise tous les champs avec des valeurs nulles,...
bool sc_empty_p(Psysteme sc)
bool sc_empty_p(Psysteme sc): check if the set associated to sc is the constant sc_empty or not.
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...
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...
#define PIVOT(X, A, B, C, D)
Pivot : x = a - b c / d
Psysteme sc_min(Psysteme sc)
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
main(int argc, char *argv[])
FIN DE sc_min.
void pivot(frac *X, frac A, frac B, frac C, frac D, bool ofl_ctrl)
static int hash(Variable s)
dump_tableau
static void printfrac(frac x)
struct Scontrainte * succ
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Entier valeur(Tableau *tp, int i, int j, Entier D)
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....