Giter Site home page Giter Site logo

shifu-engineer / optlang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from opencobra/optlang

0.0 1.0 0.0 8.92 MB

optlang - sympy based mathematical programming language

Home Page: http://optlang.readthedocs.org/

License: Apache License 2.0

Python 95.59% Jupyter Notebook 3.24% Shell 0.05% PowerShell 0.49% Batchfile 0.59% TeX 0.04%

optlang's Introduction

optlang

Sympy based mathematical programming language

PyPI License Travis AppVeyor Coverage Status Documentation Status Join the chat at https://gitter.im/biosustain/optlang JOSS DOI

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 JOSS 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 (DOI 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.)

optlang's People

Contributors

phantomas1234 avatar kristianjensen avatar hredestig avatar the-code-magician avatar cdiener avatar midnighter avatar kvikshaug avatar matthiaskoenig avatar pstjohn avatar long-m-r avatar

Watchers

James Cloos avatar

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.