# include # include # include # include typedef struct som sommet; struct som { int id; sommet *pt; }; static int s; static int smin; static int taille; static int num; static int den; static int num2; static int subtotala = 0; static int subtotalb = 0; static int *lexsizealpha; static int *maxsizealpha; static int *lexsizebeta; static int *maxsizebeta; static double p; static double borne = 0.0; static double borneinf = 0.0; static double **points; static sommet *superarbre; static sommet **lexalpha; static sommet **lexbeta; static FILE *fichier; /* Declaration of routines. */ int main ( int argc, char *argv[] ); void decomposition ( double *alpha, double *beta, int min, double value ); int explore ( sommet *liste, double *pave, int dim ); int fastexplore ( double *pave, int range, int *maxsize, int *lexsize, sommet **lex, int *subtotal ); static void fileformat ( ); void freetree ( sommet *noeud ); void initlex ( ); void initparameters ( int argc, char *argv[] ); void insertlex ( sommet *noeud, int range, int *maxsize, int *lexsize, sommet **lex ); double lowbound ( int npoints, double volume, double *pave ); static void memory ( ); void quicksort ( sommet *liste, int dim, int l, int r ); void readfile ( char *filename ); sommet *subtree ( sommet *liste, int min, int next, int dim ); void supertree ( ); void traiter ( double *outputalpha, double *outputbeta, int range ); static void usage ( char *nom ); /******************************************************************************/ int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for the star discrepancy bound computation. Modified: 30 September 2003 Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i; int j; double *oalpha; double *obeta; initparameters(argc,argv); readfile(argv[4]); printf("x={\n"); for (i=0;ip) for (i=min;i=pave[i]) { total = 0; break; } } else { total = 0; max = liste[0].id; if (dim==smin) { if (pave[dim]>points[liste[max].id][dim]) total = max; else while (max>=min) { next = (min+max+1)/2; if (points[liste[next].id][dim]=min) { next = ((1+min)*num2+max*num)/den; if (points[liste[next].id][dim]=0;i--) { refnoeud = lex[range][i]; noeud = refnoeud.pt; min = refnoeud.id; max = noeud[0].id; if (min>max) { lexsize[range]--; lex[range][i] = lex[range][lexsize[range]]; *subtotal += min-1; } else { total += min-1; right = 1; while (max>=min) { next = (min+max+1)/2; if (points[noeud[next].id][range]=min) { next = ((1+min)*num2+max*num)/den; if (points[noeud[next].id][range]=1) || (taille<1)) usage(argv[0]); if (argc==7) { num = atoi(argv[5]); den = atoi(argv[6]); if ((num<1) || (den<=num)) usage(argv[0]); } else { num = 1; den = 2; } num2 = den-num; return; } /******************************************************************************/ void insertlex ( sommet *noeud, int range, int *maxsize, int *lexsize, sommet **lex ) /******************************************************************************/ /* Purpose: INSERTLEX inserts an item into the lexicon. Modified: 30 September 2003 Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i = lexsize[range]; if (i==maxsize[range]) { maxsize[range] *= 2; lex[range] = realloc(lex[range],(unsigned)maxsize[range]*sizeof(sommet)); if (lex[range]==NULL) memory(); } lex[range][i].pt = noeud; lex[range][i].id = 1; lexsize[range] = ++i; return; } /******************************************************************************/ double lowbound ( int npoints, double volume, double *pave ) /******************************************************************************/ /* Purpose: LOWBOUND computes the lower bound. Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i; int j; double tmp; if (fabs(volume-((double) npoints/taille))>borneinf) { if (((double) npoints/taille)>volume) { volume = 1.0; for (j=0;jtmp) && (points[i][j]<=pave[j])) tmp = points[i][j]; volume *= tmp; } } else { volume = 1.0; for (j=0;j=pave[j])) tmp = points[i][j]; volume *= tmp; } } return fabs(volume-((double) npoints/taille)); } else return borneinf; } /******************************************************************************/ static void memory ( void ) /******************************************************************************/ /* Purpose: MEMORY prints a message and terminates on memory allocation errors. Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { fprintf(stderr,"Memory allocation problem\n"); exit(EXIT_FAILURE); } /******************************************************************************/ void quicksort ( sommet *liste, int dim, int l, int r ) /******************************************************************************/ /* Purpose: QUICKSORT uses Quicksort to sort an array. Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i = l; int j = r+1; int tmp; double pivot = points[liste[l].id][dim]; while (ipivot); if (j>i) { tmp = liste[i].id; liste[i].id = liste[j].id; liste[j].id = tmp; } } tmp = liste[l].id; liste[l].id = liste[j].id; liste[j].id = tmp; if (l1)) { fprintf(stderr,"PROBLEM: component x(%d,%d) is not in [0,1]\n\n",i+1,j+1); fileformat(); } } } } else { for (i=0;i1)) { fprintf(stderr,"PROBLEM: component x(%d,%d) is not in [0,1]\n\n",i+1,j+1); fileformat(); } } } fclose(fichier); return; } /******************************************************************************/ sommet *subtree ( sommet *liste, int min, int next, int dim ) /******************************************************************************/ /* Purpose: SUBTREE ??? Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i; int aux; int taille; sommet *newarbre; aux = min-1; taille = next-min+1; newarbre = (sommet *) calloc((unsigned) taille+1,sizeof(sommet)); if (newarbre==NULL) memory(); for (i=1;i<=taille;i++) newarbre[i].id=liste[i+aux].id; newarbre[0].id=taille; if (taille>1) quicksort(newarbre,dim,1,taille); return newarbre; } /******************************************************************************/ void supertree ( void ) /******************************************************************************/ /* Purpose: SUPERTREE ??? Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i; superarbre = (sommet *) calloc((unsigned) taille+1,sizeof(sommet)); if (superarbre==NULL) memory(); for (i=1;i<=taille;i++) superarbre[i].id=i-1; superarbre[0].id=taille; quicksort(superarbre,0,1,taille); return; } /******************************************************************************/ void traiter ( double *outputalpha, double *outputbeta, int range ) /******************************************************************************/ /* Purpose: TRAITER ??? Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i; double valpha = 1.0; double vbeta = 1.0; double newborne; int nalpha; int nbeta; for (i=0;iborne) borne = newborne; newborne = vbeta-((double) nalpha/taille); if (newborne>borne) borne = newborne; borneinf = lowbound(nalpha,valpha,outputalpha); borneinf = lowbound(nbeta,vbeta,outputbeta); return; } /******************************************************************************/ static void usage ( char *nom ) /******************************************************************************/ /* Purpose: USAGE prints a usage message. Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { fprintf(stderr,"Usage : %s s epsilon n Filename Num Den\n",nom); fprintf(stderr," Dimension s>=2 integer\n"); fprintf(stderr," Accuracy parameter 0=1 integer\n"); fprintf(stderr," Filename (the file must contain at least n points)\n"); fprintf(stderr," (Optional integer balance parameters Num and Den\n"); fprintf(stderr," such that 0