int n, nlopt_func f, void *f_data,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
- double *fmin, /* out: minimum */
- double fmin_max, double ftol_rel, double ftol_abs,
+ double *minf, /* out: minimum */
+ double minf_max, double ftol_rel, double ftol_abs,
double xtol_rel, const double *xtol_abs,
int maxeval, double maxtime)
{
nlopt_stopping stop;
/* some basic argument checks */
- if (n <= 0 || !f || !lb || !ub || !x || !fmin)
+ if (n <= 0 || !f || !lb || !ub || !x || !minf)
return NLOPT_INVALID_ARGS;
d.f = f;
return NLOPT_INVALID_ARGS;
stop.n = n;
- stop.fmin_max = (isnan(fmin_max) || (my_isinf(fmin_max) && fmin_max < 0))
- ? -MY_INF : fmin_max;
+ stop.minf_max = (isnan(minf_max) || (my_isinf(minf_max) && minf_max < 0))
+ ? -MY_INF : minf_max;
stop.ftol_rel = ftol_rel;
stop.ftol_abs = ftol_abs;
stop.xtol_rel = xtol_rel;
case NLOPT_GN_DIRECT:
case NLOPT_GN_DIRECT_L:
case NLOPT_GN_DIRECT_L_RAND:
- return cdirect(n, f, f_data, lb, ub, x, fmin, &stop, 0.0,
+ return cdirect(n, f, f_data, lb, ub, x, minf, &stop, 0.0,
(algorithm != NLOPT_GN_DIRECT)
+ 3 * (algorithm == NLOPT_GN_DIRECT_L_RAND ? 2 : (algorithm != NLOPT_GN_DIRECT))
+ 9 * (algorithm == NLOPT_GN_DIRECT_L_RAND ? 1 : (algorithm != NLOPT_GN_DIRECT)));
case NLOPT_GN_DIRECT_NOSCAL:
case NLOPT_GN_DIRECT_L_NOSCAL:
case NLOPT_GN_DIRECT_L_RAND_NOSCAL:
- return cdirect_unscaled(n, f, f_data, lb, ub, x, fmin,
+ return cdirect_unscaled(n, f, f_data, lb, ub, x, minf,
&stop, 0.0,
(algorithm != NLOPT_GN_DIRECT)
+ 3 * (algorithm == NLOPT_GN_DIRECT_L_RAND ? 2 : (algorithm != NLOPT_GN_DIRECT))
case NLOPT_GN_ORIG_DIRECT:
case NLOPT_GN_ORIG_DIRECT_L:
- switch (direct_optimize(f_direct, &d, n, lb, ub, x, fmin,
+ switch (direct_optimize(f_direct, &d, n, lb, ub, x, minf,
maxeval, -1, 0.0, 0.0,
pow(xtol_rel, (double) n), -1.0,
- stop.fmin_max, 0.0,
+ stop.minf_max, 0.0,
NULL,
algorithm == NLOPT_GN_ORIG_DIRECT
? DIRECT_ORIGINAL
case DIRECT_MAXITER_EXCEEDED:
return NLOPT_MAXEVAL_REACHED;
case DIRECT_GLOBAL_FOUND:
- return NLOPT_FMIN_MAX_REACHED;
+ return NLOPT_MINF_MAX_REACHED;
case DIRECT_VOLTOL:
case DIRECT_SIGMATOL:
return NLOPT_XTOL_REACHED;
case NLOPT_GD_STOGO:
case NLOPT_GD_STOGO_RAND:
- if (!stogo_minimize(n, f, f_data, x, fmin, lb, ub, &stop,
+ if (!stogo_minimize(n, f, f_data, x, minf, lb, ub, &stop,
algorithm == NLOPT_GD_STOGO
? 0 : 2*n))
return NLOPT_FAILURE;
else
scale[i] = 0.01 * x[i] + 0.0001;
}
- iret = subplex(f_subplex, fmin, x, n, &d, &stop, scale);
+ iret = subplex(f_subplex, minf, x, n, &d, &stop, scale);
free(scale);
switch (iret) {
case -2: return NLOPT_INVALID_ARGS;
case -1: return NLOPT_MAXEVAL_REACHED;
case 0: return NLOPT_XTOL_REACHED;
case 1: return NLOPT_SUCCESS;
- case 2: return NLOPT_FMIN_MAX_REACHED;
+ case 2: return NLOPT_MINF_MAX_REACHED;
case 20: return NLOPT_FTOL_REACHED;
case -200: return NLOPT_OUT_OF_MEMORY;
default: return NLOPT_FAILURE; /* unknown return code */
h0 = MIN(h0, 0.01 * x[i] + 0.0001);
}
return praxis_(0.0, DBL_EPSILON, h0, n, x, f_subplex, &d,
- &stop, fmin);
+ &stop, minf);
}
case NLOPT_LD_LBFGS: {
}
}
else {
- *fmin = f(n, x, NULL, f_data);
+ *minf = f(n, x, NULL, f_data);
switch (iret) {
case 5: return NLOPT_MAXEVAL_REACHED;
case 2: return NLOPT_XTOL_REACHED;
int n, nlopt_func f, void *f_data,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
- double *fmin, /* out: minimum */
- double fmin_max, double ftol_rel, double ftol_abs,
+ double *minf, /* out: minimum */
+ double minf_max, double ftol_rel, double ftol_abs,
double xtol_rel, const double *xtol_abs,
int maxeval, double maxtime)
{
nlopt_result ret;
if (xtol_abs)
ret = nlopt_minimize_(algorithm, n, f, f_data, lb, ub,
- x, fmin, fmin_max, ftol_rel, ftol_abs,
+ x, minf, minf_max, ftol_rel, ftol_abs,
xtol_rel, xtol_abs, maxeval, maxtime);
else {
int i;
if (!xtol) return NLOPT_OUT_OF_MEMORY;
for (i = 0; i < n; ++i) xtol[i] = -1;
ret = nlopt_minimize_(algorithm, n, f, f_data, lb, ub,
- x, fmin, fmin_max, ftol_rel, ftol_abs,
+ x, minf, minf_max, ftol_rel, ftol_abs,
xtol_rel, xtol, maxeval, maxtime);
free(xtol);
}
NLOPT_OUT_OF_MEMORY = -3,
NLOPT_SUCCESS = 1, /* generic success code */
- NLOPT_FMIN_MAX_REACHED = 2,
+ NLOPT_MINF_MAX_REACHED = 2,
NLOPT_FTOL_REACHED = 3,
NLOPT_XTOL_REACHED = 4,
NLOPT_MAXEVAL_REACHED = 5,
int n, nlopt_func f, void *f_data,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
- double *fmin, /* out: minimum */
- double fmin_max, double ftol_rel, double ftol_abs,
+ double *minf, /* out: minimum */
+ double minf_max, double ftol_rel, double ftol_abs,
double xtol_rel, const double *xtol_abs,
int maxeval, double maxtime);
.BI " const double* " "lb" ,
.BI " const double* " "ub" ,
.BI " double* " "x" ,
-.BI " double* " "fmin" ,
-.BI " double " "fmin_max" ,
+.BI " double* " "minf" ,
+.BI " double " "minf_max" ,
.BI " double " "ftol_rel" ,
.BI " double " "ftol_abs" ,
.BI " double " "xtol_rel" ,
design variables using the specified
.IR algorithm .
The minimum function value found is returned in
-.IR fmin ,
+.IR minf ,
with the corresponding design variable values returned in the array
.I x
of length
have tried to make them as consistent as reasonably possible), and
some algorithms do not support all of the stopping criteria.
.TP
-.B fmin_max
+.B minf_max
Stop when a function value less than or equal to
-.I fmin_max
+.I minf_max
is found. Set to -Inf or NaN (see constraints section above) to disable.
.TP
.B ftol_rel
.B NLOPT_SUCCESS
Generic success return value.
.TP
-.B NLOPT_FMIN_MAX_REACHED
+.B NLOPT_MINF_MAX_REACHED
Optimization stopped because
-.I fmin_max
+.I minf_max
(above) was reached.
.TP
.B NLOPT_FTOL_REACHED
nlopt_func f; void *f_data;
double *work; /* workspace, of length >= 2*n */
int *iwork; /* workspace, length >= n */
- double fmin, *xmin; /* minimum so far */
+ double minf, *xmin; /* minimum so far */
/* red-black tree of hyperrects, sorted by (d,f,age) in
lexographical order */
static double function_eval(const double *x, params *p) {
double f = p->f(p->n, x, NULL, p->f_data);
- if (f < p->fmin) {
- p->fmin = f;
+ if (f < p->minf) {
+ p->minf = f;
memcpy(p->xmin, x, sizeof(double) * p->n);
}
p->stop->nevals++;
return f;
}
-#define FUNCTION_EVAL(fv,x,p,freeonerr) fv = function_eval(x, p); if (p->fmin < p->stop->fmin_max) { free(freeonerr); return NLOPT_FMIN_MAX_REACHED; } else if (nlopt_stop_evals((p)->stop)) { free(freeonerr); return NLOPT_MAXEVAL_REACHED; } else if (nlopt_stop_time((p)->stop)) { free(freeonerr); return NLOPT_MAXTIME_REACHED; }
+#define FUNCTION_EVAL(fv,x,p,freeonerr) fv = function_eval(x, p); if (p->minf < p->stop->minf_max) { free(freeonerr); return NLOPT_MINF_MAX_REACHED; } else if (nlopt_stop_evals((p)->stop)) { free(freeonerr); return NLOPT_MAXEVAL_REACHED; } else if (nlopt_stop_time((p)->stop)) { free(freeonerr); return NLOPT_MAXTIME_REACHED; }
#define THIRD (0.3333333333333333333333)
K1 = (hull[i][1] - hull[ip][1]) / (hull[i][0] - hull[ip][0]);
K = MAX(K1, K2);
if (hull[i][1] - K * hull[i][0]
- <= p->fmin - magic_eps * fabs(p->fmin) || ip == nhull) {
+ <= p->minf - magic_eps * fabs(p->minf) || ip == nhull) {
/* "potentially optimal" rectangle, so subdivide */
nlopt_result ret = divide_rect(hull[i], p);
divided_some = 1;
nlopt_result cdirect_unscaled(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub,
double *x,
- double *fmin,
+ double *minf,
nlopt_stopping *stop,
double magic_eps, int which_alg)
{
p.f = f;
p.f_data = f_data;
p.xmin = x;
- p.fmin = HUGE_VAL;
+ p.minf = HUGE_VAL;
p.work = 0;
p.iwork = 0;
p.hull = 0;
if (ret != NLOPT_SUCCESS) goto done;
while (1) {
- double fmin0 = p.fmin;
+ double minf0 = p.minf;
ret = divide_good_rects(&p);
if (ret != NLOPT_SUCCESS) goto done;
- if (p.fmin < fmin0 && nlopt_stop_f(p.stop, p.fmin, fmin0)) {
+ if (p.minf < minf0 && nlopt_stop_f(p.stop, p.minf, minf0)) {
ret = NLOPT_FTOL_REACHED;
goto done;
}
free(p.iwork);
free(p.work);
- *fmin = p.fmin;
+ *minf = p.minf;
return ret;
}
nlopt_result cdirect(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub,
double *x,
- double *fmin,
+ double *minf,
nlopt_stopping *stop,
double magic_eps, int which_alg)
{
}
xtol_abs_save = stop->xtol_abs;
stop->xtol_abs = d.x + 3*n;
- ret = cdirect_unscaled(n, cdirect_uf, &d, d.x+n, d.x+2*n, x, fmin, stop,
+ ret = cdirect_unscaled(n, cdirect_uf, &d, d.x+n, d.x+2*n, x, minf, stop,
magic_eps, which_alg);
stop->xtol_abs = xtol_abs_save;
for (i = 0; i < n; ++i)
extern nlopt_result cdirect_unscaled(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub,
double *x,
- double *fmin,
+ double *minf,
nlopt_stopping *stop,
double magic_eps, int which_alg);
extern nlopt_result cdirect(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub,
double *x,
- double *fmin,
+ double *minf,
nlopt_stopping *stop,
double magic_eps, int which_alg);
extern nlopt_result cdirect_hybrid(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub,
double *x,
- double *fmin,
+ double *minf,
nlopt_stopping *stop,
nlopt_algorithm local_alg,
int local_maxeval,
extern nlopt_result cdirect_hybrid_unscaled(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub,
double *x,
- double *fmin,
+ double *minf,
nlopt_stopping *stop,
nlopt_algorithm local_alg,
int local_maxeval,
/* | Lipschitz continues. However, DIRECT has proven to be effective on | */
/* | more complex problems than these. | */
/* +-----------------------------------------------------------------------+ */
-/* Subroutine */ void direct_direct_(fp fcn, doublereal *x, integer *n, doublereal *eps, doublereal epsabs, integer *maxf, integer *maxt, doublereal *fmin, doublereal *l,
+/* Subroutine */ void direct_direct_(fp fcn, doublereal *x, integer *n, doublereal *eps, doublereal epsabs, integer *maxf, integer *maxt, doublereal *minf, doublereal *l,
doublereal *u, integer *algmethod, integer *ierror, FILE *logfile,
doublereal *fglobal, doublereal *fglper, doublereal *volper,
doublereal *sigmaper, void *fcn_data)
/* | eps -- Exceeding value. If eps > 0, we use the same epsilon for | */
/* | all iterations. If eps < 0, we use the update formula from | */
/* | Jones: | */
-/* | eps = max(1.D-4*abs(fmin),epsfix), | */
+/* | eps = max(1.D-4*abs(minf),epsfix), | */
/* | where epsfix = abs(eps), the absolute value of eps which is| */
/* | passed to the function. | */
/* | maxf -- The maximum number of function evaluations. | */
/* | fglper -- Terminate the optimization when the percent error | */
/* | 100(f_min - fglobal)/max(1,abs(fglobal)) < fglper. | */
/* | volper -- Terminate the optimization when the volume of the | */
-/* | hyperrectangle S with f(c(S)) = fmin is less then volper | */
+/* | hyperrectangle S with f(c(S)) = minf is less then volper | */
/* | percent of the volume of the original hyperrectangle. | */
/* |sigmaper -- Terminate the optimization when the measure of the | */
-/* | hyperrectangle S with f(c(S)) = fmin is less then sigmaper.| */
+/* | hyperrectangle S with f(c(S)) = minf is less then sigmaper.| */
/* | | */
/* | User data that is passed through without being changed: | */
/* | fcn_data - opaque pointer to any user data | */
/* | X should be a good approximation to the global minimum | */
/* | for the function within the hyper-box. | */
/* | | */
-/* | fmin -- The value of the function at x. | */
+/* | minf -- The value of the function at x. | */
/* | Ierror -- Error flag. If Ierror is lower 0, an error has occured. The| */
/* | values of Ierror mean | */
/* | Fatal errors : | */
/* | 2 Number of iterations is equal to maxT. | */
/* | 3 The best function value found is within fglper of | */
/* | the (known) global optimum, that is | */
-/* | 100(fmin - fglobal/max(1,|fglobal|)) < fglper. | */
+/* | 100(minf - fglobal/max(1,|fglobal|)) < fglper. | */
/* | Note that this termination signal only occurs when | */
/* | the global optimal value is known, that is, a test | */
/* | function is optimized. | */
-/* | 4 The volume of the hyperrectangle with fmin at its | */
+/* | 4 The volume of the hyperrectangle with minf at its | */
/* | center is less than volper percent of the volume of | */
/* | the original hyperrectangle. | */
-/* | 5 The measure of the hyperrectangle with fmin at its | */
+/* | 5 The measure of the hyperrectangle with minf at its | */
/* | center is less than sigmaper. | */
/* | | */
/* | SUBROUTINEs used : | */
/* +-----------------------------------------------------------------------+ */
direct_dirinit_(f, fcn, c__, length, &actdeep, point, anchor, &ifree,
logfile, arrayi, &maxi, list2, w, &x[1], &l[1], &u[1],
- fmin, &minpos, thirds, levels, &MAXFUNC, &MAXDEEP, n, n, &
+ minf, &minpos, thirds, levels, &MAXFUNC, &MAXDEEP, n, n, &
fmax, &ifeasiblef, &iinfesiblef, ierror, fcn_data, jones);
/* +-----------------------------------------------------------------------+ */
/* | Added error checking. | */
/* +-----------------------------------------------------------------------+ */
/* | If no feasible point has been found, give out the iteration, the | */
/* | number of function evaluations and a warning. Otherwise, give out | */
-/* | the iteration, the number of function evaluations done and fmin. | */
+/* | the iteration, the number of function evaluations done and minf. | */
/* +-----------------------------------------------------------------------+ */
if (ifeasiblef > 0) {
if (logfile)
} else {
if (logfile)
fprintf(logfile, "%d, %d, %g, %g\n",
- tstart-1, numfunc, *fmin, fmax);
+ tstart-1, numfunc, *minf, fmax);
}
/* +-----------------------------------------------------------------------+ */
/* +-----------------------------------------------------------------------+ */
/* | in the list S. | */
/* +-----------------------------------------------------------------------+ */
actdeep = actmaxdeep;
- direct_dirchoose_(anchor, s, &MAXDEEP, f, fmin, *eps, epsabs, levels, &maxpos, length,
+ direct_dirchoose_(anchor, s, &MAXDEEP, f, minf, *eps, epsabs, levels, &maxpos, length,
&MAXFUNC, &MAXDEEP, &MAXDIV, n, logfile, &cheat, &
kmax, &ifeasiblef, jones);
/* +-----------------------------------------------------------------------+ */
/* +-----------------------------------------------------------------------+ */
direct_dirsamplepoints_(c__, arrayi, &delta, &help, &start, length,
logfile, f, &ifree, &maxi, point, &x[
- 1], &l[1], fmin, &minpos, &u[1], n, &MAXFUNC, &
+ 1], &l[1], minf, &minpos, &u[1], n, &MAXFUNC, &
MAXDEEP, &oops);
if (oops > 0) {
if (logfile)
/* +-----------------------------------------------------------------------+ */
direct_dirsamplef_(c__, arrayi, &delta, &help, &start, length,
logfile, f, &ifree, &maxi, point, fcn, &x[
- 1], &l[1], fmin, &minpos, &u[1], n, &MAXFUNC, &
+ 1], &l[1], minf, &minpos, &u[1], n, &MAXFUNC, &
MAXDEEP, &oops, &fmax, &ifeasiblef, &iinfesiblef,
fcn_data);
if (oops > 0) {
if (oldpos < minpos) {
if (logfile)
fprintf(logfile, "%d, %d, %g, %g\n",
- t, numfunc, *fmin, fmax);
+ t, numfunc, *minf, fmax);
}
/* +-----------------------------------------------------------------------+ */
/* | If no feasible point has been found, give out the iteration, the | */
/* +-----------------------------------------------------------------------+ */
/* +-----------------------------------------------------------------------+ */
/* | JG 01/22/01 Calculate the index for the hyperrectangle at which | */
-/* | fmin is assumed. We then calculate the volume of this | */
+/* | minf is assumed. We then calculate the volume of this | */
/* | hyperrectangle and store it in delta. This delta can be | */
/* | used to stop DIRECT once the volume is below a certain | */
/* | percentage of the original volume. Since the original | */
}
/* +-----------------------------------------------------------------------+ */
/* | JG 01/23/01 Calculate the measure for the hyperrectangle at which | */
-/* | fmin is assumed. If this measure is smaller then sigmaper,| */
+/* | minf is assumed. If this measure is smaller then sigmaper,| */
/* | we stop DIRECT. | */
/* +-----------------------------------------------------------------------+ */
actdeep_div__ = direct_dirgetlevel_(&minpos, length, &MAXFUNC, n, jones);
/* | global minimum value, terminate. This only makes sense if this optimal| */
/* | value is known, that is, in test problems. | */
/* +-----------------------------------------------------------------------+ */
- if ((*fmin - *fglobal) * 100 / divfactor <= *fglper) {
+ if ((*minf - *fglobal) * 100 / divfactor <= *fglper) {
*ierror = 3;
if (logfile)
- fprintf(logfile, "DIRECT stopped: fmin within fglper of global minimum.\n");
+ fprintf(logfile, "DIRECT stopped: minf within fglper of global minimum.\n");
goto L100;
}
/* +-----------------------------------------------------------------------+ */
/* +-----------------------------------------------------------------------+ */
if (iepschange == 1) {
/* Computing MAX */
- d__1 = fabs(*fmin) * 1e-4;
+ d__1 = fabs(*minf) * 1e-4;
*eps = MAX(d__1,epsfix);
}
/* +-----------------------------------------------------------------------+ */
/* +-----------------------------------------------------------------------+ */
/* | Give out a summary of the run. | */
/* +-----------------------------------------------------------------------+ */
- direct_dirsummary_(logfile, &x[1], &l[1], &u[1], n, fmin, fglobal, &numfunc,
+ direct_dirsummary_(logfile, &x[1], &l[1], &u[1], n, minf, fglobal, &numfunc,
ierror);
/* +-----------------------------------------------------------------------+ */
/* | Format statements. | */
/* | termination signal. | */
/* +-----------------------------------------------------------------------+ */
/* Subroutine */ int direct_pardirect_(fp fcn, doublereal *x, integer *n,
- doublereal *eps, integer *maxf, integer *maxt, doublereal *fmin,
+ doublereal *eps, integer *maxf, integer *maxt, doublereal *minf,
doublereal *l, doublereal *u, integer *algmethod, integer *ierror,
FILE *logfile, doublereal *fglobal, doublereal *fglper, doublereal
*volper, doublereal *sigmaper, void *fcn_data)
/* | Call Direct main routine. This routine calls DIRSamplef for the | */
/* | function evaluations, which are then done in parallel. | */
/* +-----------------------------------------------------------------------+ */
- direct_direct_(fcn, &x[1], n, eps, maxf, maxt, fmin, &l[1], &u[1],
+ direct_direct_(fcn, &x[1], n, eps, maxf, maxt, minf, &l[1], &u[1],
algmethod, ierror, logfile, fglobal, fglper, volper, sigmaper,
fcn_data);
/* +-----------------------------------------------------------------------+ */
*delta, integer *sample, integer *new__, integer *length,
FILE *logfile, doublereal *f, integer *free, integer *maxi,
integer *point, fp fcn, doublereal *x, doublereal *l, doublereal *
- fmin, integer *minpos, doublereal *u, integer *n, integer *maxfunc,
+ minf, integer *minpos, doublereal *u, integer *n, integer *maxfunc,
integer *maxdeep, integer *oops, doublereal *fmax, integer *
ifeasiblef, integer *iinfesiblef, void *fcn_data)
{
/* +-----------------------------------------------------------------------+ */
i__1 = *maxi + *maxi;
for (j = 1; j <= i__1; ++j) {
- if (f[pos + f_dim1] < *fmin && f[pos + (f_dim1 << 1)] == 0.) {
- *fmin = f[pos + f_dim1];
+ if (f[pos + f_dim1] < *minf && f[pos + (f_dim1 << 1)] == 0.) {
+ *minf = f[pos + f_dim1];
*minpos = pos;
}
pos = point[pos];
*delta, integer *sample, integer *new__, integer *length,
FILE *logfile, doublereal *f, integer *free, integer *maxi,
integer *point, fp fcn, doublereal *x, doublereal *l, doublereal *
- fmin, integer *minpos, doublereal *u, integer *n, integer *maxfunc,
+ minf, integer *minpos, doublereal *u, integer *n, integer *maxfunc,
integer *maxdeep, integer *oops, doublereal *fmax, integer *
ifeasiblef, integer *iinfesiblef, void *fcn_data)
{
/* +-----------------------------------------------------------------------+ */
i__1 = *maxi + *maxi;
for (j = 1; j <= i__1; ++j) {
- if (f[(pos << 1) + 1] < *fmin && f[(pos << 1) + 2] == 0.) {
- *fmin = f[(pos << 1) + 1];
+ if (f[(pos << 1) + 1] < *minf && f[(pos << 1) + 2] == 0.) {
+ *minf = f[(pos << 1) + 1];
*minpos = pos;
}
pos = point[pos];
| */
/* +-----------------------------------------------------------------------+ */
/* Subroutine */ void direct_dirchoose_(integer *anchor, integer *s, integer *actdeep,
- doublereal *f, doublereal *fmin, doublereal epsrel, doublereal epsabs, doublereal *thirds,
+ doublereal *f, doublereal *minf, doublereal epsrel, doublereal epsabs, doublereal *thirds,
integer *maxpos, integer *length, integer *maxfunc, integer *maxdeep,
integer *maxdiv, integer *n, FILE *logfile,
integer *cheat, doublereal *kmax, integer *ifeasiblef, integer jones)
helplower = *kmax;
}
if (f[(j___ << 1) + 1] - helplower * thirds[s[j + (s_dim1 << 1)]] >
- MIN(*fmin - epsrel * fabs(*fmin),
- *fmin - epsabs)) {
+ MIN(*minf - epsrel * fabs(*minf),
+ *minf - epsabs)) {
if (logfile)
- fprintf(logfile, "> fmin - epslfminl\n");
+ fprintf(logfile, "> minf - epslminfl\n");
goto L60;
}
} else {
doublereal *delta, integer *sample, integer *start, integer *length,
FILE *logfile, doublereal *f, integer *free,
integer *maxi, integer *point, doublereal *x, doublereal *l,
- doublereal *fmin, integer *minpos, doublereal *u, integer *n,
+ doublereal *minf, integer *minpos, doublereal *u, integer *n,
integer *maxfunc, integer *maxdeep, integer *oops)
{
/* System generated locals */
integer *length, integer *actdeep, integer *point, integer *anchor,
integer *free, FILE *logfile, integer *arrayi,
integer *maxi, integer *list2, doublereal *w, doublereal *x,
- doublereal *l, doublereal *u, doublereal *fmin, integer *minpos,
+ doublereal *l, doublereal *u, doublereal *minf, integer *minpos,
doublereal *thirds, doublereal *levels, integer *maxfunc, integer *
maxdeep, integer *n, integer *maxor, doublereal *fmax, integer *
ifeasiblef, integer *iinfeasible, integer *ierror, void *fcndata,
c__ -= c_offset;
/* Function Body */
- *fmin = 1e20;
- costmin = *fmin;
+ *minf = 1e20;
+ costmin = *minf;
/* JG 09/15/00 If Jones way of characterising rectangles is used, */
/* initialise thirds to reflect this. */
if (jones == 0) {
*ifeasiblef = 0;
}
/* JG 09/25/00 Remove IF */
- *fmin = f[3];
+ *minf = f[3];
costmin = f[3];
*minpos = 1;
*actdeep = 2;
new__ = *free;
direct_dirsamplepoints_(&c__[c_offset], &arrayi[1], &delta, &c__1, &new__, &
length[length_offset], logfile, &f[3], free, maxi, &
- point[1], &x[1], &l[1], fmin, minpos, &u[1], n,
+ point[1], &x[1], &l[1], minf, minpos, &u[1], n,
maxfunc, maxdeep, &oops);
/* +-----------------------------------------------------------------------+ */
/* | JG 01/23/01 Added error checking. | */
/* +-----------------------------------------------------------------------+ */
direct_dirsamplef_(&c__[c_offset], &arrayi[1], &delta, &c__1, &new__, &length[
length_offset], logfile, &f[3], free, maxi, &point[
- 1], fcn, &x[1], &l[1], fmin, minpos, &u[1], n, maxfunc,
+ 1], fcn, &x[1], &l[1], minf, minpos, &u[1], n, maxfunc,
maxdeep, &oops, fmax, ifeasiblef, iinfeasible, fcndata);
/* +-----------------------------------------------------------------------+ */
/* | JG 01/23/01 Added error checking. | */
if (logfile) fprintf(logfile, "----------------------------------\n");
if (*ierror >= 0) {
if (logfile)
- fprintf(logfile, "Iteration # of f-eval. fmin\n");
+ fprintf(logfile, "Iteration # of f-eval. minf\n");
}
/* L10005: */
} /* dirheader_ */
/* Subroutine */ void direct_dirsummary_(FILE *logfile, doublereal *x, doublereal *
- l, doublereal *u, integer *n, doublereal *fmin, doublereal *fglobal,
+ l, doublereal *u, integer *n, doublereal *minf, doublereal *fglobal,
integer *numfunc, integer *ierror)
{
/* Local variables */
if (logfile) {
fprintf(logfile, "-----------------------Summary------------------\n"
"Final function value: %g\n"
- "Number of function evaluations: %d\n", *fmin, *numfunc);
+ "Number of function evaluations: %d\n", *minf, *numfunc);
if (*fglobal > -1e99)
- fprintf(logfile, "Final function value is within %g%% of global optimum\n", 100*(*fmin - *fglobal) / MAX(1.0, fabs(*fglobal)));
+ fprintf(logfile, "Final function value is within %g%% of global optimum\n", 100*(*minf - *fglobal) / MAX(1.0, fabs(*fglobal)));
fprintf(logfile, "Index, final solution, x(i)-l(i), u(i)-x(i)\n");
for (i__ = 1; i__ <= *n; ++i__)
fprintf(logfile, "%d, %g, %g, %g\n", i__, x[i__],
integer *length, integer *actdeep, integer *point, integer *anchor,
integer *free, FILE *logfile, integer *arrayi,
integer *maxi, integer *list2, doublereal *w, doublereal *x,
- doublereal *l, doublereal *u, doublereal *fmin, integer *minpos,
+ doublereal *l, doublereal *u, doublereal *minf, integer *minpos,
doublereal *thirds, doublereal *levels, integer *maxfunc, integer *
maxdeep, integer *n, integer *maxor, doublereal *fmax, integer *
ifeasiblef, integer *iinfeasible, integer *ierror, void *fcndata,
doublereal *xs1, doublereal *xs2, integer *oops);
extern void direct_dirchoose_(
integer *anchor, integer *s, integer *actdeep,
- doublereal *f, doublereal *fmin, doublereal epsrel, doublereal epsabs, doublereal *thirds,
+ doublereal *f, doublereal *minf, doublereal epsrel, doublereal epsabs, doublereal *thirds,
integer *maxpos, integer *length, integer *maxfunc, integer *maxdeep,
integer *maxdiv, integer *n, FILE *logfile,
integer *cheat, doublereal *kmax, integer *ifeasiblef, integer jones);
doublereal *delta, integer *sample, integer *start, integer *length,
FILE *logfile, doublereal *f, integer *free,
integer *maxi, integer *point, doublereal *x, doublereal *l,
- doublereal *fmin, integer *minpos, doublereal *u, integer *n,
+ doublereal *minf, integer *minpos, doublereal *u, integer *n,
integer *maxfunc, integer *maxdeep, integer *oops);
extern void direct_dirdivide_(
integer *new__, integer *currentlength,
FILE *logfile, doublereal *fmax, integer jones);
extern void direct_dirsummary_(
FILE *logfile, doublereal *x, doublereal *l, doublereal *u,
- integer *n, doublereal *fmin, doublereal *fglobal,
+ integer *n, doublereal *minf, doublereal *fglobal,
integer *numfunc, integer *ierror);
extern integer direct_dirgetlevel_(
integer *pos, integer *length,
*delta, integer *sample, integer *new__, integer *length,
FILE *logfile, doublereal *f, integer *free, integer *maxi,
integer *point, fp fcn, doublereal *x, doublereal *l, doublereal *
- fmin, integer *minpos, doublereal *u, integer *n, integer *maxfunc,
+ minf, integer *minpos, doublereal *u, integer *n, integer *maxfunc,
integer *maxdeep, integer *oops, doublereal *fmax, integer *
ifeasiblef, integer *iinfesiblef, void *fcn_data);
/* DIRect.c */
extern void direct_direct_(
fp fcn, doublereal *x, integer *n, doublereal *eps, doublereal epsabs,
- integer *maxf, integer *maxt, doublereal *fmin, doublereal *l,
+ integer *maxf, integer *maxt, doublereal *minf, doublereal *l,
doublereal *u, integer *algmethod, integer *ierror, FILE *logfile,
doublereal *fglobal, doublereal *fglper, doublereal *volper,
doublereal *sigmaper, void *fcn_data);
int dimension,
const double *lower_bounds, const double *upper_bounds,
- double *x, double *fmin,
+ double *x, double *minf,
int max_feval, int max_iter,
double magic_eps, double magic_eps_abs,
lower_bounds, upper_bounds: arrays of length dimension of variable bounds
x: an array of length dimension, set to optimum variables upon return
- fmin: on return, set to minimum f value
+ minf: on return, set to minimum f value
magic_eps, magic_eps_abs: Jones' "magic" epsilon parameter, and
also an absolute version of the same
- (not multipled by fmin). Jones suggests
+ (not multipled by minf). Jones suggests
setting this to 1e-4, but 0 also works...
max_feval, max_iter: maximum number of function evaluations & DIRECT iters
int dimension,
const double *lower_bounds, const double *upper_bounds,
- double *x, double *fmin,
+ double *x, double *minf,
int max_feval, int max_iter,
double magic_eps, double magic_eps_abs,
direct_direct_(f, x, &dimension, &magic_eps, magic_eps_abs,
&max_feval, &max_iter,
- fmin,
+ minf,
l, u,
&algmethod,
&ierror,
double x[2], l[2], u[2];
long int maxits = 0;
int info;
- double fmin;
+ double minf;
maxits = argc < 2 ? 100 : atoi(argv[1]);
l[0] = -3; l[1] = -3;
u[0] = 3; u[1] = 3;
- info = direct_optimize(tst_obj, NULL, n, l, u, x, &fmin,
+ info = direct_optimize(tst_obj, NULL, n, l, u, x, &minf,
maxits, 500,
0, 0, 0, 0, DIRECT_UNKNOWN_FGLOBAL, 0,
stdout, DIRECT_GABLONSKY);
printf("min f = %g at (%g,%g) after %d evals, return value %d\n",
- fmin, x[0], x[1], cnt, info);
+ minf, x[0], x[1], cnt, info);
return EXIT_SUCCESS;
}
CHECK(args(6).is_map(), "stop must be structure");
Octave_map stop = args(6).map_value();
- double fmin_max = struct_val_default(stop, "fmin_max", -HUGE_VAL);
+ double minf_max = struct_val_default(stop, "minf_max", -HUGE_VAL);
double ftol_rel = struct_val_default(stop, "ftol_rel", 0);
double ftol_abs = struct_val_default(stop, "ftol_abs", 0);
double xtol_rel = struct_val_default(stop, "xtol_rel", 0);
int maxeval = int(struct_val_default(stop, "maxeval", -1));
double maxtime = struct_val_default(stop, "maxtime", -1);
- double fmin = HUGE_VAL;
+ double minf = HUGE_VAL;
nlopt_result ret = nlopt_minimize(algorithm,
n,
user_function, &d,
lb.data(), ub.data(),
- x.fortran_vec(), &fmin,
- fmin_max, ftol_rel, ftol_abs,
+ x.fortran_vec(), &minf,
+ minf_max, ftol_rel, ftol_abs,
xtol_rel, xtol_abs.data(),
maxeval, maxtime);
retval(0) = x;
if (nargout > 1)
- retval(1) = fmin;
+ retval(1) = minf;
if (nargout > 2)
retval(2) = int(ret);
}
if (nlopt_stop_evals(stop)) *ret = NLOPT_MAXEVAL_REACHED;
else if (nlopt_stop_time(stop)) *ret = NLOPT_MAXTIME_REACHED;
- else if (ret_val <= stop->fmin_max) *ret = NLOPT_FMIN_MAX_REACHED;
+ else if (ret_val <= stop->minf_max) *ret = NLOPT_MINF_MAX_REACHED;
return ret_val;
} /* flin_ */
else if (info == LS_New ) {
box.AddTrial(tmpTrial) ;
- if (tmpTrial.objval<=fbound+mu && tmpTrial.objval<=box.fmin+mu) {
+ if (tmpTrial.objval<=fbound+mu && tmpTrial.objval<=box.minf+mu) {
if (stogo_verbose) {
cout << "Found a candidate, x=" << tmpTrial.xvals;
cout << " F=" <<tmpTrial.objval << " FC=" << FC << endl;
}
// Update fbound
- if (box.fmin < fbound) {
- fbound=box.fmin ;
+ if (box.minf < fbound) {
+ fbound=box.minf ;
#ifdef GS_DEBUG
cout <<"*** Improving fbound, fbound=" << fbound << endl;
#endif
nlopt_result ret = nlopt_minimize(NLOPT_LOCAL_LBFGS, n, f_local, &data,
box.lb.raw_data(), box.ub.raw_data(),
x.raw_data(), &f,
- stop->fmin_max,
+ stop->minf_max,
stop->ftol_rel, stop->ftol_abs,
stop->xtol_rel, stop->xtol_abs,
stop->maxeval - stop->nevals,
int stogo_minimize(int n,
objective_func fgrad, void *data,
- double *x, double *fmin,
+ double *x, double *minf,
const double *l, const double *u,
#ifdef NLOPT_UTIL_H
nlopt_stopping *stop,
if (Problem.NoMinimizers())
return 0;
- *fmin = Problem.OneMinimizer(dummyvec);
+ *minf = Problem.OneMinimizer(dummyvec);
for (int i = 0; i < n; ++i) x[i] = dummyvec(i);
return 1;
}
Output:
- fmin: the minimum value of the objective function found
+ minf: the minimum value of the objective function found
x: pointer to array of length n, giving the location of the minimum
int stogo_minimize(int n,
objective_func fgrad, void *data,
- double *x, double *fmin,
+ double *x, double *minf,
const double *l, const double *u,
#ifdef NLOPT_UTIL_H
nlopt_stopping *stop,
/************************ Trial Box ***********************/
TBox::TBox() : VBox() {
// Constructor
- fmin=DBL_MAX;
+ minf=DBL_MAX;
}
TBox::TBox(int n) : VBox(n) {
// Constructor
- fmin=DBL_MAX;
+ minf=DBL_MAX;
}
TBox::TBox(RCTBox box) : VBox(box) {
// Constructor + Copy
- fmin=box.fmin;
+ minf=box.minf;
TList=box.TList ;
}
// NB We should 'somehow' use VBox to copy lb and ub
// Note that assignment operators are _not_ inherited
lb=box.lb ; ub=box.ub ;
- fmin=box.fmin ;
+ minf=box.minf ;
TList=box.TList ;
return *this ;
}
double TBox::GetMin() {
- return fmin;
+ return minf;
}
bool TBox::EmptyBox() {
void TBox::AddTrial(RCTrial T) {
// Add a Trial to the (back of) TList
TList.push_back(T) ;
- if (T.objval<fmin)
- fmin=T.objval ;
+ if (T.objval<minf)
+ minf=T.objval ;
}
void TBox::RemoveTrial(Trial &T) {
void TBox::ClearBox() {
TList.erase(TList.begin(), TList.end());
- fmin=DBL_MAX;
+ minf=DBL_MAX;
}
bool TBox::CloseToMin(RVector &vec, double *objval, double eps_cl) {
fm2=min(fm2,(*itr).objval);
}
}
- // Set fmin of B1 and B2
- B1.fmin=fm1 ; B2.fmin=fm2;
+ // Set minf of B1 and B2
+ B1.minf=fm1 ; B2.minf=fm2;
}
void TBox::dispTrials() {
int n=(B.lb).GetLength() ;
for (int i=0 ; i<n ;i++)
os << '[' << B.lb(i) << "," << B.ub(i) << "]";
- os << " fmin= " << B.fmin << endl;
+ os << " minf= " << B.minf << endl;
return os;
}
double TBox::LowerBound(double maxgrad) {
// Lower bound estimation
- double lb=fmin ;
+ double lb=minf ;
double f1,f2,est ;
list<Trial>::const_iterator itr1,itr2 ;
class TBox: public VBox {
public:
- double fmin; // Smallest function value found so far
+ double minf; // Smallest function value found so far
list<Trial> TList; // List of trials
TBox(); // Construct a box
RCTBox operator=(RCTBox); // assignment operator
- double GetMin(); // Returns 'fmin'
+ double GetMin(); // Returns 'minf'
bool EmptyBox(); // Returns TRUE if Box contains no trials
void AddTrial(RCTrial); // Add a trial to the (back of) box
void RemoveTrial(Trial &); // Remove a trial from the (back of) box
bool Intersection(RCRVector, RCRVector, RCRVector);
double LowerBound(double);
- bool operator<(const TBox & x) const {return (fmin>x.fmin);}
+ bool operator<(const TBox & x) const {return (minf>x.minf);}
friend ostream & operator << (ostream &, const TBox &);
};
double x[2], l[2], u[2];
long int maxits = 0, maxtim = 0;
int info;
- double fmin;
+ double minf;
maxits = argc < 2 ? 100 : atoi(argv[1]);
l[0] = -3; l[1] = -3;
u[0] = 3; u[1] = 3;
- info = stogo_minimize(n, tst_obj, NULL, x, &fmin, l, u, maxits, maxtim);
+ info = stogo_minimize(n, tst_obj, NULL, x, &minf, l, u, maxits, maxtim);
printf("min f = %g at (%g,%g) after %d evals, return value %d\n",
- fmin, x[0], x[1], cnt, info);
+ minf, x[0], x[1], cnt, info);
return EXIT_SUCCESS;
}
*fx = isubc_1.sfbest;
}
L50:
- if (*fx < stop->fmin_max)
+ if (*fx < stop->minf_max)
*iflag = 2;
else if (nlopt_stop_evals(stop))
*iflag = -1;
f: function f(n,x,fdata) to be optimized
n: problem dimension
- fmin: (output) value of f at minimum
+ minf: (output) value of f at minimum
x[n]: (input) starting guess position, (output) computed minimum
fdata: data pointer passed to f
old args:
tol: relative error tolerance for x
maxnfe: maximum number of function evaluations
- fmin_max, use_fmin_max: if use_fmin_max, stop when f <= fmin_max
+ minf_max, use_minf_max: if use_minf_max, stop when f <= minf_max
new args: nlopt_stopping *stop (stopping criteria)
= 20 : ftol reached
= -200 : out of memory
*/
-int subplex(subplex_func f, double *fmin, double *x, int n, void *fdata,
+int subplex(subplex_func f, double *minf, double *x, int n, void *fdata,
nlopt_stopping *stop,
const double *scale)
{
subplx_(f,fdata, &n,
stop, &mode,
scale, x,
- fmin, &nfe,
+ minf, &nfe,
work, iwork, &errflag);
free(iwork);
typedef double (*subplex_func)(int n, const double *x, void *func_data);
-extern int subplex(subplex_func f, double *fmin, double *x, int n, void *fdata,
+extern int subplex(subplex_func f, double *minf, double *x, int n, void *fdata,
nlopt_stopping *stop,
const double *scale);
int has_gradient;
int n;
const double *lb, *ub, *xmin;
- double fmin;
+ double minf;
const char *name;
} testfunc;
#include "testfuncs.h"
static nlopt_algorithm algorithm = NLOPT_GN_DIRECT_L;
-static double ftol_rel = 0, ftol_abs = 0, xtol_rel = 0, xtol_abs = 0, fmin_max_delta = -HUGE_VAL;
+static double ftol_rel = 0, ftol_abs = 0, xtol_rel = 0, xtol_abs = 0, minf_max_delta = -HUGE_VAL;
static int maxeval = 1000, iterations = 1, center_start = 0;
static double maxtime = 0.0;
static double xinit_tol = -1;
{
testfunc func;
int i, iter;
- double *x, fmin, fmin_max, f0, *xtabs;
+ double *x, minf, minf_max, f0, *xtabs;
nlopt_result ret;
double start = nlopt_seconds();
xtabs = x + func.n * 2;
for (i = 0; i < func.n; ++i) xtabs[i] = xtol_abs;
- fmin_max = fmin_max_delta > (-HUGE_VAL) ? fmin_max_delta + func.fmin : (-HUGE_VAL);
+ minf_max = minf_max_delta > (-HUGE_VAL) ? minf_max_delta + func.minf : (-HUGE_VAL);
printf("-----------------------------------------------------------\n");
printf("Optimizing %s (%d dims) using %s algorithm\n",
ret = nlopt_minimize(algorithm,
func.n, func.f, func.f_data,
func.lb, func.ub,
- x, &fmin,
- fmin_max, ftol_rel, ftol_abs, xtol_rel, xtabs,
+ x, &minf,
+ minf_max, ftol_rel, ftol_abs, xtol_rel, xtabs,
maxeval, maxtime);
printf("finished after %g seconds.\n", nlopt_seconds() - start);
printf("return code %d from nlopt_minimize\n", ret);
return 0;
}
printf("Found minimum f = %g after %d evaluations.\n",
- fmin, testfuncs_counter);
+ minf, testfuncs_counter);
printf("Minimum at x = [");
for (i = 0; i < func.n; ++i) printf(" %g", x[i]);
printf("]\n");
- printf("|f - fmin| = %g, |f - fmin| / |fmin| = %e\n",
- fabs(fmin - func.fmin), fabs(fmin - func.fmin) / fabs(func.fmin));
+ printf("|f - minf| = %g, |f - minf| / |minf| = %e\n",
+ fabs(minf - func.minf), fabs(minf - func.minf) / fabs(func.minf));
}
- printf("vs. global minimum f = %g at x = [", func.fmin);
+ printf("vs. global minimum f = %g at x = [", func.minf);
for (i = 0; i < func.n; ++i) printf(" %g", func.xmin[i]);
printf("]\n");
" -X <t> : absolute tolerance <t> on x (default: disabled)\n"
" -f <t> : relative tolerance <t> on f (default: disabled)\n"
" -F <t> : absolute tolerance <t> on f (default: disabled)\n"
- " -m <m> : stop when fmin+<m> is reached (default: disabled)\n"
+ " -m <m> : stop when minf+<m> is reached (default: disabled)\n"
" -i <n> : iterate optimization <n> times (default: 1)\n"
" -r <s> : use random seed <s> for starting guesses\n"
, maxeval);
ftol_abs = atof(optarg);
break;
case 'm':
- fmin_max_delta = atof(optarg);
+ minf_max_delta = atof(optarg);
break;
case 'c':
center_start = 1;
/* stopping criteria */
typedef struct {
int n;
- double fmin_max;
+ double minf_max;
double ftol_rel;
double ftol_abs;
double xtol_rel;
int nlopt_stop_f(const nlopt_stopping *s, const double f, double oldf)
{
- return (f <= s->fmin_max || nlopt_stop_ftol(s, f, oldf));
+ return (f <= s->minf_max || nlopt_stop_ftol(s, f, oldf));
}
int nlopt_stop_x(const nlopt_stopping *s, const double *x, const double *oldx)