• Stars
    star
    215
  • Rank 183,925 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

optlang - sympy based mathematical programming language

optlang

Sympy based mathematical programming language

Current PyPI Version Supported Python Versions Apache Software License Version 2.0 Code of Conduct GitHub Actions Codecov Documentation Status Join the chat at https://gitter.im/biosustain/optlang Publication Zenodo Source Code

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 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 to let us know about bugs or feature requests, or our gitter channel if you have problems or questions regarding optlang.

Installation

Install using pip

pip install optlang

This will also install swiglpk, an interface to the open source (mixed integer) LP solver GLPK. Quadratic programming (and MIQP) is supported through additional optional solvers (see below).

Dependencies

The following dependencies are needed.

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

Example

Formulating and solving the problem is straightforward (example taken from GLPK documentation):

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. from optlang.glpk_interface import Model, Variable, Constraint, Objective

Documentation

Documentation for optlang is provided at readthedocs.org.

Citation

Please cite Publication 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 (Zenodo Source Code 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 interface (provides academic licenses)
  • GAMS output (support non-linear problem formulation)
  • DEAP (support for heuristic optimization)
  • Interface to 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 etc.)

More Repositories

1

cobrapy

COBRApy is a package for constraint-based modeling of metabolic networks.
Python
413
star
2

cobratoolbox

The COnstraint-Based Reconstruction and Analysis Toolbox. Documentation:
MATLAB
247
star
3

memote

memote – the genome-scale metabolic model test suite
HTML
120
star
4

COBRA.jl

High-level, high-performance, constraint-based reconstruction and analysis in Julia
Julia
61
star
5

MATLAB.devTools

MATLAB Development Tools
MATLAB
27
star
6

Medusa

Analysis of ensembles of metabolic network reconstructions
Python
20
star
7

COBRA.tutorials

Repository of tutorials for The COBRA Toolbox
MATLAB
18
star
8

m_model_collection

A collection of M models downloaded from published studies
Jupyter Notebook
14
star
9

driven

Data-Driven Constraint-based analysis
Python
13
star
10

MASS-Toolbox

Mass Action Stoichiometric Simulation (MASS) Toolbox
Mathematica
11
star
11

COBRA.papers

Repository for scripts related to reproducing the results of an individual publication
MATLAB
8
star
12

cobra-component-models

Provide SQLAlchemy ORM and pydantic data models for SQL storage and serialization of COBRA components such as reactions, compounds, and compartments.
Python
3
star
13

memote-docker

Easily use the memote command line interface from a docker container.
Shell
3
star
14

cookiecutter-memote

A cookiecuttter template for memote model repositories
Python
2
star
15

cookiecutter-python-package

Extensive cookiecutter template for openCOBRA Python packages.
Python
2
star
16

schema

xml/rdf schemas for annotating cobra models
2
star
17

cobrapy_shim

Shim for the COBRA toolbox to call cobrapy functions
Python
1
star
18

cobrapy-bigg-client

Python
1
star
19

cobrapy-website

HTML
1
star
20

ctf

Chemical table files for constraint-based modelling
1
star
21

COBRA.binary

Linux, Windows and Mac binaries maintained by the constraint-based reconstruction and analysis community
MATLAB
1
star