Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

C# port of COBYLA2 nonlinear constrained optimization method

branch: master
README.rdoc

cscobyla

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.

Links

Usage

The file Cobyla.cs can be included as-is in any C# project, .NET Framework 4.0 or later, Silverlight 4 or later and Windows Phone 7.5 and later.

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.

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, call one of the two overloaded Cobyla.FindMinimum methods:

CobylaExitStatus FindMinimum(CalcfcDelegate calcfc, int n, int m, double[] x, 
                 double rhobeg, double rhoend, int iprint, int maxfun, 
                 out double f, out double[] con, out int iters, TextWriter logger);

CobylaExitStatus FindMinimum(CalcfcDelegate calcfc, int n, int m, double[] x, 
                 double rhobeg, double rhoend, int iprint, int maxfun, TextWriter logger);

where x on input is the initial variable array, rhobeg and rhoend are the initial and final values of the simplex, iprint (0..3) specifies the level of output to the console, maxfun is the maximum allowed number of function evaluations, f is the objective function value and con the constraints function values at variables optimum and iters is the actual number of function evaluations performed in the optimization. If defined, logger is a text writer where output from COBYLA2 is logged. On return x is the optimal obtained variable values. Both methods return final optimization status, which is one of normal termination, maximum iterations reached or diverging rounding errors.

The latter of the two overloaded methods also implements default values as follows: rhobeg = 0.5, rhoend = 1.0e-6, iprint = 2, maxfun = 3500 and logger = null. The method can thus optionally be called as follows, employing the default parameter values in the minimization:

var status = Cobyla.FindMinimum(calcfc, n, m, x);

The MIT License

Copyright © 2012 Anders Gustafsson, Cureos AB.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Revision history

  • May 8, 2012: Updated API, and added description of logger argument.

  • May 2, 2012: Included link to jcobyla.

  • April 20, 2012: Included link to csbobyqa.

  • April 16, 2012: Updated to reflect changes in API.

  • April 14, 2012: Added a section on usage.

  • April 13, 2012: Added a more detailed presentation of the algorithm.

  • April 12, 2012: Initial document.

Something went wrong with that request. Please try again.