Formulate optimization problems using sympy expressions and solve them using interfaces to third-party optimization software (e.g. GLPK).
Project description
`|Build Status| <https://travis-ci.org/biosustain/optlang>`_ `|Coverage
Status| <https://coveralls.io/r/biosustain/optlang?branch=master>`_
`|PyPI version| <http://badge.fury.io/py/optlang>`_ `|Documentation
Status| <https://readthedocs.org/projects/optlang/?badge=latest>`_
optlang
=======
Vision
~~~~~~
**optlang** provides a common interface to a series of optimization
solvers (linear & non-linear) and relies on
`sympy <http://sympy.org/en/index.html>`_ for problem formulation
(constraints, objectives, variables, etc.). Adding new solvers is easy:
just sub-class the high-level interface and implement the necessary
solver specific routines.
Installation
~~~~~~~~~~~~
Install using pip
::
pip install optlang
or
::
pip install -e git+https://github.com/biosustain/optlang.git@master#egg=optlang
if you want to work with the latest stable version.
Local installations like
::
python setup.py install
might fail installing the dependencies (unresolved issue with
``easy_install``). Running
::
pip install -r requirements.txt
beforehand should fix this issue.
Documentation
~~~~~~~~~~~~~
The documentation for **optlang** is provided at
`readthedocs.org <http://optlang.readthedocs.org/en/latest/>`_.
Dependencies
~~~~~~~~~~~~
- `sympy >= 0.7.5 <http://sympy.org/en/index.html>`_
- `swiglpk >= 0.1.0 <https://pypi.python.org/pypi/swiglpk>`_
- `glpk >= 4.45 <https://www.gnu.org/software/glpk/>`_
Example
~~~~~~~
Formulating and solving the problem is straightforward (example taken
from `GLPK documentation <http://www.gnu.org/software/glpk>`_):
::
from optlang import Model, Variable, Constraint, Objective
x1 = Variable('x1', lb=0)
x2 = Variable('x2', lb=0)
x3 = Variable('x3', lb=0)
c1 = Constraint(x1 + x2 + x3, ub=100)
c2 = Constraint(10 * x1 + 4 * x2 + 5 * x3, ub=600)
c3 = Constraint(2 * x1 + 2 * x2 + 6 * x3, ub=300)
obj = Objective(10 * x1 + 6 * x2 + 4 * x3, direction='max')
model = Model(name='Simple model')
model.objective = obj
model.add([c1, c2, c3])
status = model.optimize()
print "status:", model.status
print "objective value:", model.objective.value
for var_name, var in model.variables.iteritems():
print var_name, "=", var.primal
The example will produce the following output:
::
status: optimal
objective value: 733.333333333
x2 = 66.6666666667
x3 = 0.0
x1 = 33.3333333333
Future outlook
~~~~~~~~~~~~~~
- `Gurobi <http://www.gurobi.com/>`_ interface (very efficient MILP
solver)
- `CPLEX <http://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`_
interface (very efficient MILP solver)
- `Mosek <http://www.mosek.com/>`_ interface (provides academic
licenses)
- `GAMS <http://www.gams.com/>`_ output (support non-linear problem
formulation)
- `DEAP <https://code.google.com/p/deap/>`_ (support for heuristic
optimization)
- Interface to `NEOS <http://www.neos-server.org/neos/>`_ optimization
server (for testing purposes and solver evaluation)
- Automatically handle fractional and absolute value problems when
dealing with LP/MILP/QP solvers (like GLPK,
`CPLEX <http://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`_
etc.)
Requirements
~~~~~~~~~~~~
- Models should always be serializable to common problem formulation
languages
(`CPLEX <http://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`_,
`GAMS <http://www.gams.com/>`_, etc.)
- Models should be pickable
- Common solver configuration interface (presolver, MILP gap, etc.)
.. |Build
Status| image:: https://travis-ci.org/biosustain/optlang.png?branch=master
.. |Coverage
Status| image:: https://coveralls.io/repos/biosustain/optlang/badge.png?branch=master
.. |PyPI version| image:: https://badge.fury.io/py/optlang.svg
.. |Documentation
Status| image:: https://readthedocs.org/projects/optlang/badge/?version=latest
Status| <https://coveralls.io/r/biosustain/optlang?branch=master>`_
`|PyPI version| <http://badge.fury.io/py/optlang>`_ `|Documentation
Status| <https://readthedocs.org/projects/optlang/?badge=latest>`_
optlang
=======
Vision
~~~~~~
**optlang** provides a common interface to a series of optimization
solvers (linear & non-linear) and relies on
`sympy <http://sympy.org/en/index.html>`_ for problem formulation
(constraints, objectives, variables, etc.). Adding new solvers is easy:
just sub-class the high-level interface and implement the necessary
solver specific routines.
Installation
~~~~~~~~~~~~
Install using pip
::
pip install optlang
or
::
pip install -e git+https://github.com/biosustain/optlang.git@master#egg=optlang
if you want to work with the latest stable version.
Local installations like
::
python setup.py install
might fail installing the dependencies (unresolved issue with
``easy_install``). Running
::
pip install -r requirements.txt
beforehand should fix this issue.
Documentation
~~~~~~~~~~~~~
The documentation for **optlang** is provided at
`readthedocs.org <http://optlang.readthedocs.org/en/latest/>`_.
Dependencies
~~~~~~~~~~~~
- `sympy >= 0.7.5 <http://sympy.org/en/index.html>`_
- `swiglpk >= 0.1.0 <https://pypi.python.org/pypi/swiglpk>`_
- `glpk >= 4.45 <https://www.gnu.org/software/glpk/>`_
Example
~~~~~~~
Formulating and solving the problem is straightforward (example taken
from `GLPK documentation <http://www.gnu.org/software/glpk>`_):
::
from optlang import Model, Variable, Constraint, Objective
x1 = Variable('x1', lb=0)
x2 = Variable('x2', lb=0)
x3 = Variable('x3', lb=0)
c1 = Constraint(x1 + x2 + x3, ub=100)
c2 = Constraint(10 * x1 + 4 * x2 + 5 * x3, ub=600)
c3 = Constraint(2 * x1 + 2 * x2 + 6 * x3, ub=300)
obj = Objective(10 * x1 + 6 * x2 + 4 * x3, direction='max')
model = Model(name='Simple model')
model.objective = obj
model.add([c1, c2, c3])
status = model.optimize()
print "status:", model.status
print "objective value:", model.objective.value
for var_name, var in model.variables.iteritems():
print var_name, "=", var.primal
The example will produce the following output:
::
status: optimal
objective value: 733.333333333
x2 = 66.6666666667
x3 = 0.0
x1 = 33.3333333333
Future outlook
~~~~~~~~~~~~~~
- `Gurobi <http://www.gurobi.com/>`_ interface (very efficient MILP
solver)
- `CPLEX <http://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`_
interface (very efficient MILP solver)
- `Mosek <http://www.mosek.com/>`_ interface (provides academic
licenses)
- `GAMS <http://www.gams.com/>`_ output (support non-linear problem
formulation)
- `DEAP <https://code.google.com/p/deap/>`_ (support for heuristic
optimization)
- Interface to `NEOS <http://www.neos-server.org/neos/>`_ optimization
server (for testing purposes and solver evaluation)
- Automatically handle fractional and absolute value problems when
dealing with LP/MILP/QP solvers (like GLPK,
`CPLEX <http://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`_
etc.)
Requirements
~~~~~~~~~~~~
- Models should always be serializable to common problem formulation
languages
(`CPLEX <http://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`_,
`GAMS <http://www.gams.com/>`_, etc.)
- Models should be pickable
- Common solver configuration interface (presolver, MILP gap, etc.)
.. |Build
Status| image:: https://travis-ci.org/biosustain/optlang.png?branch=master
.. |Coverage
Status| image:: https://coveralls.io/repos/biosustain/optlang/badge.png?branch=master
.. |PyPI version| image:: https://badge.fury.io/py/optlang.svg
.. |Documentation
Status| image:: https://readthedocs.org/projects/optlang/badge/?version=latest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
optlang-0.2.3.tar.gz
(41.2 kB
view hashes)