00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <math.h>
00031 #include <assert.h>
00032 #include <stdlib.h>
00033
00034 #include <polylib/polylib.h>
00035
00036
00037
00038
00039
00040
00041
00042
00043 int in_domain(Polyhedron *P, Value *list_args) {
00044
00045 int col,row;
00046 Value v;
00047
00048
00049 if( !P )
00050 return( 0 );
00051
00052 POL_ENSURE_INEQUALITIES(P);
00053
00054 value_init(v);
00055
00056
00057 for(row=0;row<P->NbConstraints;row++) {
00058 value_assign(v,P->Constraint[row][P->Dimension+1]);
00059 for(col=1;col<P->Dimension+1;col++) {
00060 value_addmul(v, P->Constraint[row][col], list_args[col-1]);
00061 }
00062 if (value_notzero_p(P->Constraint[row][0])) {
00063
00064
00065 if (value_neg_p(v)) {
00066 value_clear(v);
00067 return( in_domain(P->next, list_args) );
00068 }
00069 }
00070 else {
00071
00072
00073 if (value_notzero_p(v)) {
00074 value_clear(v);
00075 return( in_domain(P->next, list_args) );
00076 }
00077 }
00078 }
00079
00080
00081 value_clear(v);
00082 return 1;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092 static double compute_enode(enode *p, Value *list_args) {
00093
00094 int i;
00095 Value m, param;
00096 double res=0.0;
00097
00098 if (!p)
00099 return(0.);
00100
00101 value_init(m);
00102 value_init(param);
00103
00104 if (p->type == polynomial) {
00105 if (p->size > 1)
00106 value_assign(param,list_args[p->pos-1]);
00107
00108
00109 for (i=p->size-1;i>0;i--) {
00110 res +=compute_evalue(&p->arr[i],list_args);
00111 res *=VALUE_TO_DOUBLE(param);
00112 }
00113 res +=compute_evalue(&p->arr[0],list_args);
00114 }
00115 else if (p->type == periodic) {
00116 value_assign(m,list_args[p->pos-1]);
00117
00118
00119 value_set_si(param,p->size);
00120 value_pmodulus(m,m,param);
00121 res = compute_evalue(&p->arr[VALUE_TO_INT(m)],list_args);
00122 }
00123 value_clear(m);
00124 value_clear(param);
00125 return res;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135 double compute_evalue(evalue *e,Value *list_args) {
00136
00137 double res;
00138
00139 if (value_notzero_p(e->d)) {
00140 if (value_notone_p(e->d))
00141 res = VALUE_TO_DOUBLE(e->x.n) / VALUE_TO_DOUBLE(e->d);
00142 else
00143 res = VALUE_TO_DOUBLE(e->x.n);
00144 }
00145 else
00146 res = compute_enode(e->x.p,list_args);
00147 return res;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 Value *compute_poly(Enumeration *en,Value *list_args) {
00159
00160 Value *tmp;
00161
00162
00163 tmp = (Value *) malloc (sizeof(Value));
00164 assert(tmp != NULL);
00165 value_init(*tmp);
00166 value_set_si(*tmp,0);
00167
00168 if(!en)
00169 return(tmp);
00170 if(en->ValidityDomain) {
00171 if(!en->ValidityDomain->Dimension) {
00172 value_set_double(*tmp,compute_evalue(&en->EP,list_args)+.25);
00173 return(tmp);
00174 }
00175 }
00176 else
00177 return(tmp);
00178 while(en) {
00179 if(in_domain(en->ValidityDomain,list_args)) {
00180
00181 #ifdef EVAL_EHRHART_DEBUG
00182 Print_Domain(stdout,en->ValidityDomain,NULL);
00183 print_evalue(stdout,&en->EP,NULL);
00184 #endif
00185
00186
00187
00188
00189 value_set_double(*tmp,compute_evalue(&en->EP,list_args)+.25);
00190 return(tmp);
00191 }
00192 else
00193 en=en->next;
00194 }
00195 value_set_si(*tmp,0);
00196 return(tmp);
00197 }
00198
00199
00200
00201