dret = direct_optimize(f_direct, opt, ni, lb, ub, x, minf,
stop.maxeval, -1, 0.0, 0.0,
pow(stop.xtol_rel, (double) n), -1.0,
+ stop.force_stop,
stop.minf_max, 0.0,
NULL,
algorithm == NLOPT_GN_ORIG_DIRECT
return NLOPT_XTOL_REACHED;
case DIRECT_OUT_OF_MEMORY:
return NLOPT_OUT_OF_MEMORY;
+ case DIRECT_FORCED_STOP:
+ return NLOPT_FORCED_STOP;
}
break;
}
/* | 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 *minf, doublereal *l,
+/* Subroutine */ void direct_direct_(fp fcn, doublereal *x, integer *n, doublereal *eps, doublereal epsabs, integer *maxf, integer *maxt, int *force_stop, doublereal *minf, doublereal *l,
doublereal *u, integer *algmethod, integer *ierror, FILE *logfile,
doublereal *fglobal, doublereal *fglper, doublereal *volper,
doublereal *sigmaper, void *fcn_data)
direct_dirinit_(f, fcn, c__, length, &actdeep, point, anchor, &ifree,
logfile, arrayi, &maxi, list2, w, &x[1], &l[1], &u[1],
minf, &minpos, thirds, levels, &MAXFUNC, &MAXDEEP, n, n, &
- fmax, &ifeasiblef, &iinfesiblef, ierror, fcn_data, jones);
+ fmax, &ifeasiblef, &iinfesiblef, ierror, fcn_data, jones,
+ force_stop);
/* +-----------------------------------------------------------------------+ */
/* | Added error checking. | */
/* +-----------------------------------------------------------------------+ */
fprintf(logfile, "WARNING: Error occured in routine DIRsamplef..\n");
goto cleanup;
}
+ if (*ierror == -102) goto L100;
}
numfunc = maxi + 1 + maxi;
actmaxdeep = 1;
logfile, f, &ifree, &maxi, point, fcn, &x[
1], &l[1], minf, &minpos, &u[1], n, &MAXFUNC, &
MAXDEEP, &oops, &fmax, &ifeasiblef, &iinfesiblef,
- fcn_data);
+ fcn_data, force_stop);
+ if (force_stop && *force_stop) {
+ *ierror = -102;
+ goto L100;
+ }
if (oops > 0) {
if (logfile)
fprintf(logfile, "WARNING: Error occured in routine DIRsamplef.\n");
integer *point, fp fcn, doublereal *x, doublereal *l, doublereal *
minf, integer *minpos, doublereal *u, integer *n, integer *maxfunc,
const integer *maxdeep, integer *oops, doublereal *fmax, integer *
- ifeasiblef, integer *iinfesiblef, void *fcn_data)
+ ifeasiblef, integer *iinfesiblef, void *fcn_data, int *force_stop)
{
/* System generated locals */
integer length_dim1, length_offset, c_dim1, c_offset, i__1, i__2;
/* +-----------------------------------------------------------------------+ */
/* | Call the function. | */
/* +-----------------------------------------------------------------------+ */
- direct_dirinfcn_(fcn, &x[1], &l[1], &u[1], n, &f[(pos << 1) + 1],
- &kret, fcn_data);
+ if (force_stop && *force_stop) /* skip eval after forced stop */
+ f[(pos << 1) + 1] = *fmax;
+ else
+ direct_dirinfcn_(fcn, &x[1], &l[1], &u[1], n, &f[(pos << 1) + 1],
+ &kret, fcn_data);
+ if (force_stop && *force_stop)
+ kret = -1; /* mark as invalid point */
/* +-----------------------------------------------------------------------+ */
/* | Remember IF an infeasible point has been found. | */
/* +-----------------------------------------------------------------------+ */
/* | Iterate over all evaluated points and see, IF the minimal | */
/* | value of the function has changed. IF this has happEND, | */
/* | store the minimal value and its position in the array. | */
-/* | Attention: Only valied values are checked!! | */
+/* | Attention: Only valid values are checked!! | */
/* +-----------------------------------------------------------------------+ */
i__1 = *maxi + *maxi;
for (j = 1; j <= i__1; ++j) {
doublereal *thirds, doublereal *levels, integer *maxfunc, const integer *
maxdeep, integer *n, integer *maxor, doublereal *fmax, integer *
ifeasiblef, integer *iinfeasible, integer *ierror, void *fcndata,
- integer jones)
+ integer jones, int *force_stop)
{
/* System generated locals */
integer c_dim1, c_offset, length_dim1, length_offset, list2_dim1,
/* L20: */
}
direct_dirinfcn_(fcn, &x[1], &l[1], &u[1], n, &f[3], &help, fcndata);
+ if (force_stop && *force_stop) {
+ *ierror = -102;
+ return;
+ }
f[4] = (doublereal) help;
*iinfeasible = help;
*fmax = f[3];
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], minf, minpos, &u[1], n, maxfunc,
- maxdeep, &oops, fmax, ifeasiblef, iinfeasible, fcndata);
+ maxdeep, &oops, fmax, ifeasiblef, iinfeasible, fcndata,
+ force_stop);
+ if (force_stop && *force_stop) {
+ *ierror = -102;
+ return;
+ }
/* +-----------------------------------------------------------------------+ */
/* | JG 01/23/01 Added error checking. | */
/* +-----------------------------------------------------------------------+ */
doublereal *thirds, doublereal *levels, integer *maxfunc, const integer *
maxdeep, integer *n, integer *maxor, doublereal *fmax, integer *
ifeasiblef, integer *iinfeasible, integer *ierror, void *fcndata,
- integer jones);
+ integer jones, int *force_stop);
extern void direct_dirinitlist_(
integer *anchor, integer *free, integer *
point, doublereal *f, integer *maxfunc, const integer *maxdeep);
integer *point, fp fcn, doublereal *x, doublereal *l, doublereal *
minf, integer *minpos, doublereal *u, integer *n, integer *maxfunc,
const integer *maxdeep, integer *oops, doublereal *fmax, integer *
- ifeasiblef, integer *iinfesiblef, void *fcn_data);
+ ifeasiblef, integer *iinfesiblef, void *fcn_data, int *force_stop);
/* DIRect.c */
extern void direct_direct_(
fp fcn, doublereal *x, integer *n, doublereal *eps, doublereal epsabs,
- integer *maxf, integer *maxt, doublereal *minf, doublereal *l,
+ integer *maxf, integer *maxt, int *force_stop, doublereal *minf, doublereal *l,
doublereal *u, integer *algmethod, integer *ierror, FILE *logfile,
doublereal *fglobal, doublereal *fglper, doublereal *volper,
doublereal *sigmaper, void *fcn_data);
DIRECT_SIGMATOL = 5,
DIRECT_OUT_OF_MEMORY = -100,
- DIRECT_INVALID_ARGS = -101
+ DIRECT_INVALID_ARGS = -101,
+ DIRECT_FORCED_STOP = -102
} direct_return_code;
#define DIRECT_UNKNOWN_FGLOBAL (-HUGE_VAL)
int max_feval, int max_iter,
double magic_eps, double magic_eps_abs,
double volume_reltol, double sigma_reltol,
+ int *force_stop,
double fglobal,
double fglobal_reltol,
int max_feval, int max_iter,
double magic_eps, double magic_eps_abs,
double volume_reltol, double sigma_reltol,
+ int *force_stop,
double fglobal,
double fglobal_reltol,
}
direct_direct_(f, x, &dimension, &magic_eps, magic_eps_abs,
- &max_feval, &max_iter,
+ &max_feval, &max_iter, force_stop,
minf,
l, u,
&algmethod,
maxeval, maxtime);
printf("finished after %g seconds.\n", nlopt_seconds() - start);
printf("return code %d from nlopt_minimize\n", ret);
- if (ret < 0 && ret != NLOPT_ROUNDOFF_LIMITED) {
+ if (ret < 0 && ret != NLOPT_ROUNDOFF_LIMITED
+ && ret != NLOPT_FORCED_STOP) {
fprintf(stderr, "testopt: error in nlopt_minimize\n");
free(x);
return 0;
if (val != minf) {
fprintf(stderr, "Mismatch %g between returned minf=%g and f(x) = %g\n",
minf - val, minf, val);
+ free(x);
return 0;
}
}