Formulate optimization problems using sympy expressions and solve them using interfaces to third-party optimization software (e.g. GLPK).
Project description
Sympy based mathematical programming language
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 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!
Installation
Install using pip
pip install optlang
Then you could install swiglpk
pip install swiglpk
to solve your optimization problems using GLPK (see below for further supported solvers).
Example
Formulating and solving the problem is straightforward (example taken from GLPK documentation):
from optlang.glpk_interface 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
Documentation
Documentation for optlang is provided at readthedocs.org.
Development
The following dependencies are needed.
And at least one of the following
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.
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.)
The optlang trello board also provides a good overview of the project’s roadmap.
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
Built Distributions
Hashes for optlang-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba99a4e2b143df6273d19e4309421e5a2a52d90e18461769084c28aea231e83d |
|
MD5 | e17752f5ab1d5fabdac82bd85afb0ffd |
|
BLAKE2b-256 | f780df3db8655ab2993a9a65f262fd1de1f102ef418239f1f6978c72972d9cc3 |