|
NAMEnlopt_minimize_constrained - Minimize a multivariate nonlinear function subject to nonlinear constraintsSYNOPSIS#include <nlopt.h> nlopt_result nlopt_minimize_constrained(nlopt_algorithm algorithm, DESCRIPTIONnlopt_minimize_constrained() attempts to minimize a nonlinear function f of n design variables, subject to m nonlinear constraints described by the function fc (see below), using the specified algorithm. The minimum function value found is returned in minf, with the corresponding design variable values returned in the array x of length n. The input values in x should be a starting guess for the optimum. The inputs lb and ub are arrays of length n containing lower and upper bounds, respectively, on the design variables x. The other parameters specify stopping criteria (tolerances, the maximum number of function evaluations, etcetera) and other information as described in more detail below. The return value is a integer code indicating success (positive) or failure (negative), as described below.By changing the parameter algorithm among several predefined constants described below, one can switch easily between a variety of minimization algorithms. Some of these algorithms require the gradient (derivatives) of the function to be supplied via f, and other algorithms do not require derivatives. Some of the algorithms attempt to find a global minimum within the given bounds, and others find only a local minimum. Most of the algorithms only handle the case where m is zero (no explicit nonlinear constraints); the only algorithms that currently support positive m are NLOPT_LD_MMA and NLOPT_LN_COBYLA. The nlopt_minimize_constrained function is a wrapper around several free/open-source minimization packages, as well as some new implementations of published optimization algorithms. You could, of course, compile and call these packages separately, and in some cases this will provide greater flexibility than is available via the nlopt_minimize_constrained interface. However, depending upon the specific function being minimized, the different algorithms will vary in effectiveness. The intent of nlopt_minimize_constrained is to allow you to quickly switch between algorithms in order to experiment with them for your problem, by providing a simple unified interface to these subroutines. OBJECTIVE FUNCTIONnlopt_minimize_constrained() minimizes an objective function f of the form: double f(int n,
The return value should be the value of the function at the point x, where x points to an array of length n of the design variables. The dimension n is identical to the one passed to nlopt_minimize_constrained(). In addition, if the argument grad is not NULL, then grad points to an array of length n which should (upon return) be set to the gradient of the function with respect to the design variables at x. That is, grad[i] should upon return contain the partial derivative df/dx[i], for 0 <= i < n, if grad is non-NULL. Not all of the optimization algorithms (below) use the gradient information: for algorithms listed as "derivative-free," the grad argument will always be NULL and need never be computed. (For algorithms that do use gradient information, however, grad may still be NULL for some calls.) The f_data argument is the same as the one passed to nlopt_minimize_constrained(), and may be used to pass any additional data through to the function. (That is, it may be a pointer to some caller-defined data structure/type containing information your function needs, which you convert from void* by a typecast.) BOUND CONSTRAINTSMost of the algorithms in NLopt are designed for minimization of functions with simple bound constraints on the inputs. That is, the input vectors x[i] are constrainted to lie in a hyperrectangle lb[i] <= x[i] <= ub[i] for 0 <= i < n, where lb and ub are the two arrays passed to nlopt_minimize_constrained().However, a few of the algorithms support partially or totally unconstrained optimization, as noted below, where a (totally or partially) unconstrained design variable is indicated by a lower bound equal to -Inf and/or an upper bound equal to +Inf. Here, Inf is the IEEE-754 floating-point infinity, which (in ANSI C99) is represented by the macro INFINITY in math.h. Alternatively, for older C versions you may also use the macro HUGE_VAL (also in math.h). With some of the algorithms, especially those that do not require derivative information, a simple (but not especially efficient) way to implement arbitrary nonlinear constraints is to return Inf (see above) whenever the constraints are violated by a given input x. More generally, there are various ways to implement constraints by adding "penalty terms" to your objective function, which are described in the optimization literature. A much more efficient way to specify nonlinear constraints is described below, but is only supported by a small subset of the algorithms. NONLINEAR CONSTRAINTSThe nlopt_minimize_constrained function also allows you to specify m nonlinear constraints via the function fc, where m is any nonnegative integer. However, nonzero m is currently only supported by the NLOPT_LD_MMA and NLOPT_LN_COBYLA algorithms below.In particular, the nonlinear constraints are of the form fc(x) <= 0, where the function fc is of the same form as the objective function described above: double fc(int n,
The return value should be the value of the constraint at the point x, where the dimension n is identical to the one passed to nlopt_minimize_constrained(). As for the objective function, if the argument grad is not NULL, then grad points to an array of length n which should (upon return) be set to the gradient of the function with respect to x. (For any algorithm listed as "derivative-free" below, the grad argument will always be NULL and need never be computed.) The fc_datum argument is based on the fc_data argument passed to nlopt_minimize_constrained(), and may be used to pass any additional data through to the function, and is used to distinguish between different constraints. In particular, the constraint function fc will be called (at most) m times for each x, and the i-th constraint (0 <= i < m) will be passed an fc_datum argument equal to fc_data offset by i * fc_datum_size. For example, suppose that you have a data structure of type "foo" that describes the data needed by each constraint, and you store the information for the constraints in an array "foo data[m]". In this case, you would pass "data" as the fc_data parameter to nlopt_minimize_constrained, and "sizeof(foo)" as the fc_datum_size parameter. Then, your fc function would be called m times for each point, and be passed &data[0] through &data[m-1] in sequence. ALGORITHMSThe algorithm parameter specifies the optimization algorithm (for more detail on these, see the README files in the source-code subdirectories), and can take on any of the following constant values. Constants with _G{N,D}_ in their names refer to global optimization methods, whereas _L{N,D}_ refers to local optimization methods (that try to find a local minimum starting from the starting guess x). Constants with _{G,L}N_ refer to non-gradient (derivative-free) algorithms that do not require the objective function to supply a gradient, whereas _{G,L}D_ refers to derivative-based algorithms that require the objective function to supply a gradient. (Especially for local optimization, derivative-based algorithms are generally superior to derivative-free ones: the gradient is good to have if you can compute it cheaply, e.g. via an adjoint method.)
STOPPING CRITERIAMultiple stopping criteria for the optimization are supported, as specified by the following arguments to nlopt_minimize_constrained(). The optimization halts whenever any one of these criteria is satisfied. In some cases, the precise interpretation of the stopping criterion depends on the optimization algorithm above (although we have tried to make them as consistent as reasonably possible), and some algorithms do not support all of the stopping criteria.Important: you do not need to use all of the stopping criteria! In most cases, you only need one or two, and can set the remainder to values where they do nothing (as described below).
RETURN VALUEThe value returned is one of the following enumerated constants.Successful termination (positive return values):
Error codes (negative return values):
PSEUDORANDOM NUMBERSFor stochastic optimization algorithms, we use pseudorandom numbers generated by the Mersenne Twister algorithm, based on code from Makoto Matsumoto. By default, the seed for the random numbers is generated from the system time, so that they will be different each time you run the program. If you want to use deterministic random numbers, you can set the seed by calling:void nlopt_srand(unsigned long seed); Some of the algorithms also support using low-discrepancy sequences (LDS), sometimes known as quasi-random numbers. NLopt uses the Sobol LDS, which is implemented for up to 1111 dimensions. AUTHORSWritten by Steven G. Johnson.Copyright (c) 2007-2014 Massachusetts Institute of Technology. SEE ALSOnlopt_minimize(3)
Visit the GSP FreeBSD Man Page Interface. |