Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
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.
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.
Python optimization software:
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/
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
GNU Octave is another MATLAB clone that might have what you need.
For numerical optimization in Python you may take a look at OpenOpt solvers:
http://openopt.org/NLP
http://openopt.org/Problems
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.
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.
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.
Octave in the latest version implements an equivalent to the Matlab fmincon function into the optimization package.
https://octave.sourceforge.io/optim/function/fmincon.html
Scilab has an implementation of fmincon (using IPOpt) which is now regularly updated:
https://atoms.scilab.org/toolboxes/fmincon
For large-scale optimization it outperforms Matlab's fmincon.
Related
I'm currently working on an LP optimization problem with and looked into PuLP.
I know that PuLPs default solver is: PULP-CBC-CMD. I solved a test problem with this and I'm wondering what kind of algorithm this solver actually uses... it doesnt seem to be a simplex as my problem got interpreted completely differently than a simplex interpretion would look like?
Also: Every other solver for PuLP has to be added to PuLP manually right?
Also: what solvers are you guys working with in python?
Thanks in advance!
CBC is based on simplex, yes. But, like most solvers, it combines simplex with many other algorithms such as branch-and-bound and cut-generation.
In particular, to solve linear programs it uses Clp: https://github.com/coin-or/Clp
More information on the CBC solver in their site: https://github.com/coin-or/Cbc
Is there any python implementation available of TSP using the IBM cplex tool, with Dantzig-Fulkerson-Johnson formulation.
If there is any can I get the link for it?
The exact same question was asked here. Here is my (slightly modified) answer from there:
The distribution does not have an example implementation in Python, but there is one in OPL: opl/examples/opl/models/TravelingSalesmanProblem/tsp.mod in your installation. This could serve as a good starting point when implementing things in Python.
In the example the problem is solved in a loop: after each solve, subtour elimination constraints are separated. In Python you would probably want to do this using a lazy constraint callback.
In general, subtour elimination constraints are usually not added directly to the model since there exponentially many of them.
I currently solve optimization problems with complex variables using CVX + Mosek, on MATLAB. I'm now considering switching to Gurobi + Python for some applications.
Is there a way to declare complex values (both inside constraints and as optimization variables) directly into Gurobi's Python interface?
If not, which are good modeling languages, with Python interface, that automates the reduction of the problem to real variables before calling the solver?
I know, for instance, that YALMIP does this reduction (though no Python interface), and newer versions of CVXPY also (but I haven't used it extensively, and don't know if it already has good performance, is stable, and reasonably complete). Any thoughts on these issues and recommendations of other interfaces are thus welcome.
The only possible variables in Gurobi are:
Integer;
Binary;
Continuous;
Semi-Continuous and;
Semi-Integer.
Also, I don't know the problem you're trying to solve, but complex number are quite strange for linear optimization.
The complex plane isn't a ordered field, so that is not possible to say that a given complex number z1 > z2
You'll probably have to model your problem in such way that you can decompose the constraints with real and imaginary parts, so that you can work only with real numbers.
I am working on a Python package for computing several NP-Hard graph invariants. The current version of the package uses brute force for nearly all of the algorithms, but I am very interested in using integer programming to help speed up the computations for larger graphs.
For example, a simple integer program for solving the independence number of an n-vertex graph is to maximize given the constraints , where .
How do I solve this using PuLP? Is PuLP my best option, or would it be beneficial to use solvers in another language, like Julia, and interface may package with those?
I don't propose to write your full implementation for you, but to address the final question about PuLP versus other languages.
PuLP provides a Python wrapper over a range of existing LP Solvers.
Once you have specified your problem with a Python syntax, it converts it to another language internally (e.g. you can save .lp files, and inspect them) and passes that to any one of a number of third-party solvers, that generally aren't written in Python.
So there is no need to learn another language to get a better solver.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Are there any scientific packages for Lua comparable to Scipy?
You should try Torch7 (github).
Torch7 has a very nice and efficient vector/matrix/tensor numerical library
with a Lua front-end. It also has a bunch of functions for computer vision
and machine learning.
It's pretty recent but getting better quickly.
One can always use Lunatic Python and access scipy inside lua.
> require("python")
> numpy = python.import("numpy")
> numpy.array ... etc ..
You have some options:
Numeric Lua - C module for Lua 5.1/5.2, provides matrices, FFT, complex numbers and others
GSL Shell - Modification of Lua (supports Lua libraries) with a nice syntax. Provides almost everything that Numeric Lua does, plus ODE solvers, plotting capabilities, and other nice things. Has a great documentation.
SciLua - Pure LuaJIT module. Aims to be a complete framework for scientific computing in Lua. Provides vectors and matrices, random numbers / distributions, optimization, others. Still in early development.
Lua Numerical Algorithms - Pure LuaJIT module (uses blas/lapack via LuaJIT FFI). Provides matrices / linear algebra, FFT, complex numbers, optimization algorithms, ODE solver, basic statistics (+ PCA, LDA), and others. Still in early development, but has a somewhat complete documentation and test suits.
There is the basis for one in Numeric Lua.
I'm not sure if it is comparable to Scipy, but there is GSL Shell which is based on LuaJIT and GNU Scientific Library, which offers many numerical algorithms and vector/matrix linear algebra operations.
There's a Numpy-like extension for Lua which runs without dependencies at
https://github.com/jzrake/lunum
In the future it will provide FFT's and linear algebra like Numpy+Scipy. Presently it supports numeric array manipulation like in Numpy.