/****************************************** Multiplier method using Nelder and Mead's simplex method ******************************************/ #include #include #include #include "opt.h" #define Debug 1 #define Static static static int nvar, nineq, ncond; static dbl *lm, *t; static dbl *mu, *r; static dbl (*objective)(); static dbl *(*inequalities)(); static dbl *(*conditions)(); static dbl *u, **ug, *umat; static dbl *v, **vg, *vmat; static dbl *gvalue, *ga; static dbl *hvalue, *ha; static void initialize() { int i, j; lm = alloc(dbl, nineq); t = alloc(dbl, nineq); for (i=0; i= 0.00) { sum += (lm[i] + 0.5*t[i]*u[i])*u[i]; } else { sum += (-0.5)*lm[i]*lm[i]/t[i]; } } (*conditions)(n, x, ncond, v); /* vectorfprint(stderr, ncond, v); */ for (j=0; j= b) { return (a); } else { return (b); } } static dbl vectormax(int size, dbl *d) /* max d[k] */ { int k; dbl max; max = d[0]; for (k=0; k= max) { max = d[k]; } } return max; } /* the following values are used for the minimization process by quasi-Newton method of extended function L(x,mu) */ static int timeoutn = 1000; static dbl epsn = 1.0e-20; extern void MultiplierMethodSimplexSetConsts(int tm, dbl ep) { timeoutn = tm; epsn = ep; } extern status MultiplierMethodSimplex(n, f, m, g, l, h, x, length, timeout, eps) int n, m, l; dbl (*f)(), *(*g)(), *(*h)(); dbl x[]; dbl length; int timeout; dbl eps; { int count, i, j; dbl alpha = 10, beta = 0.25, c = MAXFLOAT; dbl lopt, gmax, hmax, betac; status s, stat; nvar = n; nineq = m; ncond = l; objective = f; inequalities = g; conditions = h; initialize(); stat = failure; for (count=0; count 1 fprintf(stderr, "gmax = %lf hmax = %lf\n", gmax, hmax); fprintf(stderr, "------------------------------------\n"); #endif if (gmax <= c && hmax <= c) { /* Updating c */ if ((c = fmax( gmax, hmax )) < eps) { stat = success; break; /* return(success); */ } /* Updating lambda and mu */ for (i=0; i betac) { t[i] *= alpha; } } for (j=0; j betac) { r[j] *= alpha; } } } fprintf(stderr, "***** multi-simp: end *****\n"); /* terminate(); */ return (stat); /* return(failure); */ } /* for the case of no inequaltional conditions */ static void *nullfunction(){} extern status MultiplierMethodSimplexEqConds(n, f, l, h, x, length, timeout, eps) int n, l; dbl (*f)(), *(*h)(); dbl x[]; dbl length; int timeout; dbl eps; { return MultiplierMethodSimplex(n, f, 0, nullfunction, l, h, x, length, timeout, eps); }