chiark / gitweb /
improve C++ header exceptions, rename NLOPT_FORCE_STOP to NLOPT_FORCED_STOP
[nlopt.git] / api / nlopt.3
1 .\" 
2 .\" Copyright (c) 2007 Massachusetts Institute of Technology
3 .\" 
4 .\" Copying and distribution of this file, with or without modification,
5 .\" are permitted in any medium without royalty provided the copyright
6 .\" notice and this notice are preserved.
7 .\"
8 .TH NLOPT 3  2007-08-23 "MIT" "NLopt programming manual"
9 .SH NAME
10 nlopt \- Nonlinear optimization library
11 .SH SYNOPSIS
12 .nf
13 .B #include <nlopt.h>
14 .sp
15 .BI "nlopt_opt " "opt" " = nlopt_create(" "algorithm" , " n" );
16 .BI "nlopt_set_min_objective(" "opt" , " f" , " f_data" );
17 .BI "nlopt_set_ftol_rel(" "opt" , " tol");
18 .BI "..."
19 .BI "nlopt_optimize(" "opt" , " x " , " &opt_f" );
20 .BI "nlopt_destroy(" "opt" );
21 .sp
22 The "..." indicates any number of calls to NLopt functions, below, to
23 set parameters of the optimization, constraints, and stopping
24 criteria.  Here, \fBnlopt_set_ftol_rel\fR is merely an example of a
25 possible stopping criterion.  You should link the resulting program
26 with the linker flags -lnlopt -lm on Unix.
27 .fi
28 .SH DESCRIPTION
29 NLopt is a library for nonlinear optimization.  It attempts to
30 minimize (or maximize) a given nonlinear objective function
31 .I f
32 of
33 .I n
34 design variables, using the specified
35 .IR algorithm ,
36 possibly subject to linear or nonlinear constraints.  The optimum
37 function value found is returned in \fIopt_f\fR (type double) with the
38 corresponding design variable values returned in the (double) array
39 .I x
40 of length
41 .IR n .
42 The input values in
43 .I x
44 should be a starting guess for the optimum.
45 .sp
46 The parameters of the optimization are controlled via the object
47 .I opt
48 of type
49 .BR nlopt_opt ,
50 which is created by the function
51 .B nlopt_create
52 and disposed of by
53 .BR nlopt_destroy .
54 By calling various functions in the NLopt library, one can specify
55 stopping criteria (e.g., a relative tolerance on the objective
56 function value is specified by
57 .BR nlopt_set_ftol_rel ),
58 upper and/or lower bounds on the design parameters 
59 .IR x ,
60 and even arbitrary nonlinear inequality and equality constraints.
61 .sp
62 By changing the parameter
63 .I algorithm
64 among several predefined constants described below, one can switch easily
65 between a variety of minimization algorithms.  Some of these algorithms
66 require the gradient (derivatives) of the function to be supplied via
67 .IR f ,
68 and other algorithms do not require derivatives.  Some of the
69 algorithms attempt to find a global optimum within the given bounds,
70 and others find only a local optimum.  Most of the algorithms only
71 handle the case where there are no nonlinear constraints.  The NLopt
72 library is a wrapper around several free/open-source minimization
73 packages, as well as some new implementations of published
74 optimization algorithms.  You could, of course, compile and call these
75 packages separately, and in some cases this will provide greater
76 flexibility than is available via NLopt.  However, depending upon the
77 specific function being optimized, the different algorithms will vary
78 in effectiveness.  The intent of NLopt is to allow you to quickly
79 switch between algorithms in order to experiment with them for your
80 problem, by providing a simple unified interface to these subroutines.
81 .SH OBJECTIVE FUNCTION
82 The objective function is specified by calling one of:
83 .sp
84 .BI "  nlopt_result nlopt_set_min_objective(nlopt_opt " "opt" , 
85 .br
86 .BI "                                       nlopt_func " "f" ,
87 .br
88 .BI "                                       void* " "f_data" );
89 .br
90 .BI "  nlopt_result nlopt_set_max_objective(nlopt_opt " "opt" , 
91 .br
92 .BI "                                       nlopt_func " "f" ,
93 .br
94 .BI "                                       void* " "f_data" );
95 .sp
96 depending on whether one wishes to minimize or maximize the objective
97 function
98 .IR f ,
99 respectively.  The function
100 .I f
101 should be of the form:
102 .sp
103 .BI "  double f(unsigned " "n" , 
104 .br
105 .BI "           const double* " "x" , 
106 .br
107 .BI "           double* " "grad" , 
108 .br
109 .BI "           void* " "f_data" );
110 .sp
111 The return value should be the value of the function at the point
112 .IR x ,
113 where
114 .I x
115 points to an array of length
116 .I n
117 of the design variables.  The dimension
118 .I n
119 is identical to the one passed to
120 .BR nlopt_create .
121 .sp
122 In addition, if the argument
123 .I grad
124 is not NULL, then
125 .I grad
126 points to an array of length
127 .I n
128 which should (upon return) be set to the gradient of the function with
129 respect to the design variables at
130 .IR x .
131 That is,
132 .IR grad[i]
133 should upon return contain the partial derivative df/dx[i],
134 for 0 <= i < n, if
135 .I grad
136 is non-NULL.
137 Not all of the optimization algorithms (below) use the gradient information:
138 for algorithms listed as "derivative-free," the 
139 .I grad
140 argument will always be NULL and need never be computed.  (For
141 algorithms that do use gradient information, however,
142 .I grad
143 may still be NULL for some calls.)
144 .sp
145 The 
146 .I f_data
147 argument is the same as the one passed to 
148 .B nlopt_set_min_objective
149 or
150 .BR nlopt_set_max_objective ,
151 and may be used to pass any additional data through to the function.
152 (That is, it may be a pointer to some caller-defined data
153 structure/type containing information your function needs, which you
154 convert from void* by a typecast.)
155 .SH BOUND CONSTRAINTS
156 Most of the algorithms in NLopt are designed for minimization of
157 functions with simple bound constraints on the inputs.  That is, the
158 input vectors x[i] are constrainted to lie in a hyperrectangle lb[i]
159 <= x[i] <= ub[i] for 0 <= i < n.  These bounds are specified by
160 passing arrays
161 .I lb
162 and
163 .I ub
164 of length
165 .I n
166 to one or both of the functions:
167 .sp
168 .BI "  nlopt_result nlopt_set_lower_bounds(nlopt_opt " "opt" , 
169 .br
170 .BI "                                      const double* " "lb" ); 
171 .br
172 .BI "  nlopt_result nlopt_set_upper_bounds(nlopt_opt " "opt" , 
173 .br
174 .BI "                                      const double* " "ub" ); 
175 .sp
176 If a lower/upper bound is not set, the default is no bound
177 (unconstrained, i.e. a bound of infinity); it is possible to have
178 lower bounds but not upper bounds or vice versa.  Alternatively, the
179 user can call one of the above functions and explicitly pass a lower
180 bound of -HUGE_VAL and/or an upper bound of +HUGE_VAL for some design
181 variables to make them have no lower/upper bound, respectively.
182 (HUGE_VAL is the standard C constant for a floating-point infinity,
183 found in the math.h header file.)
184 .sp
185 Note, however, that some of the algorithms in NLopt, in particular
186 most of the global-optimization algorithms, do not support unconstrained
187 optimization and will return an error if you do not supply finite lower
188 and upper bounds.
189 .sp
190 For convenience, the following two functions are supplied in order to
191 set the lower/upper bounds for all design variables to a single
192 constant (so that you don't have to fill an array with a constant value):
193 .sp
194 .BI "  nlopt_result nlopt_set_lower_bounds1(nlopt_opt " "opt" , 
195 .br
196 .BI "                                       double " "lb" ); 
197 .br
198 .BI "  nlopt_result nlopt_set_upper_bounds1(nlopt_opt " "opt" , 
199 .br
200 .BI "                                       double " "ub" ); 
201 .sp
202 .SH NONLINEAR CONSTRAINTS
203 Several of the algorithms in NLopt (MMA, COBYLA, and ORIG_DIRECT) also
204 support arbitrary nonlinear inequality constraints, and some also
205 allow nonlinear equality constraints (ISRES and AUGLAG).  For these
206 algorithms, you can specify as many nonlinear constraints as you wish
207 by calling the following functions multiple times.
208 .sp
209 In particular, a nonlinear inequality constraint of the form 
210 \fIfc\fR(\fIx\fR) <= 0, where the function
211 .I fc
212 is of the same form as the objective function described above,
213 can be specified by calling:
214 .sp
215 .BI "  nlopt_result nlopt_add_inequality_constraint(nlopt_opt " "opt" , 
216 .br
217 .BI "                                               nlopt_func " "fc" ,
218 .br
219 .BI "                                               void* " "fc_data" ,
220 .br
221 .BI "                                               double " "tol" );
222 .sp
223 Just as for the objective function, 
224 .I fc_data
225 is a pointer to arbitrary user data that will be passed through to the
226 .I fc
227 function whenever it is called.  The parameter
228 .I tol
229 is a tolerance that is used for the purpose of stopping criteria only:
230 a point
231 .I x
232 is considered feasible for judging whether to stop the optimization if
233 \fIfc\fR(\fIx\fR) <= \fItol\fR.  A tolerance of zero means that NLopt
234 will try not to consider any \fIx\fR to be converged unless
235 .I fc
236 is strictly non-positive; generally, at least a small positive tolerance is
237 advisable to reduce sensitivity to rounding errors.
238
239 A nonlinear equality constraint of the form 
240 \fIh\fR(\fIx\fR) = 0, where the function
241 .I h
242 is of the same form as the objective function described above,
243 can be specified by calling:
244 .sp
245 .BI "  nlopt_result nlopt_add_equality_constraint(nlopt_opt " "opt" , 
246 .br
247 .BI "                                             nlopt_func " "h" ,
248 .br
249 .BI "                                             void* " "h_data" ,
250 .br
251 .BI "                                             double " "tol" );
252 .sp
253 Just as for the objective function, 
254 .I h_data
255 is a pointer to arbitrary user data that will be passed through to the
256 .I h
257 function whenever it is called.  The parameter
258 .I tol
259 is a tolerance that is used for the purpose of stopping criteria only:
260 a point
261 .I x
262 is considered feasible for judging whether to stop the optimization if
263 |\fIh\fR(\fIx\fR)| <= \fItol\fR.  For equality constraints, a small
264 positive tolerance is strongly advised in order to allow NLopt to 
265 converge even if the equality constraint is slightly nonzero.
266 .sp
267 (For any algorithm listed as "derivative-free" below, the
268 .I grad
269 argument to \fIfc\fR or \fIh\fR will always be NULL and need never be
270 computed.)
271 .sp
272 To remove all of the inequality and/or equality constraints from 
273 a given problem \fIopt\fR, you can call the following functions:
274 .sp
275 .BI "  nlopt_result nlopt_remove_inequality_constraints(nlopt_opt " "opt" );
276 .br
277 .BI "  nlopt_result nlopt_remove_equality_constraints(nlopt_opt " "opt" );
278 .SH ALGORITHMS
279 The 
280 .I algorithm
281 parameter specifies the optimization algorithm (for more detail on
282 these, see the README files in the source-code subdirectories), and
283 can take on any of the following constant values.
284 .sp
285 Constants with
286 .B _G{N,D}_
287 in their names
288 refer to global optimization methods, whereas
289 .B _L{N,D}_
290 refers to local optimization methods (that try to find a local optimum
291 starting from the starting guess
292 .IR x ).
293 Constants with
294 .B _{G,L}N_
295 refer to non-gradient (derivative-free) algorithms that do not require the
296 objective function to supply a gradient, whereas
297 .B _{G,L}D_
298 refers to derivative-based algorithms that require the objective
299 function to supply a gradient.  (Especially for local optimization,
300 derivative-based algorithms are generally superior to derivative-free
301 ones: the gradient is good to have 
302 .I if 
303 you can compute it cheaply, e.g. via an adjoint method.)
304 .sp
305 The algorithm specified for a given problem
306 .I opt
307 is returned by the function:
308 .sp
309 .BI "  nlopt_algorithm nlopt_get_algorithm(nlopt_opt " "opt" );
310 .sp
311 The available algorithms are:
312 .TP 
313 .B NLOPT_GN_DIRECT_L
314 Perform a global (G) derivative-free (N) optimization using the
315 DIRECT-L search algorithm by Jones et al. as modified by Gablonsky et
316 al. to be more weighted towards local search.  Does not support
317 unconstrainted optimization.  There are also several other variants of
318 the DIRECT algorithm that are supported:
319 .BR NLOPT_GLOBAL_DIRECT ,
320 which is the original DIRECT algorithm;
321 .BR NLOPT_GLOBAL_DIRECT_L_RAND ,
322 a slightly randomized version of DIRECT-L that may be better in
323 high-dimensional search spaces;
324 .BR NLOPT_GLOBAL_DIRECT_NOSCAL ,
325 .BR NLOPT_GLOBAL_DIRECT_L_NOSCAL ,
326 and
327 .BR NLOPT_GLOBAL_DIRECT_L_RAND_NOSCAL ,
328 which are versions of DIRECT where the dimensions are not rescaled to
329 a unit hypercube (which means that dimensions with larger bounds are
330 given more weight).
331 .TP 
332 .B NLOPT_GN_ORIG_DIRECT_L
333 A global (G) derivative-free optimization using the DIRECT-L algorithm
334 as above, along with
335 .B NLOPT_GN_ORIG_DIRECT
336 which is the original DIRECT algorithm.  Unlike 
337 .B NLOPT_GN_DIRECT_L 
338 above, these two algorithms refer to code based on the original
339 Fortran code of Gablonsky et al., which has some hard-coded
340 limitations on the number of subdivisions etc. and does not support
341 all of the NLopt stopping criteria, but on the other hand it supports
342 arbitrary nonlinear inequality constraints.
343 .TP 
344 .B NLOPT_GD_STOGO
345 Global (G) optimization using the StoGO algorithm by Madsen et al.  StoGO
346 exploits gradient information (D) (which must be supplied by the
347 objective) for its local searches, and performs the global search by a
348 branch-and-bound technique.  Only bound-constrained optimization
349 is supported.  There is also another variant of this algorithm,
350 .BR NLOPT_GD_STOGO_RAND ,
351 which is a randomized version of the StoGO search scheme.  The StoGO
352 algorithms are only available if NLopt is compiled with C++ code
353 enabled, and should be linked via -lnlopt_cxx instead of -lnlopt (via
354 a C++ compiler, in order to link the C++ standard libraries).
355 .TP 
356 .B NLOPT_LN_NELDERMEAD
357 Perform a local (L) derivative-free (N) optimization, starting at
358 .IR x ,
359 using the Nelder-Mead simplex algorithm, modified to support bound
360 constraints.  Nelder-Mead, while popular, is known to occasionally
361 fail to converge for some objective functions, so it should be used
362 with caution.  Anecdotal evidence, on the other hand, suggests that it
363 works fairly well for some cases that are hard to handle otherwise,
364 e.g. noisy/discontinuous objectives.  See also
365 .B NLOPT_LN_SBPLX
366 below.
367 .TP 
368 .B NLOPT_LN_SBPLX
369 Perform a local (L) derivative-free (N) optimization, starting at
370 .IR x ,
371 using an algorithm based on the Subplex algorithm of Rowan et al.,
372 which is an improved variant of Nelder-Mead (above).  Our
373 implementation does not use Rowan's original code, and has some minor
374 modifications such as explicit support for bound constraints.  (Like
375 Nelder-Mead, Subplex often works well in practice, even for
376 noisy/discontinuous objectives, but there is no rigorous guarantee that it
377 will converge.)
378 .TP
379 .B NLOPT_LN_PRAXIS
380 Local (L) derivative-free (N) optimization using the principal-axis
381 method, based on code by Richard Brent.  Designed for unconstrained
382 optimization, although bound constraints are supported too (via the
383 inefficient method of returning +Inf when the constraints are violated).
384 .TP
385 .B NLOPT_LD_LBFGS
386 Local (L) gradient-based (D) optimization using the limited-memory BFGS
387 (L-BFGS) algorithm.  (The objective function must supply the
388 gradient.)  Unconstrained optimization is supported in addition to
389 simple bound constraints (see above).  Based on an implementation by
390 Luksan et al.
391 .TP
392 .B NLOPT_LD_VAR2
393 Local (L) gradient-based (D) optimization using a shifted limited-memory
394 variable-metric method based on code by Luksan et al., supporting both
395 unconstrained and bound-constrained optimization.  
396 .B NLOPT_LD_VAR2
397 uses a rank-2 method, while 
398 .B .B NLOPT_LD_VAR1
399 is another variant using a rank-1 method.
400 .TP
401 .B NLOPT_LD_TNEWTON_PRECOND_RESTART
402 Local (L) gradient-based (D) optimization using an
403 LBFGS-preconditioned truncated Newton method with steepest-descent
404 restarting, based on code by Luksan et al., supporting both
405 unconstrained and bound-constrained optimization.  There are several
406 other variants of this algorithm:
407 .B NLOPT_LD_TNEWTON_PRECOND 
408 (same without restarting), 
409 .B NLOPT_LD_TNEWTON_RESTART
410 (same without preconditioning), and
411 .B NLOPT_LD_TNEWTON
412 (same without restarting or preconditioning).
413 .TP
414 .B NLOPT_GN_CRS2_LM
415 Global (G) derivative-free (N) optimization using the controlled random
416 search (CRS2) algorithm of Price, with the "local mutation" (LM)
417 modification suggested by Kaelo and Ali.
418 .TP
419 .B NLOPT_GN_ISRES
420 Global (G) derivative-free (N) optimization using a genetic algorithm
421 (mutation and differential evolution), using a stochastic ranking to
422 handle nonlinear inequality and equality constraints as suggested by
423 Runarsson and Yao.
424 .TP
425 \fBNLOPT_GD_MLSL_LDS\fR, \fBNLOPT_GN_MLSL_LDS\fR
426 Global (G) derivative-based (D) or derivative-free (N) optimization
427 using the multi-level single-linkage (MLSL) algorithm with a
428 low-discrepancy sequence (LDS).  This algorithm executes a quasi-random
429 (LDS) sequence of local searches, with a clustering heuristic to
430 avoid multiple local searches for the same local optimum.  The local
431 search uses the derivative/nonderivative algorithm set by
432 .I nlopt_set_local_optimizer
433 (currently defaulting to
434 .I NLOPT_LD_MMA
435 and
436 .I NLOPT_LN_COBYLA
437 for derivative/nonderivative searches, respectively).  There are also
438 two other variants, \fBNLOPT_GD_MLSL\fR and \fBNLOPT_GN_MLSL\fR, which use
439 pseudo-random numbers (instead of an LDS) as in the original MLSL algorithm.
440 .TP
441 .B NLOPT_LD_MMA
442 Local (L) gradient-based (D) optimization using the method of moving
443 asymptotes (MMA), or rather a refined version of the algorithm as
444 published by Svanberg (2002).  (NLopt uses an independent
445 free-software/open-source implementation of Svanberg's algorithm.)
446 The
447 .B NLOPT_LD_MMA
448 algorithm supports both bound-constrained and unconstrained optimization,
449 and also supports an arbitrary number (\fIm\fR) of nonlinear constraints
450 as described above.
451 .TP
452 .B NLOPT_LN_COBYLA
453 Local (L) derivative-free (N) optimization using the COBYLA algorithm
454 of Powell (Constrained Optimization BY Linear Approximations).
455 The
456 .B NLOPT_LN_COBYLA
457 algorithm supports both bound-constrained and unconstrained optimization,
458 and also supports an arbitrary number (\fIm\fR) of nonlinear constraints
459 as described above.
460 .TP
461 .B NLOPT_LN_NEWUOA
462 Local (L) derivative-free (N) optimization using a variant of the
463 NEWUOA algorithm of Powell, based on successive quadratic
464 approximations of the objective function. We have modified the
465 algorithm to support bound constraints.  The original NEWUOA algorithm
466 is also available, as
467 .BR NLOPT_LN_NEWUOA ,
468 but this algorithm ignores the bound constraints
469 .I lb
470 and 
471 .IR ub ,
472 and so it should only be used for unconstrained problems.  Mostly
473 superseded by BOBYQA.
474 .TP
475 .B NLOPT_LN_BOBYQA
476 Local (L) derivative-free (N) optimization using the BOBYQA algorithm
477 of Powell, based on successive quadratic approximations of the
478 objective function, supporting bound constraints.
479 .SH STOPPING CRITERIA
480 Multiple stopping criteria for the optimization are supported, as
481 specified by the functions to modify a given optimization problem
482 .BR opt .
483 The optimization halts whenever any one of these criteria is
484 satisfied.  In some cases, the precise interpretation of the stopping
485 criterion depends on the optimization algorithm above (although we
486 have tried to make them as consistent as reasonably possible), and
487 some algorithms do not support all of the stopping criteria.
488 .sp
489 Important: you do not need to use all of the stopping criteria!  In most
490 cases, you only need one or two, and can omit the remainder (all criteria
491 are disabled by default).
492 .TP
493 .BI "nlopt_result nlopt_set_stopval(nlopt_opt " "opt" ,
494 .br
495 .BI "                        double " stopval );
496 .sp
497 Stop when an objective value of at least
498 .I stopval
499 is found: stop minimizing when a value <= \fIstopval\fR is found, or
500 stop maximizing when a value >= \fIstopval\fR is found.  (Setting
501 \fIstopval\fR to -HUGE_VAL for minimizing or +HUGE_VAL for maximizing
502 disables this stopping criterion.)
503 .TP
504 .BI "nlopt_result nlopt_set_ftol_rel(nlopt_opt " "opt" ,
505 .br
506 .BI "                         double " tol );
507 .sp
508 Set relative tolerance on function value: stop when an optimization step
509 (or an estimate of the optimum) changes the function value by less
510 than
511 .I tol
512 multiplied by the absolute value of the function value.  (If there is any chance that your optimum function value is close to zero, you might want to set an absolute tolerance with
513 .B nlopt_set_ftol_abs
514 as well.)  Criterion is disabled if \fItol\fR is non-positive.
515 .TP
516 .BI "nlopt_result nlopt_set_ftol_abs(nlopt_opt " "opt" ,
517 .br
518 .BI "                         double " tol );
519 .sp
520 Set absolute tolerance on function value: stop when an optimization step
521 (or an estimate of the optimum) changes the function value by less
522 than
523 .IR tol .
524 Criterion is disabled if \fItol\fR is non-positive.
525 .TP
526 .BI "nlopt_result nlopt_set_xtol_rel(nlopt_opt " "opt" ,
527 .br
528 .BI "                         double " tol );
529 .sp
530 Set relative tolerance on design variables: stop when an optimization step
531 (or an estimate of the optimum) changes every design variable by less
532 than
533 .I tol
534 multiplied by the absolute value of the design variable.  (If there is
535 any chance that an optimal design variable is close to zero, you
536 might want to set an absolute tolerance with
537 .B nlopt_set_xtol_abs
538 as well.)  Criterion is disabled if \fItol\fR is non-positive.
539 .TP
540 .BI "nlopt_result nlopt_set_xtol_abs(nlopt_opt " "opt" ,
541 .br
542 .BI "                         const double* " tol );
543 .sp
544 Set absolute tolerances on design variables.  \fItol\fR is a pointer
545 to an array of length
546 .I
547 n giving the tolerances: stop when an
548 optimization step (or an estimate of the optimum) changes every design
549 variable
550 .IR x [i]
551 by less than
552 .IR tol [i].
553 .sp
554 For convenience, the following function may be used to set the absolute tolerances in all \fIn\fR design variables to the same value:
555 .sp
556 .BI "  nlopt_result nlopt_set_xtol_abs1(nlopt_opt " "opt" ,
557 .br
558 .BI "                                   double " tol );
559 .sp
560 Criterion is disabled if \fItol\fR is non-positive.
561 .TP
562 .BI "nlopt_result nlopt_set_maxeval(nlopt_opt " "opt" ,
563 .br
564 .BI "                        int " maxeval );
565 .sp
566 Stop when the number of function evaluations exceeds
567 .IR maxeval .
568 (This is not a strict maximum: the number of function evaluations may
569 exceed
570 .I maxeval 
571 slightly, depending upon the algorithm.)  Criterion is disabled
572 if \fImaxeval\fR is non-positive.
573 .TP
574 .BI "nlopt_result nlopt_set_maxtime(nlopt_opt " "opt" ,
575 .br
576 .BI "                        double " maxtime );
577 .sp
578 Stop when the optimization time (in seconds) exceeds
579 .IR maxtime .
580 (This is not a strict maximum: the time may
581 exceed
582 .I maxtime
583 slightly, depending upon the algorithm and on how slow your function
584 evaluation is.)  Criterion is disabled if \fImaxtime\fR is non-positive.
585 .SH RETURN VALUE
586 Most of the NLopt functions return an enumerated constant
587 of type
588 .BR nlopt_result ,
589 which takes on one of the following values:
590 .SS Successful termination (positive return values):
591 .TP
592 .B NLOPT_SUCCESS
593 Generic success return value.
594 .TP
595 .B NLOPT_STOPVAL_REACHED
596 Optimization stopped because
597 .I stopval
598 (above) was reached.
599 .TP
600 .B NLOPT_FTOL_REACHED
601 Optimization stopped because
602 .I ftol_rel
603 or
604 .I ftol_abs
605 (above) was reached.
606 .TP
607 .B NLOPT_XTOL_REACHED
608 Optimization stopped because
609 .I xtol_rel
610 or
611 .I xtol_abs
612 (above) was reached.
613 .TP
614 .B NLOPT_MAXEVAL_REACHED
615 Optimization stopped because
616 .I maxeval
617 (above) was reached.
618 .TP
619 .B NLOPT_MAXTIME_REACHED
620 Optimization stopped because
621 .I maxtime
622 (above) was reached.
623 .SS Error codes (negative return values):
624 .TP
625 .B NLOPT_FAILURE
626 Generic failure code.
627 .TP
628 .B NLOPT_INVALID_ARGS
629 Invalid arguments (e.g. lower bounds are bigger than upper bounds, an
630 unknown algorithm was specified, etcetera).
631 .TP
632 .B NLOPT_OUT_OF_MEMORY
633 Ran out of memory.
634 .TP
635 .B NLOPT_ROUNDOFF_LIMITED
636 Halted because roundoff errors limited progress.
637 .TP
638 .B NLOPT_FORCED_STOP
639 Halted because the user called \fBnlopt_force_stop\fR(\fIopt\fR) on
640 the optimization's \fBnlopt_opt\fR object \fIopt\fR from the user's
641 objective function.
642 .SH LOCAL OPTIMIZER
643 Some of the algorithms, especially MLSL and AUGLAG, use a different
644 optimization algorithm as a subroutine, typically for local
645 optimization.  By default, they use MMA or COBYLA for gradient-based
646 or derivative-free searching, respectively.  However, you can change
647 the local search algorithm and its tolerances by calling:
648 .sp
649 .BI "  nlopt_result nlopt_set_local_optimizer(nlopt_opt " "opt" , 
650 .br
651 .BI "                                         const nlopt_opt " "local_opt" );
652 .sp
653 Here, \fIlocal_opt\fR is another \fBnlopt_opt\fR object whose
654 parameters are used to determine the local search algorithm and
655 stopping criteria.  (The objective function and nonlinear-constraint
656 parameters of \fIlocal_opt\fR are ignored.)  The dimension \fIn\fR of
657 \fIlocal_opt\fR must match that of \fIopt\fR.
658 .sp
659 This function makes a copy of the \fIlocal_opt\fR object, so you can
660 freely destroy your original \fIlocal_opt\fR afterwards.
661 .SH INITIAL STEP SIZE
662 For derivative-free local-optimization algorithms, the optimizer must
663 somehow decide on some initial step size to perturb \fIx\fR by when it
664 begins the optimization.  This step size should be big enough that the
665 value of the objective changes significantly, but not too big if you
666 want to find the local optimum nearest to \fIx\fR.  By default, NLopt
667 chooses this initial step size heuristically from the bounds,
668 tolerances, and other information, but this may not always be the best
669 choice.
670 .sp
671 You can modify the initial step size by calling:
672 .sp
673 .BI "  nlopt_result nlopt_set_initial_step(nlopt_opt " "opt" , 
674 .br
675 .BI "                                      const double* " "dx" );
676 .sp
677 Here, \fIdx\fR is an array of length \fIn\fR containing the (nonzero)
678 initial step size for each component of the design parameters \fIx\fR.
679 For convenience, if you want to set the step sizes in every direction
680 to be the same value, you can instead call:
681 .sp
682 .BI "  nlopt_result nlopt_set_initial_step1(nlopt_opt " "opt" , 
683 .br
684 .BI "                                       double " "dx" );
685 .SH STOCHASTIC POPULATION
686 Several of the stochastic search algorithms (e.g., CRS, MLSL, and
687 ISRES) start by generating some initial "population" of random points
688 \fIx\fR.  By default, this initial population size is chosen
689 heuristically in some algorithm-specific way, but the initial
690 population can by changed by calling:
691 .sp
692 .BI "  nlopt_result nlopt_set_population(nlopt_opt " "opt" , 
693 .br
694 .BI "                                    unsigned " "pop" );
695 .sp
696 (A \fIpop\fR of zero implies that the heuristic default will be used.)
697 .SH PSEUDORANDOM NUMBERS
698 For stochastic optimization algorithms, we use pseudorandom numbers generated
699 by the Mersenne Twister algorithm, based on code from Makoto Matsumoto.
700 By default, the seed for the random numbers is generated from the system
701 time, so that they will be different each time you run the program.  If
702 you want to use deterministic random numbers, you can set the seed by
703 calling:
704 .sp
705 .BI "            void nlopt_srand(unsigned long " "seed" );
706 .sp
707 Some of the algorithms also support using low-discrepancy sequences (LDS),
708 sometimes known as quasi-random numbers.  NLopt uses the Sobol LDS, which
709 is implemented for up to 1111 dimensions.
710 .SH AUTHORS
711 Written by Steven G. Johnson.
712 .PP
713 Copyright (c) 2007-2010 Massachusetts Institute of Technology.
714 .SH "SEE ALSO"
715 nlopt_minimize(3)