#include "bz_discr.h" #include #define INT_EPS 1e-12 // define SPAM to get trace output #ifdef SPAM #define SPIM #endif // SPIM is more benign int comparedim; double globaldiscr; double fmax(double a,double b) { return ((a)>(b))?(a):(b); } // argument is pointer to pointsetmember, i.e. double **. int cmpkeyk(double **pt1, double **pt2) { double a=(*pt1)[comparedim], b=(*pt2)[comparedim]; if (ab) return 1; return 0; } int intpoints(double **pointset, int dim, int npoints, double *base) { int n=npoints,i,j; for (i=0; i= (base[j]-INT_EPS)) { n--; break; } } } return n; } // Fixes one dimension at a time, each dimension defined by a point (which // must be on the boundary of the box). Maintains list of points that are // still possible (first rempoints points) and smallest base compatible with // earlier dimension choices (boundary points must not be excluded). double int_poly_discr(double **pointset, int dim, int npoints, int rempoints, double *base, int cdim) { double discr,maxdiscr=0.0, basecopy[dim], *ptcopy[rempoints]; int i,j, resort=0; #ifdef SPAM fprintf(stderr, "Dim %d points %d/%d base (%g", cdim, rempoints, npoints, base[0]); for (i=1; i discr. %g\n", discr, (double)intpoints(pointset, dim, rempoints, base)/npoints, (double)rempoints/npoints, maxdiscr); #endif if (maxdiscr > globaldiscr) { globaldiscr=maxdiscr; #ifdef SPIM fprintf(stderr, "Improved to %g\n", globaldiscr); #endif } return maxdiscr; } for (i=cdim; i base[j]) base[j]=pointset[i][j]; } if ((i && (pointset[i-1][cdim] == pointset[i][cdim])) || (((i+1) maxdiscr) maxdiscr=discr; if (resort) { for (j=0; j maxdiscr) maxdiscr=discr; return maxdiscr; } double poly_discr(double **pointset, int dim, int npoints) { double *base, discr; int i; globaldiscr=0; base = malloc(dim*sizeof(double)); for (i=0; i