optlang


Nameoptlang JSON
Version 1.8.1 PyPI version JSON
download
home_pagehttps://github.com/opencobra/optlang
SummaryFormulate optimization problems using sympy expressions and solve them using interfaces to third-party optimization software (e.g. GLPK).
upload_time2023-10-29 19:52:58
maintainer
docs_urlNone
authorNikolaus Sonnenschein
requires_python>=3.8
licenseApache-2.0
keywords optimization mathematical programming heuristic optimization sympy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            optlang
=======

*Sympy based mathematical programming language*

|PyPI| |Python Versions| |License| |Code of Conduct| |GitHub Actions| |Coverage Status| |Documentation Status| |Gitter| |JOSS| |DOI|

Optlang is a Python package for solving mathematical optimization
problems, i.e. maximizing or minimizing an objective function over a set
of variables subject to a number of constraints. Optlang provides a
common interface to a series of optimization tools, so different solver
backends can be changed in a transparent way.
Optlang's object-oriented API takes advantage of the symbolic math library
`sympy <http://sympy.org/en/index.html>`__ to allow objective functions
and constraints to be easily formulated from symbolic expressions of
variables (see examples).

Show us some love by staring this repo if you find optlang useful!

Also, please use the GitHub `issue tracker <https://github.com/biosustain/optlang/issues>`_
to let us know about bugs or feature requests, or our `gitter channel <https://gitter.im/biosustain/optlang>`_ if you have problems or questions regarding optlang.

Installation
~~~~~~~~~~~~

Install using pip

::

    pip install optlang

This will also install `swiglpk <https://github.com/biosustain/swiglpk>`_, an interface to the open source (mixed integer) LP solver `GLPK <https://www.gnu.org/software/glpk/>`_.
Quadratic programming (and MIQP) is supported through additional optional solvers (see below).

Dependencies
~~~~~~~~~~~~

The following dependencies are needed.

-  `sympy >= 1.0.0 <http://sympy.org/en/index.html>`__
-  `six >= 1.9.0 <https://pypi.python.org/pypi/six>`__
-  `swiglpk >= 1.4.3 <https://pypi.python.org/pypi/swiglpk>`__

The following are optional dependencies that allow other solvers to be used.

-  `cplex <https://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`__ (LP, MILP, QP, MIQP)
-  `gurobipy <http://www.gurobi.com>`__ (LP, MILP, QP, MIQP)
-  `scipy <http://www.scipy.org>`__ (LP)
-  `osqp <https://osqp.org/>`__ (LP, QP)



Example
~~~~~~~

Formulating and solving the problem is straightforward (example taken
from `GLPK documentation <http://www.gnu.org/software/glpk>`__):

.. code-block:: python

    from __future__ import print_function
    from optlang import Model, Variable, Constraint, Objective

    # All the (symbolic) variables are declared, with a name and optionally a lower and/or upper bound.
    x1 = Variable('x1', lb=0)
    x2 = Variable('x2', lb=0)
    x3 = Variable('x3', lb=0)

    # A constraint is constructed from an expression of variables and a lower and/or upper bound (lb and ub).
    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)

    # An objective can be formulated
    obj = Objective(10 * x1 + 6 * x2 + 4 * x3, direction='max')

    # Variables, constraints and objective are combined in a Model object, which can subsequently be optimized.
    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)
    print("----------")
    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

Using a particular solver
-------------------------
If you have more than one solver installed, it's also possible to specify which one to use, by importing directly from the
respective solver interface, e.g. :code:`from optlang.glpk_interface import Model, Variable, Constraint, Objective`

Documentation
~~~~~~~~~~~~~

Documentation for optlang is provided at
`readthedocs.org <http://optlang.readthedocs.org/en/latest/>`__.

Citation
~~~~~~~~

Please cite |JOSS| if you use optlang in a scientific publication. In case you would like to reference a specific version of of optlang you can also include the respective Zenodo DOI (|DOI| points to the latest version).

Contributing
~~~~~~~~~~~~

