Constructing nonlinear constraints

In this section, you will learn about

Declaring Nonlinear Constraint Functions

Like the objective function, the nonlinear constraint functions are classified according to the availability of the derivatives. However, the argument list of the constructors for the two objects differ in the storage types for the function's value, gradient, and Hessian.
• ```typedef void (*USERNLNCON0)(int, const ColumnVector&, ColumnVector&, int&);
```
For a nonlinear constraint the third argument is a ColumnVector because storage is needed for ncnln values. The corresponding declaration for a trig_constraint follows:
```   void trig_constraint(ndim, x, cvalue, result);
```

• ```typedef void (*USERNLNCON1)(int, int, const ColumnVector&, ColumnVector&,
Matrix&, int&);
```
An example for a constraint function with first derivative information available is
```   void rosen_constraint(mode, n, x, cvalue, cJacobian, result);
```
The fifth argument, a Matrix, contains the Jacobian of the constraints.

• ```typedef void (*USERNLNCON2)(int, int, const ColumnVector&, ColumnVector&,
Matrix&, OptppArray<SymmetricMatrix>&, int&);
```
The declaration for a constraint function with analytic Hessian follows:
```   void illum2_constraint(mode, n, x, cvalue, cJacobian, cHessian, result);
```
The sixth argument, an array of symmetric matrices, contains the Hessians of the constraints.
Now, we turn our focus to the construction of nonlinear equations.

Creating Nonlinear Equations

The nonlinear equation is written as

There are two NonLinearEquation constructors. The first constructor requires two parameters, a pointer to an NLP object and an integer argument for the number of nonlinear equations, which defaults to one. The right-hand side is set to zero. For example,

```   NonLinearEquation(NLP* nlprob, int numconstraints = 1);
```

The second constructor

```   NonLinearEquation(NLP* nlprob, const ColumnVector& rhs,
int numconstraints = 1);
```
permits a nonzero value for the right-hand side.

The following code fragment creates

```   //  Number of nonlinear equations
int ncnln    = 3;
ColumnVector b(ncnln);

//  Create a pointer to an NLP object
NLP* nlprob  = new NLP( new NLF1(n, ncnln, nleqn, init_nleqn) );

//  Initialize the right-hand side of the equations
b << 1.0 << 2.0 << 3.0;

//  Create a set of nonlinear equations
NonLinearEquation(nlprob, b, ncnln);
```

Creating Nonlinear Inequalities

In OPT++, the standard form for a nonlinear inequality is

The corresponding constructor is

```   NonLinearInequality(NLP* nlprob, int numconstraints = 1);
```

To define a nonzero right-hand side for the inequalities, use the following constructor:

```   NonLinearInequality(NLP* nlprob, const ColumnVector& rhs,
int numconstraints = 1);
```

If the user wants nonzero upper bounds on the constraints, such as

then they must use the following constructor:

```   NonLinearInequality(NLP* nlprob, const ColumnVector& rhs,
const bool flag, int numconstraints = 1);
```

To create lower and upper bounds for the constraints, use

```   NonLinearInequality(NLP* nlprob, const ColumnVector& lower,
const ColumnVector& upper, int numconstraints = 1);
```
which generates

OPT++ does not support sparse constraints. Therefore, a bound must be given for each variable even if only a subset of the constraints have finite bounds. An infinite lower bound is specified by

Similarly, an infinite upper bound is specified by

Last revised July 13, 2006