Giter Club home page Giter Club logo

optlang's Introduction

PyPI License Travis Coverage Status Code Climate Documentation Status DOI

optlang

Vision

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

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

And at least one of the following

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

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.

Requirements

  • Models should always be serializable to common problem formulation languages (CPLEX, GAMS, etc.)
  • Models should be picklable
  • Common solver configuration interface (presolver, MILP gap, etc.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.