<p>Is there an open-source alternative to MATLAB's <a href="https://www.mathworks.com/help/optim/index.html;jsessionid=95cd06964ab253598de29e7d0a80" rel="nofollow noreferrer"><code>fmincon</code></a> function for constrained linear optimization? I'm rewriting a MATLAB program to use Python / <a href="https://numpy.org/" rel="nofollow noreferrer">NumPy</a> / <a href="https://scipy.org/" rel="nofollow noreferrer">SciPy</a> 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.</p>

[{'answer_id': 49929, 'author': 'jjnguy', 'author_id': 2598, 'author_profile': 'https://Stackoverflow.com/users/2598', 'pm_score': 1, 'selected': False, 'text': '<p>There is a program called <a href="http://www.scilab.org/" rel="nofollow noreferrer">SciLab</a> that is a MATLAB clone.</p>\n\n<p>I haven\'t used it at all, but it is open source and might have the function you are looking for.</p>\n'}, {'answer_id': 49930, 'author': 'lindelof', 'author_id': 1428, 'author_profile': 'https://Stackoverflow.com/users/1428', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.gnu.org/software/octave/" rel="nofollow noreferrer">GNU Octave</a> is another MATLAB clone that might have what you need.</p>\n'}, {'answer_id': 50041, 'author': 'wcm', 'author_id': 2173, 'author_profile': 'https://Stackoverflow.com/users/2173', 'pm_score': 1, 'selected': False, 'text': '<p>I don\'t know if it\'s in there, but there\'s a python distribution called <a href="http://www.enthought.com/" rel="nofollow noreferrer">Enthought</a> that might have what you\'re looking for.  It was designed specifically for data analysis has over 60 additional libraries.</p>\n'}, {'answer_id': 70798, 'author': 'WalkingRandomly', 'author_id': 1856916, 'author_profile': 'https://Stackoverflow.com/users/1856916', 'pm_score': 4, 'selected': False, 'text': '<p>The open source Python package,<a href="http://www.scipy.org/" rel="noreferrer">SciPy</a>, 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</p>\n\n<p>help(scipy.optimize)</p>\n\n<p>The resulting document is extensive and includes the following which I believe might be of use to you.</p>\n\n<pre><code>   Constrained Optimizers (multivariate)\n\n   fmin_l_bfgs_b -- Zhu, Byrd, and Nocedal\'s L-BFGS-B constrained optimizer\n                      (if you use this please quote their papers -- see help)\n\n   fmin_tnc      -- Truncated Newton Code originally written by Stephen Nash and\n                      adapted to C by Jean-Sebastien Roy.\n\n   fmin_cobyla   -- Constrained Optimization BY Linear Approximation\n</code></pre>\n'}, {'answer_id': 196806, 'author': 'user27315', 'author_id': 27315, 'author_profile': 'https://Stackoverflow.com/users/27315', 'pm_score': 6, 'selected': True, 'text': "<p>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)</p>\n<ul>\n<li>Linear Program (LP)</li>\n<li>Quadratic Program (QP)</li>\n<li>Convex Quadratically-Constrained Quadratic Program (QCQP)</li>\n<li>Second Order Cone Program (SOCP)</li>\n<li>Semidefinite Program (SDP)</li>\n<li>Non-Linear Convex Problem</li>\n<li>Non-Convex Problem</li>\n</ul>\n<p>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.</p>\n<p>The CVXOpt package will be of great use to you if your problem is convex.</p>\n<p>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.</p>\n"}, {'answer_id': 444167, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Have a look at <a href="http://www.aemdesign.com/downloadfsqp.htm" rel="nofollow noreferrer">http://www.aemdesign.com/downloadfsqp.htm</a>.</p>\n\n<p>There you will find C code which provides the same functionality as <code>fmincon</code>. (However, using a different algorithm. You can read the manual if you are interested in the details.)</p>\n\n<p>It\'s open source but not under GPL. </p>\n'}, {'answer_id': 765053, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>For numerical optimization in Python you may take a look at OpenOpt solvers:</p>\n\n<p><a href="http://openopt.org/NLP" rel="nofollow noreferrer">http://openopt.org/NLP</a></p>\n\n<p><a href="http://openopt.org/Problems" rel="nofollow noreferrer">http://openopt.org/Problems</a></p>\n'}, {'answer_id': 1856211, 'author': 'Alex', 'author_id': 225901, 'author_profile': 'https://Stackoverflow.com/users/225901', 'pm_score': 4, 'selected': False, 'text': '<p>Python optimization software:</p>\n\n<ul>\n<li><p><strong>OpenOpt</strong> <a href="http://openopt.org" rel="noreferrer">http://openopt.org</a> <strong>(this one is numpy-based as you wish, with automatic differentiation by FuncDesigner)</strong></p></li>\n<li><p><strong>Pyomo</strong> <a href="https://software.sandia.gov/trac/coopr/wiki/Package/pyomo" rel="noreferrer">https://software.sandia.gov/trac/coopr/wiki/Package/pyomo</a></p></li>\n<li><p><strong>CVXOPT</strong> <a href="http://abel.ee.ucla.edu/cvxopt/" rel="noreferrer">http://abel.ee.ucla.edu/cvxopt/</a></p></li>\n<li><p><strong>NLPy</strong> <a href="http://nlpy.sourceforge.net/" rel="noreferrer">http://nlpy.sourceforge.net/</a></p></li>\n</ul>\n'}, {'answer_id': 67208467, 'author': 'Stéphane Mottelet', 'author_id': 9595931, 'author_profile': 'https://Stackoverflow.com/users/9595931', 'pm_score': 0, 'selected': False, 'text': '<p>Scilab has an implementation of fmincon (using IPOpt) which is now regularly updated:</p>\n<p><a href="https://atoms.scilab.org/toolboxes/fmincon" rel="nofollow noreferrer">https://atoms.scilab.org/toolboxes/fmincon</a></p>\n<p>For large-scale optimization it outperforms Matlab\'s fmincon.</p>\n'}, {'answer_id': 68615890, 'author': 'Luis Ramon Merchan', 'author_id': 16574729, 'author_profile': 'https://Stackoverflow.com/users/16574729', 'pm_score': 1, 'selected': False, 'text': '<p>Octave in the latest version implements an equivalent to the Matlab fmincon function into the optimization package.</p>\n<p><a href="https://octave.sourceforge.io/optim/function/fmincon.html" rel="nofollow noreferrer">https://octave.sourceforge.io/optim/function/fmincon.html</a></p>\n'}]
['https://Stackoverflow.com/questions/49926', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3002/']