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));
int * ivector(int nl, int nh)
char circuit_name[NAME_LENGTH]
char output_dir[NAME_LENGTH]
int read_config(char *filename)
void intpickpnts(int, int *)
void nrerror(char *error_text)
char spice_name[NAME_LENGTH]
char opt_num[NAME_LENGTH]
double * vector(int nl, int nh)
int findface(double *, double *)
int generate_jspice_config()
double multiarea(double r, int dim)
char(* names)[NAME_LENGTH]
static double ** aNmatrix
double area(double leftmargin, double rightmargin)
int ** imatrix(int nrl, int nrh, int ncl, int nch)
char opt_ext[NAME_LENGTH]
int addpoint(double *pc, double *po)
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)