nlopt.c 16.4 KB
Newer Older
S
stevenj 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* Copyright (c) 2007-2008 Massachusetts Institute of Technology
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 */

S
stevenj 已提交
23 24
#include <stdlib.h>
#include <math.h>
25
#include <string.h>
26
#include <float.h>
S
stevenj 已提交
27 28

#include "nlopt.h"
29
#include "nlopt-util.h"
S
stevenj 已提交
30 31
#include "config.h"

S
stevenj 已提交
32 33 34 35 36 37 38 39 40 41
#define MIN(a,b) ((a) < (b) ? (a) : (b))

/*************************************************************************/

#ifdef INFINITY
#  define MY_INF INFINITY
#else
#  define MY_INF HUGE_VAL
#endif

S
stevenj 已提交
42
int nlopt_isinf(double x) {
S
stevenj 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55
     return fabs(x) >= HUGE_VAL * 0.99
#ifdef HAVE_ISINF
	  || isinf(x)
#endif
	  ;
}

#ifndef HAVE_ISNAN
static int my_isnan(double x) { return x != x; }
#  define isnan my_isnan
#endif

/*************************************************************************/
56

S
stevenj 已提交
57 58 59 60 61 62 63
void nlopt_version(int *major, int *minor, int *bugfix)
{
     *major = MAJOR_VERSION;
     *minor = MINOR_VERSION;
     *bugfix = BUGFIX_VERSION;
}

S
stevenj 已提交
64 65
/*************************************************************************/

66
static const char nlopt_algorithm_names[NLOPT_NUM_ALGORITHMS][256] = {
67 68 69 70 71 72 73 74 75
     "DIRECT (global, no-derivative)",
     "DIRECT-L (global, no-derivative)",
     "Randomized DIRECT-L (global, no-derivative)",
     "Unscaled DIRECT (global, no-derivative)",
     "Unscaled DIRECT-L (global, no-derivative)",
     "Unscaled Randomized DIRECT-L (global, no-derivative)",
     "Original DIRECT version (global, no-derivative)",
     "Original DIRECT-L version (global, no-derivative)",
     "Subplex (local, no-derivative)",
76
#ifdef WITH_CXX
77 78
     "StoGO (global, derivative-based)",
     "StoGO with randomized search (global, derivative-based)",
79 80 81
#else
     "StoGO (NOT COMPILED)",
     "StoGO randomized (NOT COMPILED)",
82 83
#endif
#ifdef WITH_NOCEDAL_LBFGS
S
stevenj 已提交
84
     "original NON-FREE L-BFGS code by Nocedal et al. (local, deriv.-based)",
85
#else
S
stevenj 已提交
86
     "original NON-FREE L-BFGS code by Nocedal et al. (NOT COMPILED)",
87
#endif
S
stevenj 已提交
88
     "Limited-memory BFGS (L-BFGS) (local, derivative-based)",
89
     "Principal-axis, praxis (local, no-derivative)",
S
stevenj 已提交
90 91
     "Limited-memory variable-metric, rank 1 (local, derivative-based)",
     "Limited-memory variable-metric, rank 2 (local, derivative-based)",
S
stevenj 已提交
92 93 94 95
     "Truncated Newton (local, derivative-based)",
     "Truncated Newton with restarting (local, derivative-based)",
     "Preconditioned truncated Newton (local, derivative-based)",
     "Preconditioned truncated Newton with restarting (local, derivative-based)",
96
     "Controlled random search (CRS2) with local mutation (global, no-derivative)",
97 98 99
     "Multi-level single-linkage (MLSL), random (global, no-derivative)",
     "Multi-level single-linkage (MLSL), random (global, derivative)",
     "Multi-level single-linkage (MLSL), quasi-random (global, no-derivative)",
S
stevenj 已提交
100
     "Multi-level single-linkage (MLSL), quasi-random (global, derivative)",
S
stevenj 已提交
101 102
     "Method of Moving Asymptotes (MMA) (local, derivative)",
     "COBYLA (Constrained Optimization BY Linear Approximations) (local, no-derivative)"
S
stevenj 已提交
103 104
};

