opt->fc));
if (!opt->work) return NLOPT_OUT_OF_MEMORY;
dret = direct_optimize(f_direct, opt, ni, lb, ub, x, minf,
- stop.maxeval, -1, 0.0, 0.0,
+ stop.maxeval, -1,
+ stop.start, stop.maxtime,
+ 0.0, 0.0,
pow(stop.xtol_rel, (double) n), -1.0,
stop.force_stop,
stop.minf_max, 0.0,
case DIRECT_MAXFEVAL_EXCEEDED:
case DIRECT_MAXITER_EXCEEDED:
return NLOPT_MAXEVAL_REACHED;
+ case DIRECT_MAXTIME_EXCEEDED:
+ return NLOPT_MAXTIME_REACHED;
case DIRECT_GLOBAL_FOUND:
return NLOPT_MINF_MAX_REACHED;
case DIRECT_VOLTOL:
return NLOPT_FAILURE;
break;
#else
- return NLOPT_FAILURE;
+ return NLOPT_INVALID_ARGS;
#endif
#if 0
L40:
if (nlopt_stop_forced(stop)) rc = NLOPT_FORCED_STOP;
- else if (nlopt_stop_evals(stop)) rc = NLOPT_MAXEVAL_REACHED;
- else if (nlopt_stop_time(stop)) rc = NLOPT_MAXTIME_REACHED;
+ else if (stop->nevals > 0) {
+ if (nlopt_stop_evals(stop)) rc = NLOPT_MAXEVAL_REACHED;
+ else if (nlopt_stop_time(stop)) rc = NLOPT_MAXTIME_REACHED;
+ }
if (rc != NLOPT_SUCCESS) goto L600;
stop->nevals++;
/* | 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, int *force_stop, doublereal *minf, doublereal *l,
+/* Subroutine */ void direct_direct_(fp fcn, doublereal *x, integer *n, doublereal *eps, doublereal epsabs, integer *maxf, integer *maxt, double starttime, double maxtime, 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)
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,
- force_stop);
+ starttime, maxtime, force_stop);
/* +-----------------------------------------------------------------------+ */
/* | Added error checking. | */
/* +-----------------------------------------------------------------------+ */
}
if (*ierror == -102) goto L100;
}
+ else if (*ierror == DIRECT_MAXTIME_EXCEEDED) goto L100;
numfunc = maxi + 1 + maxi;
actmaxdeep = 1;
oldpos = 0;
*ierror = -102;
goto L100;
}
+ if (nlopt_stop_time_(starttime, maxtime)) {
+ *ierror = DIRECT_MAXTIME_EXCEEDED;
+ goto L100;
+ }
if (oops > 0) {
if (logfile)
fprintf(logfile, "WARNING: Error occured in routine DIRsamplef.\n");
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, int *force_stop)
+ integer jones, double starttime, double maxtime, int *force_stop)
{
/* System generated locals */
integer c_dim1, c_offset, length_dim1, length_offset, list2_dim1,
point[1] = 0;
*free = 2;
delta = thirds[1];
+ if (nlopt_stop_time_(starttime, maxtime)) {
+ *ierror = DIRECT_MAXTIME_EXCEEDED;
+ return;
+ }
direct_dirget_i__(&length[length_offset], &c__1, &arrayi[1], maxi, n, maxfunc);
new__ = *free;
direct_dirsamplepoints_(&c__[c_offset], &arrayi[1], &delta, &c__1, &new__, &
*ierror = -102;
return;
}
+ if (nlopt_stop_time_(starttime, maxtime)) {
+ *ierror = DIRECT_MAXTIME_EXCEEDED;
+ 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, int *force_stop);
+ integer jones, double starttime, double maxtime, int *force_stop);
extern void direct_dirinitlist_(
integer *anchor, integer *free, integer *
point, doublereal *f, integer *maxfunc, const integer *maxdeep);
/* DIRect.c */
extern void direct_direct_(
fp fcn, doublereal *x, integer *n, doublereal *eps, doublereal epsabs,
- integer *maxf, integer *maxt, int *force_stop, doublereal *minf, doublereal *l,
+ integer *maxf, integer *maxt,
+ double starttime, double maxtime,
+ 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_GLOBAL_FOUND = 3,
DIRECT_VOLTOL = 4,
DIRECT_SIGMATOL = 5,
+ DIRECT_MAXTIME_EXCEEDED = 6,
DIRECT_OUT_OF_MEMORY = -100,
DIRECT_INVALID_ARGS = -101,
double *x, double *minf,
- int max_feval, int max_iter,
+ int max_feval, int max_iter,
+ double start, double maxtime,
double magic_eps, double magic_eps_abs,
double volume_reltol, double sigma_reltol,
int *force_stop,
double *x, double *minf,
int max_feval, int max_iter,
+ double start, double maxtime,
double magic_eps, double magic_eps_abs,
double volume_reltol, double sigma_reltol,
int *force_stop,
}
direct_direct_(f, x, &dimension, &magic_eps, magic_eps_abs,
- &max_feval, &max_iter, force_stop,
+ &max_feval, &max_iter,
+ start, maxtime, force_stop,
minf,
l, u,
&algmethod,
if (*iterm != 0) {
goto L11190;
}
- if (nlopt_stop_time(stop)) { *iterm = 100; goto L11190; }
*f = objgrad(*nf, &x[1], &gf[1], objgrad_data);
++stop->nevals;
++stat_1->nfg;
+ if (nlopt_stop_time(stop)) { *iterm = 100; goto L11190; }
L11120:
luksan_pytrcg__(nf, nf, &ix[1], &gf[1], &umax, gmax, &kbf, &iold);
luksan_pyfut1__(nf, f, &fo, &umax, gmax, xstop, stop, tolg,
case 4: return NLOPT_SUCCESS; /* gradient tolerance reached */
case 6: return NLOPT_SUCCESS;
case 12: case 13: return NLOPT_MAXEVAL_REACHED;
+ case 100: return NLOPT_MAXTIME_REACHED;
case -999: return NLOPT_FORCED_STOP;
default: return NLOPT_FAILURE;
}
if (*iterm != 0) {
goto L11190;
}
- if (nlopt_stop_time(stop)) { *iterm = 100; goto L11190; }
*f = objgrad(*nf, &x[1], &gf[1], objgrad_data);
++stop->nevals;
++stat_1->nfg;
+ if (nlopt_stop_time(stop)) { *iterm = 100; goto L11190; }
L11120:
luksan_pytrcg__(nf, nf, &ix[1], &gf[1], &umax, gmax, &kbf, &iold);
luksan_pyfut1__(nf, f, &fo, &umax, gmax, xstop, stop, tolg,
case 4: return NLOPT_SUCCESS; /* gradient tolerance reached */
case 6: return NLOPT_SUCCESS;
case 12: case 13: return NLOPT_MAXEVAL_REACHED;
+ case 100: return NLOPT_MAXTIME_REACHED;
case -999: return NLOPT_FORCED_STOP;
default: return NLOPT_FAILURE;
}
*f = objgrad(*nf, &x[1], &gf[1], objgrad_data);
++stop->nevals;
++stat_1->nfg;
+ if (nlopt_stop_time(stop)) { *iterm = 100; goto L11080; }
ld = kd;
L11020:
luksan_pytrcg__(nf, nf, &ix[1], &gf[1], &umax, gmax, &kbf, &iold);
case 4: return NLOPT_SUCCESS; /* gradient tolerance reached */
case 6: return NLOPT_SUCCESS;
case 12: case 13: return NLOPT_MAXEVAL_REACHED;
+ case 100: return NLOPT_MAXTIME_REACHED;
case -999: return NLOPT_FORCED_STOP;
default: return NLOPT_FAILURE;
}
++nf;
L310:
if (nlopt_stop_forced(stop)) rc = NLOPT_FORCED_STOP;
- else if (nlopt_stop_evals(stop)) rc = NLOPT_MAXEVAL_REACHED;
- else if (nlopt_stop_time(stop)) rc = NLOPT_MAXTIME_REACHED;
+ else if (stop->nevals > 0) {
+ if (nlopt_stop_evals(stop)) rc = NLOPT_MAXEVAL_REACHED;
+ else if (nlopt_stop_time(stop)) rc = NLOPT_MAXTIME_REACHED;
+ }
if (rc != NLOPT_SUCCESS) goto L530;
stop->nevals++;
const double *xs, const double *oldxs,
const double *scale_min, const double *scale_max);
extern int nlopt_stop_evals(const nlopt_stopping *stop);
+extern int nlopt_stop_time_(double start, double maxtime);
extern int nlopt_stop_time(const nlopt_stopping *stop);
extern int nlopt_stop_evalstime(const nlopt_stopping *stop);
extern int nlopt_stop_forced(const nlopt_stopping *stop);
return (s->maxeval > 0 && s->nevals >= s->maxeval);
}
+int nlopt_stop_time_(double start, double maxtime)
+{
+ return (maxtime > 0 && nlopt_seconds() - start >= maxtime);
+}
+
int nlopt_stop_time(const nlopt_stopping *s)
{
- return (s->maxtime > 0 && nlopt_seconds() - s->start >= s->maxtime);
+ return nlopt_stop_time_(s->start, s->maxtime);
}
int nlopt_stop_evalstime(const nlopt_stopping *stop)