chiark / gitweb /
document NLOPT_AUGLAG
[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 .TP
480 .B NLOPT_AUGLAG
481 Optimize an objective with nonlinear inequality/equality constraints
482 via an unconstrained (or bound-constrained) optimization algorithm,
483 using a gradually increasing "augmented Lagrangian" penalty for
484 violated constraints.  Requires you to specify another optimization
485 algorithm for optimizing the objective+penalty function, using
486 \fInlopt_set_local_optimizer\fR.  (This subsidiary algorithm can be
487 global or local and with or without derivatives, but you must specify
488 its own termination criteria.)  A variant, \fBNLOPT_AUGLAG_EQ\fR, only
489 uses the penalty approach for equality constraints, while inequality
490 constraints are handled directly by the subsidiary algorithm (restricting
491 the choice of subsidiary algorithms to those that can handle inequality
492 constraints).
493 .SH STOPPING CRITERIA
494 Multiple stopping criteria for the optimization are supported, as
495 specified by the functions to modify a given optimization problem
496 .BR opt .
497 The optimization halts whenever any one of these criteria is
498 satisfied.  In some cases, the precise interpretation of the stopping
499 criterion depends on the optimization algorithm above (although we
500 have tried to make them as consistent as reasonably possible), and
501 some algorithms do not support all of the stopping criteria.
502 .sp
503 Important: you do not need to use all of the stopping criteria!  In most
504 cases, you only need one or two, and can omit the remainder (all criteria
505 are disabled by default).
506 .TP
507 .BI "nlopt_result nlopt_set_stopval(nlopt_opt " "opt" ,
508 .br
509 .BI "                        double " stopval );
510 .sp
511 Stop when an objective value of at least
512 .I stopval
513 is found: stop minimizing when a value <= \fIstopval\fR is found, or
514 stop maximizing when a value >= \fIstopval\fR is found.  (Setting
515 \fIstopval\fR to -HUGE_VAL for minimizing or +HUGE_VAL for maximizing
516 disables this stopping criterion.)
517 .TP
518 .BI "nlopt_result nlopt_set_ftol_rel(nlopt_opt " "opt" ,
519 .br
520 .BI "                         double " tol );
521 .sp
522 Set relative tolerance on function value: stop when an optimization step
523 (or an estimate of the optimum) changes the function value by less
524 than
525 .I tol
526 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
527 .B nlopt_set_ftol_abs
528 as well.)  Criterion is disabled if \fItol\fR is non-positive.
529 .TP
530 .BI "nlopt_result nlopt_set_ftol_abs(nlopt_opt " "opt" ,
531 .br
532 .BI "                         double " tol );
533 .sp
534 Set absolute tolerance on function value: stop when an optimization step
535 (or an estimate of the optimum) changes the function value by less
536 than
537 .IR tol .
538 Criterion is disabled if \fItol\fR is non-positive.
539 .TP
540 .BI "nlopt_result nlopt_set_xtol_rel(nlopt_opt " "opt" ,
541 .br
542 .BI "                         double " tol );
543 .sp
544 Set relative tolerance on design variables: stop when an optimization step
545 (or an estimate of the optimum) changes every design variable by less
546 than
547 .I tol
548 multiplied by the absolute value of the design variable.  (If there is
549 any chance that an optimal design variable is close to zero, you
550 might want to set an absolute tolerance with
551 .B nlopt_set_xtol_abs
552 as well.)  Criterion is disabled if \fItol\fR is non-positive.
553 .TP
554 .BI "nlopt_result nlopt_set_xtol_abs(nlopt_opt " "opt" ,
555 .br
556 .BI "                         const double* " tol );
557 .sp
558 Set absolute tolerances on design variables.  \fItol\fR is a pointer
559 to an array of length
560 .I
561 n giving the tolerances: stop when an
562 optimization step (or an estimate of the optimum) changes every design
563 variable
564 .IR x [i]
565 by less than
566 .IR tol [i].
567 .sp
568 For convenience, the following function may be used to set the absolute tolerances in all \fIn\fR design variables to the same value:
569 .sp
570 .BI "  nlopt_result nlopt_set_xtol_abs1(nlopt_opt " "opt" ,
571 .br
572 .BI "                                   double " tol );
573 .sp
574 Criterion is disabled if \fItol\fR is non-positive.
575 .TP
576 .BI "nlopt_result nlopt_set_maxeval(nlopt_opt " "opt" ,
577 .br
578 .BI "                        int " maxeval );
579 .sp
580 Stop when the number of function evaluations exceeds
581 .IR maxeval .
582 (This is not a strict maximum: the number of function evaluations may
583 exceed
584 .I maxeval 
585 slightly, depending upon the algorithm.)  Criterion is disabled
586 if \fImaxeval\fR is non-positive.
587 .TP
588 .BI "nlopt_result nlopt_set_maxtime(nlopt_opt " "opt" ,
589 .br
590 .BI "                        double " maxtime );
591 .sp
592 Stop when the optimization time (in seconds) exceeds
593 .IR maxtime .
594 (This is not a strict maximum: the time may
595 exceed
596 .I maxtime
597 slightly, depending upon the algorithm and on how slow your function
598 evaluation is.)  Criterion is disabled if \fImaxtime\fR is non-positive.
599 .SH RETURN VALUE
600 Most of the NLopt functions return an enumerated constant
601 of type
602 .BR nlopt_result ,
603 which takes on one of the following values:
604 .SS Successful termination (positive return values):
605 .TP
606 .B NLOPT_SUCCESS
607 Generic success return value.
608 .TP
609 .B NLOPT_STOPVAL_REACHED
610 Optimization stopped because
611 .I stopval
612 (above) was reached.
613 .TP
614 .B NLOPT_FTOL_REACHED
615 Optimization stopped because
616 .I ftol_rel
617 or
618 .I ftol_abs
619 (above) was reached.
620 .TP
621 .B NLOPT_XTOL_REACHED
622 Optimization stopped because
623 .I xtol_rel
624 or
625 .I xtol_abs
626 (above) was reached.
627 .TP
628 .B NLOPT_MAXEVAL_REACHED
629 Optimization stopped because
630 .I maxeval
631 (above) was reached.
632 .TP
633 .B NLOPT_MAXTIME_REACHED
634 Optimization stopped because
635 .I maxtime
636 (above) was reached.
637 .SS Error codes (negative return values):
638 .TP
639 .B NLOPT_FAILURE
640 Generic failure code.
641 .TP
642 .B NLOPT_INVALID_ARGS
643 Invalid arguments (e.g. lower bounds are bigger than upper bounds, an
644 unknown algorithm was specified, etcetera).
645 .TP
646 .B NLOPT_OUT_OF_MEMORY
647 Ran out of memory.
648 .TP
649 .B NLOPT_ROUNDOFF_LIMITED
650 Halted because roundoff errors limited progress.
651 .TP
652 .B NLOPT_FORCED_STOP
653 Halted because the user called \fBnlopt_force_stop\fR(\fIopt\fR) on
654 the optimization's \fBnlopt_opt\fR object \fIopt\fR from the user's
655 objective function.
656 .SH LOCAL OPTIMIZER
657 Some of the algorithms, especially MLSL and AUGLAG, use a different
658 optimization algorithm as a subroutine, typically for local
659 optimization.  By default, MLSL uses MMA or COBYLA for gradient-based
660 or derivative-free searching, respectively.  You can change
661 the local search algorithm and its tolerances by calling:
662 .sp
663 .BI "  nlopt_result nlopt_set_local_optimizer(nlopt_opt " "opt" , 
664 .br
665 .BI "                                         const nlopt_opt " "local_opt" );
666 .sp
667 Here, \fIlocal_opt\fR is another \fBnlopt_opt\fR object whose
668 parameters are used to determine the local search algorithm and
669 stopping criteria.  (The objective function, bounds, and
670 nonlinear-constraint parameters of \fIlocal_opt\fR are ignored.)  The
671 dimension \fIn\fR of \fIlocal_opt\fR must match that of \fIopt\fR.
672 .sp
673 This function makes a copy of the \fIlocal_opt\fR object, so you can
674 freely destroy your original \fIlocal_opt\fR afterwards.
675 .SH INITIAL STEP SIZE
676 For derivative-free local-optimization algorithms, the optimizer must
677 somehow decide on some initial step size to perturb \fIx\fR by when it
678 begins the optimization.  This step size should be big enough that the
679 value of the objective changes significantly, but not too big if you
680 want to find the local optimum nearest to \fIx\fR.  By default, NLopt
681 chooses this initial step size heuristically from the bounds,
682 tolerances, and other information, but this may not always be the best
683 choice.
684 .sp
685 You can modify the initial step size by calling:
686 .sp
687 .BI "  nlopt_result nlopt_set_initial_step(nlopt_opt " "opt" , 
688 .br
689 .BI "                                      const double* " "dx" );
690 .sp
691 Here, \fIdx\fR is an array of length \fIn\fR containing the (nonzero)
692 initial step size for each component of the design parameters \fIx\fR.
693 For convenience, if you want to set the step sizes in every direction
694 to be the same value, you can instead call:
695 .sp
696 .BI "  nlopt_result nlopt_set_initial_step1(nlopt_opt " "opt" , 
697 .br
698 .BI "                                       double " "dx" );
699 .SH STOCHASTIC POPULATION
700 Several of the stochastic search algorithms (e.g., CRS, MLSL, and
701 ISRES) start by generating some initial "population" of random points
702 \fIx\fR.  By default, this initial population size is chosen
703 heuristically in some algorithm-specific way, but the initial
704 population can by changed by calling:
705 .sp
706 .BI "  nlopt_result nlopt_set_population(nlopt_opt " "opt" , 
707 .br
708 .BI "                                    unsigned " "pop" );
709 .sp
710 (A \fIpop\fR of zero implies that the heuristic default will be used.)
711 .SH PSEUDORANDOM NUMBERS
712 For stochastic optimization algorithms, we use pseudorandom numbers generated
713 by the Mersenne Twister algorithm, based on code from Makoto Matsumoto.
714 By default, the seed for the random numbers is generated from the system
715 time, so that they will be different each time you run the program.  If
716 you want to use deterministic random numbers, you can set the seed by
717 calling:
718 .sp
719 .BI "            void nlopt_srand(unsigned long " "seed" );
720 .sp
721 Some of the algorithms also support using low-discrepancy sequences (LDS),
722 sometimes known as quasi-random numbers.  NLopt uses the Sobol LDS, which
723 is implemented for up to 1111 dimensions.
724 .SH AUTHORS
725 Written by Steven G. Johnson.
726 .PP
727 Copyright (c) 2007-2010 Massachusetts Institute of Technology.
728 .SH "SEE ALSO"
729 nlopt_minimize(3)