105 106 107 108 109 110
const char *nlopt_algorithm_name(nlopt_algorithm a)
{
     if (a < 0 || a >= NLOPT_NUM_ALGORITHMS) return "UNKNOWN";
     return nlopt_algorithm_names[a];
}

S
stevenj 已提交
111 112
/*************************************************************************/

113 114 115 116 117 118 119 120 121 122
static int nlopt_srand_called = 0;
void nlopt_srand(unsigned long seed) {
     nlopt_srand_called = 1;
     nlopt_init_genrand(seed);
}

void nlopt_srand_time() {
     nlopt_srand(nlopt_time_seed());
}

S
stevenj 已提交
123
/*************************************************************************/
S
stevenj 已提交
124 125 126 127

typedef struct {
     nlopt_func f;
     void *f_data;
128
     const double *lb, *ub;
S
stevenj 已提交
129 130 131
} nlopt_data;

#include "subplex.h"
132
#include "praxis.h"
S
stevenj 已提交
133

S
stevenj 已提交
134
static double f_subplex(int n, const double *x, void *data_)
S
stevenj 已提交
135
{
136
     int i;
S
stevenj 已提交
137
     nlopt_data *data = (nlopt_data *) data_;
S
stevenj 已提交
138
     double f;
139 140 141 142 143

     /* subplex does not support bound constraints, but it supports
	discontinuous objectives so we can just return Inf for invalid x */
     for (i = 0; i < n; ++i)
	  if (x[i] < data->lb[i] || x[i] > data->ub[i])
S
stevenj 已提交
144
	       return MY_INF;
145

S
stevenj 已提交
146 147
     f = data->f(n, x, NULL, data->f_data);
     return (isnan(f) ? MY_INF : f);
S
stevenj 已提交
148 149 150 151
}

#include "direct.h"

S
stevenj 已提交
152
static double f_direct(int n, const double *x, int *undefined, void *data_)
S
stevenj 已提交
153 154
{
     nlopt_data *data = (nlopt_data *) data_;
155
     double f;
156
     f = data->f(n, x, NULL, data->f_data);
S
stevenj 已提交
157
     *undefined = isnan(f) || nlopt_isinf(f);
S
stevenj 已提交
158 159 160
     return f;
}

161 162 163
#ifdef WITH_CXX
#  include "stogo.h"
#endif
164

165 166
#include "cdirect.h"

167 168 169 170
#ifdef WITH_NOCEDAL
#  include "l-bfgs-b.h"
#endif

171 172
#include "luksan.h"

173 174
#include "crs.h"

S
stevenj 已提交
175 176
#include "mlsl.h"
#include "mma.h"
S
stevenj 已提交
177
#include "cobyla.h"
S
stevenj 已提交
178

S
stevenj 已提交
179
/*************************************************************************/
S
stevenj 已提交
180

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
/* for "hybrid" algorithms that combine global search with some
   local search algorithm, most of the time we anticipate that people
   will stick with the default local search algorithm, so we
   don't add this as a parameter to nlopt_minimize.  Instead, the user
   can call nlopt_{set/get}_hybrid_local_algorithm to get/set the defaults. */

/* default local-search algorithms */
static nlopt_algorithm local_search_alg_deriv = NLOPT_LD_LBFGS;
static nlopt_algorithm local_search_alg_nonderiv = NLOPT_LN_SUBPLEX;

static int local_search_maxeval = -1; /* no maximum by default */

void nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
				      nlopt_algorithm *nonderiv,
				      int *maxeval)
{
     *deriv = local_search_alg_deriv;
     *nonderiv = local_search_alg_nonderiv;
     *maxeval = local_search_maxeval;
}

void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
				      nlopt_algorithm nonderiv,
				      int maxeval)
{
     local_search_alg_deriv = deriv;
     local_search_alg_nonderiv = nonderiv;
     local_search_maxeval = maxeval;
}

