views:

3803

answers:

8

Is there an open-source alternative to MATLAB's fmincon function for constrained linear optimization? I'm rewriting a MATLAB program to use Python / NumPy / SciPy and this is the only function I haven't found an equivalent to. A NumPy-based solution would be ideal, but any language will do.

+1  A: 

There is a program called SciLab that is a MATLAB clone.

I haven't used it at all, but it is open source and might have the function you are looking for.

jjnguy
+1  A: 

GNU Octave is another MATLAB clone that might have what you need.

lindelof
A: 

I don't know if it's in there, but there's a python distribution called Enthought that might have what you're looking for. It was designed specifically for data analysis has over 60 additional libraries.

wcm
Two other people added links that weren't sure whether or not their suggestions would have what the original poster wanted. Why the down votes. A comment would be nice here.
wcm
+6  A: 

The open source Python package,SciPy, has quite a large set of optimization routines including some for multivariable problems with constraints (which is what fmincon does I believe). Once you have SciPy installed type the following at the Python command prompt

help(scipy.optimize)

The resulting document is extensive and includes the following which I believe might be of use to you.

   Constrained Optimizers (multivariate)

   fmin_l_bfgs_b -- Zhu, Byrd, and Nocedal's L-BFGS-B constrained optimizer
                      (if you use this please quote their papers -- see help)

   fmin_tnc      -- Truncated Newton Code originally written by Stephen Nash and
                      adapted to C by Jean-Sebastien Roy.

   fmin_cobyla   -- Constrained Optimization BY Linear Approximation
MikeCroucher
+10  A: 

Is your problem convex? Linear? Non-linear? I agree that SciPy.optimize will probably do the job, but fmincon is a sort of bazooka for solving optimization problems, and you'll be better off if you can confine it to one of the categories below (in increasing level of difficulty to solve efficiently)

Linear Program (LP) Quadratic Program (QP) Convex Quadratically-Constrained Quadratic Program (QCQP) Second Order Cone Program (SOCP) Semidefinite Program (SDP) Non-Linear Convex Problem Non-Convex Problem

There are also combinatoric problems such as Mixed-Integer Linear Programs (MILP), but you didn't mention any sort of integrality constraints, suffice to say that they fall into a different class of problems.

The CVXOpt package will be of great use to you if your problem is convex.

If your problem is not convex, you need to choose between finding a local solution or the global solution. Many convex solvers 'sort of' work in a non-convex domain. Finding a good approximation to the global solution would require some form Simulated Annealing or Genetic Algorithm. Finding the global solution will require an enumeration of all local solutions or a combinatorial strategy such as Branch and Bound.

+1  A: 

Have a look at http://www.aemdesign.com/downloadfsqp.htm.

There you will find C code which provides the same functionality as fmincon. (However, using a different algorithm. You can read the manual if you are interested in the details.)

It's open source but not under GPL.

+2  A: 

For numerical optimization in Python you may take a look at OpenOpt solvers:

http://openopt.org/NLP

http://openopt.org/Problems

+2  A: 

Python optimization soft:

  • OpenOpt http://openopt.org (this one is numpy-based as you wish, with automatic differentiation by FuncDesigner)

  • Pyomo https ://software.sandia.gov/trac/coopr/wiki/Package/pyomo

  • CVXOPT http ://abel.ee.ucla.edu/cvxopt/

  • NLPy http ://nlpy.sourceforge.net/

I have inserted spaces because stackoverflow says "we're sorry, but as a spam prevention mechanism, new users can only post a maximum of one hyperlink. Earn 10 reputation to post more hyperlinks."

Alex