Please read `<CONTRIBUTING.md>`__.

Funding
~~~~~~~

The development of optlang was partly support by the Novo Nordisk Foundation.

Future outlook
~~~~~~~~~~~~~~

-  `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.)

.. |PyPI| image:: https://img.shields.io/pypi/v/optlang.svg
   :target: https://pypi.org/project/optlang/
   :alt: Current PyPI Version
.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/optlang.svg
   :target: https://pypi.org/project/optlang/
   :alt: Supported Python Versions
.. |License| image:: https://img.shields.io/pypi/l/optlang.svg
   :target: https://www.apache.org/licenses/LICENSE-2.0
   :alt: Apache Software License Version 2.0
.. |Code of Conduct| image:: https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg
   :target: .github/CODE_OF_CONDUCT.md
   :alt: Code of Conduct
.. |GitHub Actions| image:: https://github.com/opencobra/optlang/workflows/CI-CD/badge.svg
   :target: https://github.com/opencobra/optlang/workflows/CI-CD
   :alt: GitHub Actions
.. |Coverage Status| image:: https://codecov.io/gh/opencobra/optlang/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/opencobra/optlang
   :alt: Codecov
.. |Documentation Status| image:: https://readthedocs.org/projects/optlang/badge/?version=latest
   :target: https://readthedocs.org/projects/optlang/?badge=latest
   :alt: Documentation Status
.. |JOSS|  image:: http://joss.theoj.org/papers/cd848071a664d696e214a3950c840e15/status.svg
   :target: http://joss.theoj.org/papers/cd848071a664d696e214a3950c840e15
   :alt: Publication
.. |DOI| image:: https://zenodo.org/badge/5031/biosustain/optlang.svg
   :target: https://zenodo.org/badge/latestdoi/5031/biosustain/optlang
   :alt: Zenodo Source Code
.. |Gitter| image:: https://badges.gitter.im/biosustain/optlang.svg
   :target: https://gitter.im/biosustain/optlang?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
   :alt: Join the chat at https://gitter.im/biosustain/optlang


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/opencobra/optlang",
    "name": "optlang",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "optimization,mathematical programming,heuristic optimization,sympy",
    "author": "Nikolaus Sonnenschein",
    "author_email": "niko.sonnenschein@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/86/c4/321180666e3d51286977f1d0b4a16ee693785c28041d3ce0f2ea7038ac91/optlang-1.8.1.tar.gz",
    "platform": null,
    "description": "optlang\n=======\n\n*Sympy based mathematical programming language*\n\n|PyPI| |Python Versions| |License| |Code of Conduct| |GitHub Actions| |Coverage Status| |Documentation Status| |Gitter| |JOSS| |DOI|\n\nOptlang is a Python package for solving mathematical optimization\nproblems, i.e. maximizing or minimizing an objective function over a set\nof variables subject to a number of constraints. Optlang provides a\ncommon interface to a series of optimization tools, so different solver\nbackends can be changed in a transparent way.\nOptlang's object-oriented API takes advantage of the symbolic math library\n`sympy <http://sympy.org/en/index.html>`__ to allow objective functions\nand constraints to be easily formulated from symbolic expressions of\nvariables (see examples).\n\nShow us some love by staring this repo if you find optlang useful!\n\nAlso, please use the GitHub `issue tracker <https://github.com/biosustain/optlang/issues>`_\nto let us know about bugs or feature requests, or our `gitter channel <https://gitter.im/biosustain/optlang>`_ if you have problems or questions regarding optlang.\n\nInstallation\n~~~~~~~~~~~~\n\nInstall using pip\n\n::\n\n    pip install optlang\n\nThis will also install `swiglpk <https://github.com/biosustain/swiglpk>`_, an interface to the open source (mixed integer) LP solver `GLPK <https://www.gnu.org/software/glpk/>`_.\nQuadratic programming (and MIQP) is supported through additional optional solvers (see below).\n\nDependencies\n~~~~~~~~~~~~\n\nThe following dependencies are needed.\n\n-  `sympy >= 1.0.0 <http://sympy.org/en/index.html>`__\n-  `six >= 1.9.0 <https://pypi.python.org/pypi/six>`__\n-  `swiglpk >= 1.4.3 <https://pypi.python.org/pypi/swiglpk>`__\n\nThe following are optional dependencies that allow other solvers to be used.\n\n-  `cplex <https://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`__ (LP, MILP, QP, MIQP)\n-  `gurobipy <http://www.gurobi.com>`__ (LP, MILP, QP, MIQP)\n-  `scipy <http://www.scipy.org>`__ (LP)\n-  `osqp <https://osqp.org/>`__ (LP, QP)\n\n\n\nExample\n~~~~~~~\n\nFormulating and solving the problem is straightforward (example taken\nfrom `GLPK documentation <http://www.gnu.org/software/glpk>`__):\n\n.. code-block:: python\n\n    from __future__ import print_function\n    from optlang import Model, Variable, Constraint, Objective\n\n    # All the (symbolic) variables are declared, with a name and optionally a lower and/or upper bound.\n    x1 = Variable('x1', lb=0)\n    x2 = Variable('x2', lb=0)\n    x3 = Variable('x3', lb=0)\n\n    # A constraint is constructed from an expression of variables and a lower and/or upper bound (lb and ub).\n    c1 = Constraint(x1 + x2 + x3, ub=100)\n    c2 = Constraint(10 * x1 + 4 * x2 + 5 * x3, ub=600)\n    c3 = Constraint(2 * x1 + 2 * x2 + 6 * x3, ub=300)\n\n    # An objective can be formulated\n    obj = Objective(10 * x1 + 6 * x2 + 4 * x3, direction='max')\n\n    # Variables, constraints and objective are combined in a Model object, which can subsequently be optimized.\n    model = Model(name='Simple model')\n    model.objective = obj\n    model.add([c1, c2, c3])\n\n    status = model.optimize()\n\n    print(\"status:\", model.status)\n    print(\"objective value:\", model.objective.value)\n    print(\"----------\")\n    for var_name, var in model.variables.iteritems():\n        print(var_name, \"=\", var.primal)\n\nThe example will produce the following output:\n\n::\n\n    status: optimal\n    objective value: 733.333333333\n    ----------\n    x2 = 66.6666666667\n    x3 = 0.0\n    x1 = 33.3333333333\n\nUsing a particular solver\n-------------------------\nIf you have more than one solver installed, it's also possible to specify which one to use, by importing directly from the\nrespective solver interface, e.g. :code:`from optlang.glpk_interface import Model, Variable, Constraint, Objective`\n\nDocumentation\n~~~~~~~~~~~~~\n\nDocumentation for optlang is provided at\n`readthedocs.org <http://optlang.readthedocs.org/en/latest/>`__.\n\nCitation\n~~~~~~~~\n\nPlease cite |JOSS| if you use optlang in a scientific publication. In case you would like to reference a specific version of of optlang you can also include the respective Zenodo DOI (|DOI| points to the latest version).\n\nContributing\n~~~~~~~~~~~~\n\nPlease read `<CONTRIBUTING.md>`__.\n\nFunding\n~~~~~~~\n\nThe development of optlang was partly support by the Novo Nordisk Foundation.\n\nFuture outlook\n~~~~~~~~~~~~~~\n\n-  `Mosek <http://www.mosek.com/>`__ interface (provides academic\n   licenses)\n-  `GAMS <http://www.gams.com/>`__ output (support non-linear problem\n   formulation)\n-  `DEAP <https://code.google.com/p/deap/>`__ (support for heuristic\n   optimization)\n-  Interface to `NEOS <http://www.neos-server.org/neos/>`__ optimization\n   server (for testing purposes and solver evaluation)\n-  Automatically handle fractional and absolute value problems when\n   dealing with LP/MILP/QP solvers (like GLPK,\n   `CPLEX <http://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`__\n   etc.)\n\n.. |PyPI| image:: https://img.shields.io/pypi/v/optlang.svg\n   :target: https://pypi.org/project/optlang/\n   :alt: Current PyPI Version\n.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/optlang.svg\n   :target: https://pypi.org/project/optlang/\n   :alt: Supported Python Versions\n.. |License| image:: https://img.shields.io/pypi/l/optlang.svg\n   :target: https://www.apache.org/licenses/LICENSE-2.0\n   :alt: Apache Software License Version 2.0\n.. |Code of Conduct| image:: https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg\n   :target: .github/CODE_OF_CONDUCT.md\n   :alt: Code of Conduct\n.. |GitHub Actions| image:: https://github.com/opencobra/optlang/workflows/CI-CD/badge.svg\n   :target: https://github.com/opencobra/optlang/workflows/CI-CD\n   :alt: GitHub Actions\n.. |Coverage Status| image:: https://codecov.io/gh/opencobra/optlang/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/opencobra/optlang\n   :alt: Codecov\n.. |Documentation Status| image:: https://readthedocs.org/projects/optlang/badge/?version=latest\n   :target: https://readthedocs.org/projects/optlang/?badge=latest\n   :alt: Documentation Status\n.. |JOSS|  image:: http://joss.theoj.org/papers/cd848071a664d696e214a3950c840e15/status.svg\n   :target: http://joss.theoj.org/papers/cd848071a664d696e214a3950c840e15\n   :alt: Publication\n.. |DOI| image:: https://zenodo.org/badge/5031/biosustain/optlang.svg\n   :target: https://zenodo.org/badge/latestdoi/5031/biosustain/optlang\n   :alt: Zenodo Source Code\n.. |Gitter| image:: https://badges.gitter.im/biosustain/optlang.svg\n   :target: https://gitter.im/biosustain/optlang?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge\n   :alt: Join the chat at https://gitter.im/biosustain/optlang\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Formulate optimization problems using sympy expressions and solve them using interfaces to third-party optimization software (e.g. GLPK).",
    "version": "1.8.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/opencobra/optlang/issues",
        "Documentation": "https://optlang.readthedocs.io",
        "Download": "https://pypi.org/project/optlang/",
        "Homepage": "https://github.com/opencobra/optlang",
        "Source Code": "https://github.com/opencobra/optlang"
    },
    "split_keywords": [
        "optimization",
        "mathematical programming",
        "heuristic optimization",
        "sympy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f58a754a97b1671de71a145034a847993371ec500881e4bface9bc3900737ff7",
                "md5": "5fb66771ae661a279e8f09abde758817",
                "sha256": "18fa6dded1f7650b7a0d14ddf58c66de6847a99a4f27ef7a104a30efcdef1233"
            },
            "downloads": -1,
            "filename": "optlang-1.8.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5fb66771ae661a279e8f09abde758817",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 142021,
            "upload_time": "2023-10-29T19:52:56",
            "upload_time_iso_8601": "2023-10-29T19:52:56.327379Z",
            "url": "https://files.pythonhosted.org/packages/f5/8a/754a97b1671de71a145034a847993371ec500881e4bface9bc3900737ff7/optlang-1.8.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86c4321180666e3d51286977f1d0b4a16ee693785c28041d3ce0f2ea7038ac91",
                "md5": "8674bc4e4fd7f91a202052129605b85d",
                "sha256": "9eb586b69fd88d558a8a0a0eac33c3067c59b5de510fddc36c0aa874eb74bfec"
            },
            "downloads": -1,
            "filename": "optlang-1.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8674bc4e4fd7f91a202052129605b85d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 137524,
            "upload_time": "2023-10-29T19:52:58",
            "upload_time_iso_8601": "2023-10-29T19:52:58.751227Z",
            "url": "https://files.pythonhosted.org/packages/86/c4/321180666e3d51286977f1d0b4a16ee693785c28041d3ce0f2ea7038ac91/optlang-1.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-29 19:52:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "opencobra",
    "github_project": "optlang",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "optlang"
}
        
Elapsed time: 0.13147s