Skip to content
Anders Gustafsson edited this page Jul 30, 2014 · 2 revisions

Constrained Optimization BY Linear Approximation for .NET

COBYLA2 is an implementation of Powell's nonlinear derivative-free constrained optimization that uses a linear approximation approach. The algorithm is a sequential trust-region algorithm that employs linear approximations to the objective and constraint functions, where the approximations are formed by linear interpolation at n + 1 points in the space of the variables and tries to maintain a regular-shaped simplex over iterations.

It solves nonsmooth NLP with a moderate number of variables (about 100). Inequality constraints only.

The initial point X is taken as one vertex of the initial simplex with zero being another, so, X should not be entered as the zero vector.

Usage

The C# implementation is relatively faithful to the original Fortran 77 and 90 implementations. It should be noted however that the indexing of the variables and constraints arrays in the public interface is zero-based, i.e. for a problem with 3 variables, x[0], x[1] and x[2] should be employed in the objective and constraints function evaluations.

COBYLA solves the following optimization task:

minimize F(x)
subject to Cj (x) ≥ 0, j = 1, ..., m

Implement a method for computing objective function and (potentially) constraints functions with the following signature:

void calcfc(int n, int m, double[] x, out double f, double[] con)

where n is the number of variables, m is the number of constraints, x is the variable array, f is the calculated objective function value and con is the array of calculated constraints function values.

To minimize the objective function subject to constraints, initialize a Cobyla instance and call the FindMinimum method:

var optimizer = new Cobyla(n, m, calcfc);
var result = optimizer.FindMinimum(x0);

where x0 is the initial variable array.

You may additionally set Cobyla properties TrustRegionRadiusStart and TrustRegionRadiusEnd, MaximumFunctionCalls which is the maximum allowed number of function evaluations, PrintLevel (0..3) which specifies the level of output, and Logger which is a text writer to where COBYLA's log will be output.

Upon instantiation, Cobyla applies these default values as follows: TrustRegionRadiusStart = 0.5, TrustRegionRadiusEnd = 1.0e-6, MaximumFunctionCalls = 10000, PrintLevel = 1 and Logger = null.

The FindMinimum method returns the result as an OptimizationResult object containing:

OptimizationStatus Status   /* Optimization status upon exit from BOBYQA */
int                Evals    /* Total number of function evaluations */
double[]           X        /* Optimal values of the optimization variables */
double             F        /* Optimal value of the objective function */
double[]           G        /* Values of the constraint functions at optimum */

Links

Clone this wiki locally