/*************************************************************************/

213 214
/* same as nlopt_minimize, but xtol_abs is required to be non-NULL */
static nlopt_result nlopt_minimize_(
215
     nlopt_algorithm algorithm,
S
stevenj 已提交
216
     int n, nlopt_func f, void *f_data,
217
     int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
S
stevenj 已提交
218 219
     const double *lb, const double *ub, /* bounds */
     double *x, /* in: initial guess, out: minimizer */
220 221
     double *minf, /* out: minimum */
     double minf_max, double ftol_rel, double ftol_abs,
S
stevenj 已提交
222 223 224
     double xtol_rel, const double *xtol_abs,
     int maxeval, double maxtime)
{
225
     int i;
S
stevenj 已提交
226
     nlopt_data d;
227 228
     nlopt_stopping stop;

229
     /* some basic argument checks */
230 231
     if (!minf || !f || n < 0 || m < 0
	  || (m > 0 && !fc)) return NLOPT_INVALID_ARGS;
S
stevenj 已提交
232 233 234 235 236
     if (n == 0) { /* trivial case: no degrees of freedom */
	  *minf = f(n, x, NULL, f_data);
	  return NLOPT_SUCCESS;
     }
     else if (n < 0 || !lb || !ub || !x)
237 238
	  return NLOPT_INVALID_ARGS;

S
stevenj 已提交
239 240 241
     /* nonlinear constraints are only supported with MMA or COBYLA */
     if (m != 0 && algorithm != NLOPT_LD_MMA && algorithm != NLOPT_LN_COBYLA) 
	  return NLOPT_INVALID_ARGS;
242

S
stevenj 已提交
243 244
     d.f = f;
     d.f_data = f_data;
245 246 247
     d.lb = lb;
     d.ub = ub;

248 249 250 251
     /* make sure rand generator is inited */
     if (!nlopt_srand_called)
	  nlopt_srand_time(); /* default is non-deterministic */

252 253 254 255
     /* check bound constraints */
     for (i = 0; i < n; ++i)
	  if (lb[i] > ub[i] || x[i] < lb[i] || x[i] > ub[i])
	       return NLOPT_INVALID_ARGS;
S
stevenj 已提交
256

257
     stop.n = n;
S
stevenj 已提交
258 259
     stop.minf_max = (isnan(minf_max) 
		      || (nlopt_isinf(minf_max) && minf_max < 0))
260
	  ? -MY_INF : minf_max;
261 262 263 264 265 266 267 268 269
     stop.ftol_rel = ftol_rel;
     stop.ftol_abs = ftol_abs;
     stop.xtol_rel = xtol_rel;
     stop.xtol_abs = xtol_abs;
     stop.nevals = 0;
     stop.maxeval = maxeval;
     stop.maxtime = maxtime;
     stop.start = nlopt_seconds();

270
     switch (algorithm) {
271 272 273
	 case NLOPT_GN_DIRECT:
	 case NLOPT_GN_DIRECT_L: 
	 case NLOPT_GN_DIRECT_L_RAND: 
274
	      return cdirect(n, f, f_data, lb, ub, x, minf, &stop, 0.0, 
275 276 277 278 279 280 281
			     (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: 
282
	      return cdirect_unscaled(n, f, f_data, lb, ub, x, minf, 
283 284 285 286
				      &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)));
287
	      
288 289
	 case NLOPT_GN_ORIG_DIRECT:
	 case NLOPT_GN_ORIG_DIRECT_L: 
290
	      switch (direct_optimize(f_direct, &d, n, lb, ub, x, minf,
291 292
				      maxeval, -1, 0.0, 0.0,
				      pow(xtol_rel, (double) n), -1.0,
293
				      stop.minf_max, 0.0,
294
				      NULL, 
295
				      algorithm == NLOPT_GN_ORIG_DIRECT
296 297
				      ? DIRECT_ORIGINAL
				      : DIRECT_GABLONSKY)) {
S
stevenj 已提交
298 299 300 301 302 303 304 305 306 307 308 309
		  case DIRECT_INVALID_BOUNDS:
		  case DIRECT_MAXFEVAL_TOOBIG:
		  case DIRECT_INVALID_ARGS:
		       return NLOPT_INVALID_ARGS;
		  case DIRECT_INIT_FAILED:
		  case DIRECT_SAMPLEPOINTS_FAILED:
		  case DIRECT_SAMPLE_FAILED:
		       return NLOPT_FAILURE;
		  case DIRECT_MAXFEVAL_EXCEEDED:
		  case DIRECT_MAXITER_EXCEEDED:
		       return NLOPT_MAXEVAL_REACHED;
		  case DIRECT_GLOBAL_FOUND:
310
		       return NLOPT_MINF_MAX_REACHED;
S
stevenj 已提交
311 312 313 314 315
		  case DIRECT_VOLTOL:
		  case DIRECT_SIGMATOL:
		       return NLOPT_XTOL_REACHED;
		  case DIRECT_OUT_OF_MEMORY:
		       return NLOPT_OUT_OF_MEMORY;
S
stevenj 已提交
316
	      break;
317
	 }
S
stevenj 已提交
318

319 320
	 case NLOPT_GD_STOGO:
	 case NLOPT_GD_STOGO_RAND:
321
#ifdef WITH_CXX
322
	      if (!stogo_minimize(n, f, f_data, x, minf, lb, ub, &stop,
323
				  algorithm == NLOPT_GD_STOGO
324 325
				  ? 0 : 2*n))
		   return NLOPT_FAILURE;
S
stevenj 已提交
326
	      break;
327 328 329
#else
	      return NLOPT_FAILURE;
#endif
S
stevenj 已提交
330

331
	 case NLOPT_LN_SUBPLEX: {
332
	      int iret;
S
stevenj 已提交
333 334
	      double *scale = (double *) malloc(sizeof(double) * n);
	      if (!scale) return NLOPT_OUT_OF_MEMORY;
335
	      for (i = 0; i < n; ++i) {
S
stevenj 已提交
336
		   if (!nlopt_isinf(ub[i]) && !nlopt_isinf(lb[i]))
337
			scale[i] = (ub[i] - lb[i]) * 0.01;
S
stevenj 已提交
338
		   else if (!nlopt_isinf(lb[i]) && x[i] > lb[i])
339
			scale[i] = (x[i] - lb[i]) * 0.01;
S
stevenj 已提交
340
		   else if (!nlopt_isinf(ub[i]) && x[i] < ub[i])
341 342 343 344
			scale[i] = (ub[i] - x[i]) * 0.01;
		   else
			scale[i] = 0.01 * x[i] + 0.0001;
	      }
345
	      iret = nlopt_subplex(f_subplex, minf, x, n, &d, &stop, scale);
S
stevenj 已提交
346 347
	      free(scale);
	      switch (iret) {
S
stevenj 已提交
348
		  case -2: return NLOPT_INVALID_ARGS;
349
		  case -10: return NLOPT_MAXTIME_REACHED;
S
stevenj 已提交
350 351 352
		  case -1: return NLOPT_MAXEVAL_REACHED;
		  case 0: return NLOPT_XTOL_REACHED;
		  case 1: return NLOPT_SUCCESS;
353
		  case 2: return NLOPT_MINF_MAX_REACHED;
354 355 356
		  case 20: return NLOPT_FTOL_REACHED;
		  case -200: return NLOPT_OUT_OF_MEMORY;
		  default: return NLOPT_FAILURE; /* unknown return code */
S
stevenj 已提交
357 358 359 360
	      }
	      break;
	 }

361
	 case NLOPT_LN_PRAXIS: {
362 363
	      double h0 = HUGE_VAL;
	      for (i = 0; i < n; ++i) {
S
stevenj 已提交
364
		   if (!nlopt_isinf(ub[i]) && !nlopt_isinf(lb[i]))
365
			h0 = MIN(h0, (ub[i] - lb[i]) * 0.01);
S
stevenj 已提交
366
		   else if (!nlopt_isinf(lb[i]) && x[i] > lb[i])
367
			h0 = MIN(h0, (x[i] - lb[i]) * 0.01);
S
stevenj 已提交
368
		   else if (!nlopt_isinf(ub[i]) && x[i] < ub[i])
369 370 371 372 373
			h0 = MIN(h0, (ub[i] - x[i]) * 0.01);
		   else
			h0 = MIN(h0, 0.01 * x[i] + 0.0001);
	      }
	      return praxis_(0.0, DBL_EPSILON, h0, n, x, f_subplex, &d,
374
			     &stop, minf);
375 376
	 }

377 378 379 380 381
#ifdef WITH_NOCEDAL
	 case NLOPT_LD_LBFGS_NOCEDAL: {
	      int iret, *nbd = (int *) malloc(sizeof(int) * n);
	      if (!nbd) return NLOPT_OUT_OF_MEMORY;
	      for (i = 0; i < n; ++i) {
S
stevenj 已提交
382 383
		   int linf = nlopt_isinf(lb[i]) && lb[i] < 0;
		   int uinf = nlopt_isinf(ub[i]) && ub[i] > 0;
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
		   nbd[i] = linf && uinf ? 0 : (uinf ? 1 : (linf ? 3 : 2));
	      }
	      iret = lbfgsb_minimize(n, f, f_data, x, nbd, lb, ub,
				     MIN(n, 5), 0.0, ftol_rel, 
				     xtol_abs ? *xtol_abs : xtol_rel,
				     maxeval);
	      free(nbd);
	      if (iret <= 0) {
		   switch (iret) {
		       case -1: return NLOPT_INVALID_ARGS;
		       case -2: default: return NLOPT_FAILURE;
		   }
	      }
	      else {
		   *minf = f(n, x, NULL, f_data);
		   switch (iret) {
		       case 5: return NLOPT_MAXEVAL_REACHED;
		       case 2: return NLOPT_XTOL_REACHED;
		       case 1: return NLOPT_FTOL_REACHED;
		       default: return NLOPT_SUCCESS;
		   }
	      }
	      break;
	 }
#endif

410 411
	 case NLOPT_LD_LBFGS: 
	      return luksan_plis(n, f, f_data, lb, ub, x, minf, &stop);
S
stevenj 已提交
412

S
stevenj 已提交
413 414 415 416 417
	 case NLOPT_LD_VAR1: 
	 case NLOPT_LD_VAR2: 
	      return luksan_plip(n, f, f_data, lb, ub, x, minf, &stop,
		   algorithm == NLOPT_LD_VAR1 ? 1 : 2);

S
stevenj 已提交
418 419 420 421 422 423 424 425
	 case NLOPT_LD_TNEWTON: 
	 case NLOPT_LD_TNEWTON_RESTART: 
	 case NLOPT_LD_TNEWTON_PRECOND: 
	 case NLOPT_LD_TNEWTON_PRECOND_RESTART: 
	      return luksan_pnet(n, f, f_data, lb, ub, x, minf, &stop,
				 1 + (algorithm - NLOPT_LD_TNEWTON) % 2,
				 1 + (algorithm - NLOPT_LD_TNEWTON) / 2);

426 427 428
	 case NLOPT_GN_CRS2_LM:
	      return crs_minimize(n, f, f_data, lb, ub, x, minf, &stop, 0);

429 430 431 432 433 434 435 436 437 438 439 440
	 case NLOPT_GN_MLSL:
	 case NLOPT_GD_MLSL:
	 case NLOPT_GN_MLSL_LDS:
	 case NLOPT_GD_MLSL_LDS:
	      return mlsl_minimize(n, f, f_data, lb, ub, x, minf, &stop,
				   (algorithm == NLOPT_GN_MLSL ||
				    algorithm == NLOPT_GN_MLSL_LDS)
				   ? local_search_alg_nonderiv
				   : local_search_alg_deriv,
				   local_search_maxeval,
				   algorithm >= NLOPT_GN_MLSL_LDS);

S
stevenj 已提交
441
	 case NLOPT_LD_MMA:
442
	      return mma_minimize(n, f, f_data, m, fc, fc_data, fc_datum_size,
443
				  lb, ub, x, minf, &stop,
444
				  local_search_alg_deriv, 1e-12, 100000);
S
stevenj 已提交
445

S
stevenj 已提交
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
	 case NLOPT_LN_COBYLA: {
	      /* crude heuristics for initial step */
	      double rhobegin = HUGE_VAL;
	      for (i = 0; i < n; ++i) {
		   if (!nlopt_isinf(ub[i]) && !nlopt_isinf(lb[i])
			&& (ub[i] - lb[i]) * 0.25 < rhobegin && ub[i] != lb[i])
			rhobegin = (ub[i] - lb[i]) * 0.25;
	      }
	      if (nlopt_isinf(rhobegin)) {
		   rhobegin = 0;
		   for (i = 0; i < n; ++i)
			if (fabs(x[i]) * 0.25 > rhobegin)
			     rhobegin = fabs(x[i]) * 0.25;
		   if (rhobegin == 0)
			rhobegin = 1;
	      }
	      
	      return cobyla_minimize(n, f, f_data, 
				     m, fc, fc_data, fc_datum_size,
				     lb, ub, x, minf, &stop, rhobegin);
	 }

S
stevenj 已提交
468 469 470 471 472 473
	 default:
	      return NLOPT_INVALID_ARGS;
     }

     return NLOPT_SUCCESS;
}
474

