skip to navigation
skip to content

optlang 0.2.14

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



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.


Install using pip

pip install optlang

Local installations like

python install

might fail installing the dependencies (unresolved issue with easy_install). Running

pip install -r requirements.txt

beforehand should fix this issue.


The documentation for optlang is provided at


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


  • 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.)
File Type Py Version Uploaded on Size
optlang-0.2.14-py2.7.egg (md5) Python Egg 2.7 2015-09-28 76KB
optlang-0.2.14-py3.4.egg (md5) Python Egg 3.4 2015-09-28 79KB
optlang-0.2.14.tar.gz (md5) Source 2015-09-28 39KB
  • Downloads (All Versions):
  • 23 downloads in the last day
  • 376 downloads in the last week
  • 1603 downloads in the last month