
To solve an optimization problem with OPT++, an user must 1) write a C++ main routine which set ups the problem and algorithm and 2) write the C++ code that evaluates the function and and associated constraints. A more detailed explanation and an example appear in the following sections.
The arguments to the constructors must be defined before instantiating the function object. The following description holds for the first four nonlinear function objects, which have identical argument lists. We will define the argument list for the LSQNLF later.
The first argument, ndim, is an integer specifying the dimension of the problem. The second argument, fcn, is a pointer to the subroutine that evaluates the function. The form of this pointer/subroutine is described in more detail in the UserDefined Functions subsection. The third argument, init_fcn, is a pointer to the subroutine that initializes the function. Again, the form of this pointer/subroutine is described in the UserDefined Functions subsection. The final argument, constraint, is a pointer to a constraint object. If the optimization problem of interest has no constraints, this argument can be excluded. Otherwise, it can be constructed as described in the Constraint Setup subsection.
Once the problem has been instantiated, it must be initialized with its initFcn method. More information on these objects and their associated methods can be found in the detailed documentation; however, the tutorials on their usage in the Example Problems section will probably be more useful.
For the LSQNLF object, the first argument, ndim, is an integer specifying the dimension of the problem. The second argument, lsqterms, is an integer specifying the number of least square terms in the function. The third argument, lsqfcn, is a pointer to the subroutine that evaluates the least squares operator. The form of this pointer/subroutine is described in more detail in the UserDefined Functions subsection. The remaining arguments have the same meaning as previously defined.
Setting up the constraints consists of two main steps. The first step defines the different classes of constraints present. The second step rolls them all up into a single object. The most common forms of the necessary constructors are listed here.
The arguments required by the constraint constructors are relatively selfexplanatory, but require some implementation effort. numconstraints is an integer specifying the number of constraints of the type being constructed, lower is a ColumnVector containing the lower bounds on the optimization variables, upper is a ColumnVector containing the upper bounds, A is a Matrix containing the coefficients of the terms in the linear constraints, rhs is a ColumnVector containing the values of the righthand sides of the linear and nonlinear constraints, and nlprob is a function that evaluates the nonlinear constraints. This function is set up in the same manner as the objective function described in the Problem Setup section. The variable, stdFlag is a Boolean variable indicating whether or not inequality constraints are given in standard form. The standard form is given in the detailed documentation. Finally, the single argument, constraints, to the CompoundConstraint constructor is an OptppArray of the constraints created using the constructors of the specific types.
Details about the OptppArray object can be found in the detailed documentation, while information about the ColumnVector and Matrix objects can be found in the NEWMAT documentation. The most useful documentation, however, appears in the Example Problems.
In addition to the main routine, the user must provide additional C++ code that performs the initialization of the problem, the evaluation of the objective function, and the evaluation of any nonlinear constraints. This code must also include the computation of any analytic derivative information that is to be provided. These subroutines may appear in the same file as the main routine or in a separate file, and they must satisfy the interfaces listed below.
The function interfaces are the following:
The arguments of these functions are fairly straightforward. ndim is an integer that specifies the dimension of the problem, x is a ColumnVector that contains the values of the optimization variables, fx is the value of the objective function at x, gx is a ColumnVector containing the gradient of the objective function at x, Hx is a SymmetricMatrix containing the Hessian of the objective function at x, mode is an integer encoding of the type of evaluation requested (i.e., function, gradient, Hessian), and result is an integer encoding of the type of evaluations available. For the least squares operator, lsfx is a ColumnVector with each entry containing the value of one of the least squares terms and lsgx is a Matrix containing the Jacobian of the least squares operator at x. The ColumnVector, Matrix, and SymmetricMatrix objects are described in the NEWMAT documentation. The Example Problems demonstrate how to implement the userdefined functions.
Nonlinear constraints are quite similar in nature to the objective function. In fact, they are constructed using the function objects in the Problem Setup section. The interfaces for the subroutines that evaluate the nonlinear constraints, however, are slightly different from those for evaluating the objective function. The interfaces are as follows:
The arguments of these functions are fairly straightforward. ndim is an integer that specifies the dimension of the problem, x is a ColumnVector that contains the values of the optimization variables, cx is a ColumnVector with each entry containing the value of one of the nonlinear constraints at x, cgx is a Matrix with each column containing the gradient of one of the nonlinear constraints at x, cHx is an OptppArray of SymmetricMatrix with each matrix containing the Hessian of one of the nonlinear constraints at x, mode is an integer encoding of the type of evaluation requested (i.e., function, gradient, Hessian), and result is an integer encoding of the type of evaluations available. A description of OptppArray can be found in the detailed documentation. The ColumnVector and SymmetricMatrix objects are described in the NEWMAT documentation. The Example Problems demonstrate how to implement the userdefined functions. In particular, Example 2 demonstrates the use of constraints.
In these constructors, nlp is the nonlinear function/problem object created as described in the Problem Setup section and gsb is the generating set method described in the Generating Set Search section. All of the Newton methods have a choice of globalization strategy: line search, trust region, or trust regionPDS. Furthermore, there are numerous algorithmic parameters that can be set. These can be found in the detailed documentation for each particular method.
Once the algorithm object has been instantiated and the desired algorithmic parameters set, the problem can then be solved by calling that algorithm's optimize method. Tutorial examples of how to do set up and use the optimization algorithms can be found in the Example Problems.
Previous Section: Installation  Next Section: Alternate Forms of Nonlinear Objects  Back to the Main Page
Last revised July 25, 2006