Skip to main content

Formulate optimization problems using sympy expressions and solve them using interfaces to third-party optimization software (e.g. GLPK).

Project description

PyPI License Travis Coverage Status Code Climate Documentation Status DOI

optlang

Vision

optlang provides a common interface to a series of optimization solvers (linear & non-linear) and relies on sympy 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

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.

Dependencies

Example

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

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 interface (very efficient MILP solver)

  • CPLEX interface (very efficient MILP solver)

  • 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.

Requirements

  • Models should always be serializable to common problem formulation languages (CPLEX, GAMS, etc.)

  • Models should be pickable

  • Common solver configuration interface (presolver, MILP gap, etc.)

Project details


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.3.1.tar.gz (45.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

optlang-0.3.1-py3.4.egg (89.6 kB view details)

Uploaded Egg

optlang-0.3.1-py2.7.egg (87.0 kB view details)

Uploaded Egg

File details

Details for the file optlang-0.3.1.tar.gz.

File metadata

  • Download URL: optlang-0.3.1.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for optlang-0.3.1.tar.gz
Algorithm Hash digest
SHA256 f60a2118908f78803ee9a3b280474c078e58dd31f8e9770ef9e5ec74735c60aa
MD5 801e977c429aa384170f33612f89ebb1
BLAKE2b-256 878317942fe508dac22ef49e6dacf61e5c95cea2a05d515157b8a6153ec51c47

See more details on using hashes here.

File details

Details for the file optlang-0.3.1-py3.4.egg.

File metadata

  • Download URL: optlang-0.3.1-py3.4.egg
  • Upload date:
  • Size: 89.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for optlang-0.3.1-py3.4.egg
Algorithm Hash digest
SHA256 18a213f895d8da615af1b6db0ec1584e5ea93f60a2287a5964b11567d11a11e6
MD5 21dfd5f19d5a5c667c153bf17cff6b4a
BLAKE2b-256 5d3c13601c70d5674d3086faf8fac8c6d3cd47c720bd05cd32258c1b234f1171

See more details on using hashes here.

File details

Details for the file optlang-0.3.1-py2.7.egg.

File metadata

  • Download URL: optlang-0.3.1-py2.7.egg
  • Upload date:
  • Size: 87.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for optlang-0.3.1-py2.7.egg
Algorithm Hash digest
SHA256 00d8ac8d16a5ec1235ac38c33bd7d19b36182f5d2b6bc3b0147b3f69aab44fc6
MD5 9c61ff96b242173390d14a81e3c5c4c9
BLAKE2b-256 e6584343f89679f4714bd1ae801bc42eb517191e23cafb990f98f14af1bdc60a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page