4 #define STEP (param.accuracy/200.0) 6 #define OUT (param.accuracy/200.0) 7 #define DEFINED 1.0e-18 8 #define INSCRIBE 1.0e-8 29 double det(
double **,
int);
30 int simplx(
double **,
int,
int,
int *,
int *);
42 #define OUT_SCREEN_FILE \ 43 printf("%s", outline); \ 44 fprintf(fpout, "%s", outline); 48 if((argc<3) || (argc>4))
57 if((argc==4) && (argv[2][0]!=
'-'))
59 if(strcmp(argv[1],
"-B")==0)
79 double *pc, *po, *facecenter, *radius, *direction;
80 double bound, cbig, c, out, distance, step, dist;
83 int good, count, big, oldcount, lowcount, concave;
84 int iterate=0, direcount=0;
85 double yest1=1.0, yest3=1.0, *ypnt;
86 double gpdf3, gpdf1, total3, total1, ycount3, ycount1, gint3, gint1;
88 long tick, z, seed=-1;
95 printf(
"SYNOPSIS:\n\topt [-B] <circuit_name> <parameter_set_number>\n\n");
100 printf(
"Can't read the '");
118 if ((fp=fopen(
"ITERATE",
"w")) == NULL) {
119 printf(
"Can't write the 'ITERATE' file.\n");
122 fprintf(fp,
"Delete this file to terminate the optimization program intelligently.\n");
139 if ((
fpout=fopen(outfile,
"w")) == NULL) {
140 printf(
"Can't write to the '");
154 for (x=0;
dim+1 >= x; ++x)
157 for (x=1;
dim >= x; ++x)
166 sprintf(
outline,
" Margins: Percent:\n");
168 for (x=1;
dim >= x; ++x) {
169 for (y=1;
dim >= y; ++y)
174 nrerror(
"parameter values failed");
176 sprintf(
outline,
"%s\t%9.5f%s...%9.5f ...",
186 nrerror(
"parameter values failed");
188 sprintf(
outline,
"%9.5f%s -%5.1f +%5.1f\n",
205 sprintf(
outline,
"%i\n", ++iterate);
208 if (!(big=
findface(facecenter, radius))) {
209 sprintf(
outline,
"Could not expand in any critical direction.\n");
218 for (x=1;
dim >= x; ++x) {
224 for (x=1;
dim >= x; ++x) {
228 sprintf(
outline,
"\ndirection ");
230 for (x=1;
dim >= x; ++x) {
231 sprintf(
outline,
"%9.3f ",c=-
ab[big][x]);
240 for (x=1;
dim >= x; ++x) {
242 if ((c=
ab[big][x]/(facecenter[x]-bound)) > cbig)
249 for (x=2;
dim >= x; ++x)
253 for (x=1;
dim >= x; ++x) {
254 out=facecenter[x]-2*step*
ab[big][x];
259 sprintf(
outline,
"Could not expand in above direction.\n");
264 for (x=1;
dim >= x; ++x) {
265 pc[x]=facecenter[x]-step*
ab[big][x];
266 po[x]=facecenter[x]-ab[big][x]/cbig-
OUT/
scale[x]*ab[big][x];
272 sprintf(
outline,
"New point is not outside hull.\n");
276 sprintf(
outline,
"new point ");
278 for (x=1;
dim >= x; ++x) {
288 for (y=1; oldcount >= y; ++y) {
290 for (x=1;
dim >= x; ++x)
292 if (distance < 0.0) {
298 for (xx=1; oldcount >= xx; ++xx) {
300 for (x=1; x <=
dim; ++x) {
301 for (y=1; y <=
dim; ++y)
302 pntstack[y] =
abpnts[xx][y];
312 for (y=1; oldcount >= y; ) {
314 for (x=0;
dim >= x; ++x) {
325 sprintf(
outline,
"hull planes: %i deleted, %i added, %i total\n",oldcount-lowcount,
plncount-lowcount,
plncount);
331 sprintf(
outline,
"Number of iterations equals MAX_ITER.\n");
336 sprintf(
outline,
"Number of hull planes exceeds MAX_PLANE.\n");
340 if (!(
stop>=2)&&(radius[0] - radius[
dim+1])/radius[0] <
STEP*2) {
342 sprintf(
outline,
"Axes of inscribed ellipse increasing slowly.\n");
345 for (x=
dim+1; 1 <= x; --x)
346 radius[x]=radius[x-1];
350 if ((fp=fopen(
"ITERATE",
"r")) == NULL) {
352 sprintf(
outline,
"The ITERATE file was deleted.\n");
358 sprintf(
outline,
"\nResults.");
365 for (x=1;
dim >= x; ++x) {
371 for (x=1;
dim >= x; ++x) {
375 sprintf(
outline,
"\nAVE DIRECTION ");
377 for (x=1;
dim >= x; ++x) {
378 sprintf(
outline,
"%5.3f ",sqrt(direction[x]/direcount));
382 sprintf(
outline,
"\n\ncriticalness ");
384 for (x=1;
dim >= x; ++x) {
386 for (y=1;
dim+1-
pin >= y; ++y)
387 direction[x] +=(
ab[tang[y]][x])*(
ab[tang[y]][x]);
388 sprintf(
outline,
"%6.3f ",sqrt(direction[x]/(
dim+1-pin)));
393 sprintf(
outline,
"\n\ndistance to boundary (normalized) ... critical direction\n");
395 for (y=1;
dim+1-
pin >= y; ++y) {
396 for (x=1;
dim >= x; ++x) {
399 for (xx=1;
dim >= xx; ++xx) {
400 bound=((
ab[tang[y]][xx] > 0.0) ?
lower[xx] :
upper[xx]);
401 if ((c=
ab[tang[y]][xx]/(
centerpnt[xx]-bound)) > cbig)
410 nrerror(
"parameter values failed");
413 for (x=1;
dim >= x; ++x)
416 sprintf(
outline,
"%6.4f ... ",(dist/radius[0]));
418 for (x=1;
dim >= x; ++x) {
419 sprintf(
outline,
"%7.3f ",-
ab[tang[y]][x]);
430 sprintf(
outline,
"Yield calculation for parameter(s):\t");
432 for (x=1;
dim >= x; ++x)
if (
yield[x]) {
437 sprintf(
outline,
"\nAssuming 1 sigma variations of :\t");
439 for (x=1;
dim >= x; ++x)
if (
yield[x]) {
450 total3=total1=ycount3=ycount1=0.0;
451 for (z=1; 10000 >= z && tick <= 1000 && (z-tick) <= 1000; ++z) {
454 for (x=1;
dim >= x; ++x) {
459 for (y=1;
plncount >= y && !outside; ++y) {
461 for (x=1;
dim >= x; ++x)
462 distance +=
ab[y][x]*ypnt[x];
463 if (distance < 0.0) outside=1;
474 for (x=1;
dim >= x; ++x) {
478 sprintf(
outline,
"\nYield within ellipse, yield within hull: %7.3f %5.1f",100.0*yest3,100.0*gint3*(ycount3/total3));
480 sprintf(
outline,
"\n\nAssuming 1 sigma variations of :\t");
482 for (x=1;
dim >= x; ++x)
if (
yield[x]) {
487 sprintf(
outline,
"\nYield within ellipse, yield within hull: %7.3f %5.1f\n\n",100.0*yest1,100.0*gint1*(ycount1/total1));
506 for (y=0;
dim >= y; ++y)
510 tab[1][x+1]=-
ab[x][0];
511 for (x=1;
pin >= x; ++x) {
517 tab[
dim+2][x+1]=-1.0;
521 for (y=1;
dim >= y; ++y)
523 tab[y+1][x+1]=
ab[x][y];
524 for (y=1;
dim >= y; ++y)
525 for (x=1; pin >= x; ++x) {
531 nrerror(
"inscribing in hull failed");
532 radius[0]=-tab[1][1];
533 for (y=1;
dim >= y; ++y)
538 for (y=1;
dim+1 >= y; ++y)
551 double cos, facevalue=0.0;
552 int *right, *left, *tang, *intsect;
553 int x, y, z, fail, plane, yy, share, noshare, count, face=0, tnum;
564 for (y=0;
dim >= y; ++y)
568 tab[1][x+1]=-
ab[x][0];
569 for (x=1;
pin >= x; ++x) {
575 tab[
dim+2][x+1]=-1.0;
579 for (y=1;
dim >= y; ++y)
581 tab[y+1][x+1]=
ab[x][y];
582 for (y=1;
dim >= y; ++y)
583 for (x=1; pin >= x; ++x) {
590 sprintf(
outline,
"Hull simplex failed.\n");
594 radius[0]=-tab[1][1];
595 for (y=1;
dim >= y; ++y)
600 for (y=1;
dim+1 >= y; ++y)
602 if (x+1 >
dim+1-pin) {
603 sprintf(
outline,
"One tangent plane is being ignored\n");
605 }
else tang[++x]=left[y];
607 if ((tnum=x) !=
dim+1-pin) {
608 sprintf(
outline,
"One or more tangent planes are missing.\n");
612 for (z=1; tnum >= z; ++z) {
620 for (y=1; noshare < 2 && dim >= y; ++y) {
622 for (yy=1; !share &&
dim >= yy; ++yy)
624 if (!share) ++noshare;
634 intsect[
dim+1]=plane;
637 for (y=1;
dim >= y; ++y) {
639 for (x=1;
dim >= x; ++x)
640 cos=cos+
ab[intsect[y]][x]*
ab[plane][x];
641 sine[y]=sqrt(1.0 - cos*cos);
643 for (y=0;
dim >= y; ++y)
646 for (x=1;
dim+1 >= x; ++x)
647 tab[1][x+1]=-
ab[intsect[x]][0];
648 for (x=1;
dim+1 >= x; ++x)
649 tab[
dim+2][x+1]=-sine[x];
650 for (y=1;
dim >= y; ++y)
651 for (x=1;
dim+1 >= x; ++x)
652 tab[y+1][x+1]=
ab[intsect[x]][y];
653 for (y=0;
dim+1 >= y; ++y)
654 tab[y+1][
dim+3]=-tab[y+1][
dim+2];
662 if (-tab[1][1] > facevalue) {
663 facevalue=(-tab[1][1]);
665 for (y=1;
dim >= y; ++y)
666 for (x=1;
dim+2 >= x; ++x)
667 if (right[x] == y+
dim+2)
668 centface[y]=-tab[1][x+1];
673 if (
abpnts[plane][0]==1) {
676 for (x=1;
dim >= x; ++x) {
677 sprintf(
outline,
"%9.3f ",-
ab[plane][x]);
680 sprintf(
outline,
"\nCould not expand in above direction.\n");
698 for (pp[depth]=depth*2-1; depth*2 >= pp[depth]; ++pp[depth])
707 double distance, sumsqr, norm;
708 int n, a, y, posd=0, negd=0, pntinpln, def;
711 for (a=1;
dim >= a; ++a)
712 for (y=1;
dim >= y; ++y)
716 for (n=1;
dim >= n; ++n) {
717 for (a=1;
dim >= a; ++a) {
718 for (y=1;
dim >= y; ++y)
730 for (y=1; !(posd && negd) &&
pntcount >= y; y++) {
731 for (a=1; !(pntinpln=(y == pp[a])) &&
dim >= a; a++);
734 for (n=1;
dim >= n; ++n)
736 if (distance >= 0.0) posd=1;
741 if (!(posd && negd)) {
745 for (n=1; n <=
dim; n++)
747 norm=1/(sqrt(sumsqr));
748 for (n=0; n <=
dim; n++)
751 for (n=1; n <=
dim; n++)
754 for (n=0; n <=
dim; n++)
757 for (n=0; n <=
dim; n++)
760 for (n=1; n <=
dim; n++)
int * ivector(int nl, int nh)
char circuit_name[NAME_LENGTH]
double det(double **, int)
char output_dir[NAME_LENGTH]
double ** reallocmatrix(double **oldm, int nrl, int nrh, int newnrh, int ncl, int nch)
int read_config(char *filename)
void free_vector(double *v, int nl, int nh)
void intpickpnts(int, int *)
void nrerror(char *error_text)
int postshift(int *, double *)
int opt_main(int argc, char *argv[])
char spice_name[NAME_LENGTH]
char opt_num[NAME_LENGTH]
double * vector(int nl, int nh)
int findface(double *, double *)
int generate_jspice_config()
void free_ivector(int *v, int nl, int nh)
void free_matrix(double **m, int nrl, int nrh, int ncl, int nch)
double multiarea(double r, int dim)
char(* names)[NAME_LENGTH]
static double ** aNmatrix
double area(double leftmargin, double rightmargin)
int simplx(double **, int, int, int *, int *)
int ** imatrix(int nrl, int nrh, int ncl, int nch)
char opt_ext[NAME_LENGTH]
int addpoint(double *pc, double *po)
static char filename[LINE_LENGTH]
static char outline[LONG_LINE_LENGTH]
static int read_opt_command_line(int argc, char *argv[])
int postcenter(int *, double *)
double uniform_deviate(long *idum)
double ** matrix(int nrl, int nrh, int ncl, int nch)
int ** ireallocmatrix(int **oldm, int nrl, int nrh, int newnrh, int ncl, int nch)