475
nlopt_result nlopt_minimize_constrained(
476 477
     nlopt_algorithm algorithm,
     int n, nlopt_func f, void *f_data,
478
     int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
479 480
     const double *lb, const double *ub, /* bounds */
     double *x, /* in: initial guess, out: minimizer */
481 482
     double *minf, /* out: minimum */
     double minf_max, double ftol_rel, double ftol_abs,
483 484 485 486 487
     double xtol_rel, const double *xtol_abs,
     int maxeval, double maxtime)
{
     nlopt_result ret;
     if (xtol_abs)
488 489
	  ret = nlopt_minimize_(algorithm, n, f, f_data,
				m, fc, fc_data, fc_datum_size, lb, ub,
490
				x, minf, minf_max, ftol_rel, ftol_abs,
491 492 493 494 495 496
				xtol_rel, xtol_abs, maxeval, maxtime);
     else {
	  int i;
	  double *xtol = (double *) malloc(sizeof(double) * n);
	  if (!xtol) return NLOPT_OUT_OF_MEMORY;
	  for (i = 0; i < n; ++i) xtol[i] = -1;
497 498
	  ret = nlopt_minimize_(algorithm, n, f, f_data, 
				m, fc, fc_data, fc_datum_size, lb, ub,
499
				x, minf, minf_max, ftol_rel, ftol_abs,
500 501 502 503 504
				xtol_rel, xtol, maxeval, maxtime);
	  free(xtol);
     }
     return ret;
}
505 506 507 508 509 510 511 512 513 514 515

nlopt_result nlopt_minimize(
     nlopt_algorithm algorithm,
     int n, nlopt_func f, void *f_data,
     const double *lb, const double *ub, /* bounds */
     double *x, /* in: initial guess, out: minimizer */
     double *minf, /* out: minimum */
     double minf_max, double ftol_rel, double ftol_abs,
     double xtol_rel, const double *xtol_abs,
     int maxeval, double maxtime)
{
516 517 518 519
     return nlopt_minimize_constrained(
	  algorithm, n, f, f_data, 0, NULL, NULL, 0,
	  lb, ub, x, minf, minf_max, ftol_rel, ftol_abs,
	  xtol_rel, xtol_abs, maxeval, maxtime);
520
}