Skip to content

Commit 52a632e

Browse files
authoredJan 2, 2017
Joss review (#55)
* chore: make example in README solver agnostic And add a note on how to use a specific solver * docs: add comments to README code * Update requirements.txt * docs: update README to reflect swiglpk as a dep. swiglpk is a hard dependency now, so that 'pip install optlang' works out of the box. * docs: update install instructions Swiglpk is now a hard dependency so the installation instructions are updated accordingly. * docs: update dependency versions in readme * docs: update contributing guidelines And add CONTRIBUTIONS.md file * docs: update readme, paper and documentation Add target audience to paper and docs/index Add solver problem capabilities to readme Move installation issue from readme to docs/installation * test: remove libglp from travis.yml * docs: highlight 'modeling language' * docs: change paper title * Some minor writing fixes (#57) I made some minor writing fixes, to be adopted before acceptance in JOSS (openjournals/joss-reviews#139)
1 parent d607d21 commit 52a632e

File tree

7 files changed

+89
-54
lines changed

7 files changed

+89
-54
lines changed
 

‎CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Contribute
2+
==========
3+
4+
Contributions to optlang are very welcome. Fork optlang at `github
5+
<http://github.com/biosustain/optlang>`_, implement your feature and send us
6+
a pull request. Also, please use the GitHub `issue tracker <https://github.com/biosustain/optlang/issues>`_
7+
to let us know about bugs or feature requests, or if you have problems or questions regarding optlang.

‎README.rst

+33-37
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ problems, i.e. maximizing or minimizing an objective function over a set
1010
of variables subject to a number of constraints. Optlang provides a
1111
common interface to a series of optimization tools, so different solver
1212
backends can be changed in a transparent way.
13-
Optlang takes advantage of the symbolic math library
13+
Optlang's object-oriented API takes advantage of the symbolic math library
1414
`sympy <http://sympy.org/en/index.html>`__ to allow objective functions
1515
and constraints to be easily formulated from symbolic expressions of
1616
variables (see examples).
1717

1818
Show us some love by staring this repo if you find optlang useful!
1919

20+
Also, please use the GitHub `issue tracker <https://github.com/biosustain/optlang/issues>`_
21+
to let us know about bugs or feature requests, or if you have problems or questions regarding optlang.
22+
2023
Installation
2124
~~~~~~~~~~~~
2225

@@ -26,35 +29,51 @@ Install using pip
2629

2730
pip install optlang
2831

29-
Then you could install `swiglpk <https://github.com/biosustain/swiglpk>`_
32+
This will also install `swiglpk <https://github.com/biosustain/swiglpk>`_, an interface to the open source (mixed integer) LP solver `GLPK <https://www.gnu.org/software/glpk/>`_.
33+
Quadratic programming (and MIQP) is supported through additional optional solvers (see below).
3034

31-
::
35+
Dependencies
36+
~~~~~~~~~~~~
37+
38+
The following dependencies are needed.
39+
40+
- `sympy >= 1.0.0 <http://sympy.org/en/index.html>`__
41+
- `six >= 1.9.0 <https://pypi.python.org/pypi/six>`__
42+
- `swiglpk >= 1.3.0 <https://pypi.python.org/pypi/swiglpk>`__
43+
44+
The following are optional dependencies that allow other solvers to be used.
45+
46+
- `cplex <https://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`__ (LP, MILP, QP, MIQP)
47+
- `gurobipy <http://www.gurobi.com>`__ (LP, MILP (QP and MIQP support will be added in the future))
48+
- `scipy <http://www.scipy.org>`__ (LP)
3249

33-
pip install swiglpk
3450

35-
to solve your optimization problems using `GLPK <https://www.gnu.org/software/glpk/>`_ (see below for further supported solvers).
3651

3752
Example
3853
~~~~~~~
3954

4055
Formulating and solving the problem is straightforward (example taken
4156
from `GLPK documentation <http://www.gnu.org/software/glpk>`__):
4257

43-
::
58+
.. code-block:: python
4459
4560
from __future__ import print_function
46-
from optlang.glpk_interface import Model, Variable, Constraint, Objective
61+
from optlang import Model, Variable, Constraint, Objective
4762
63+
# All the (symbolic) variables are declared, with a name and optionally a lower and/or upper bound.
4864
x1 = Variable('x1', lb=0)
4965
x2 = Variable('x2', lb=0)
5066
x3 = Variable('x3', lb=0)
5167
68+
# A constraint is constructed from an expression of variables and a lower and/or upper bound (lb and ub).
5269
c1 = Constraint(x1 + x2 + x3, ub=100)
5370
c2 = Constraint(10 * x1 + 4 * x2 + 5 * x3, ub=600)
5471
c3 = Constraint(2 * x1 + 2 * x2 + 6 * x3, ub=300)
5572
73+
# An objective can be formulated
5674
obj = Objective(10 * x1 + 6 * x2 + 4 * x3, direction='max')
5775
76+
# Variables, constraints and objective are combined in a Model object, which can subsequently be optimized.
5877
model = Model(name='Simple model')
5978
model.objective = obj
6079
model.add([c1, c2, c3])
@@ -63,6 +82,7 @@ from `GLPK documentation <http://www.gnu.org/software/glpk>`__):
6382
6483
print("status:", model.status)
6584
print("objective value:", model.objective.value)
85+
print("----------")
6686
for var_name, var in model.variables.iteritems():
6787
print(var_name, "=", var.primal)
6888
@@ -72,46 +92,22 @@ The example will produce the following output:
7292

7393
status: optimal
7494
objective value: 733.333333333
95+
----------
7596
x2 = 66.6666666667
7697
x3 = 0.0
7798
x1 = 33.3333333333
7899

100+
Using a particular solver
101+
-------------------------
102+
If you have more than one solver installed, it's also possible to specify which one to use, by importing directly from the
103+
respective solver interface, e.g. :code:`from optlang.glpk_interface import Model, Variable, Constraint, Objective`
104+
79105
Documentation
80106
~~~~~~~~~~~~~
81107

82108
Documentation for optlang is provided at
83109
`readthedocs.org <http://optlang.readthedocs.org/en/latest/>`__.
84110

85-
Development
86-
~~~~~~~~~~~
87-
88-
The following dependencies are needed.
89-
90-
- `sympy >= 0.7.5 <http://sympy.org/en/index.html>`__
91-
- `six >= 1.9.0 <https://pypi.python.org/pypi/six>`__
92-
93-
And at least one of the following
94-
95-
- `swiglpk >= 0.1.0 <https://pypi.python.org/pypi/swiglpk>`__
96-
- `cplex <https://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`__
97-
- `gurobipy <http://www.gurobi.com>`__
98-
- `scipy <http://www.scipy.org>`__
99-
100-
Local installations like
101-
102-
::
103-
104-
python setup.py install
105-
106-
107-
might fail installing the dependencies (unresolved issue with
108-
``easy_install``). Running
109-
110-
::
111-
112-
pip install -r requirements.txt
113-
114-
beforehand should fix this issue.
115111

116112
Future outlook
117113
~~~~~~~~~~~~~~

‎docs/source/developers.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contribute
44
Contributions to optlang are very welcome. Fork optlang at `github
55
<http://github.com/biosustain/optlang>`_, implement your feature and send us
66
a pull request. Also, please use the GitHub `issue tracker <https://github.com/biosustain/optlang/issues>`_
7-
to let us know about bugs or feature requests.
7+
to let us know about bugs or feature requests, or if you have problems or questions regarding optlang.
88

99
Add solver interface
1010
--------------------

‎docs/source/index.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
optlang
22
*******
33

4-
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.
4+
Optlang is a Python package implementing a modeling language for solving mathematical optimization problems, i.e. maximizing or minimizing an objective function over a set of variables subject to a number of constraints.
55
Optlang provides a common interface to a series of optimization tools, so different solver backends can be changed in a transparent way.
66

77
In constrast to e.g. the commonly used General Algebraic Modeling System (GAMS), optlang has a simple and intuitive interface using native Python algebra syntax, and is free and open-source.
88

99
Optlang takes advantage of the symbolic math library `SymPy <http://sympy.org>`_ to allow objective functions and constraints to be easily formulated from symbolic expressions of variables (see examples).
10+
Scientists can thus use optlang to formulate their optimization problems using mathematical expressions derived from domain knowledge.
1011

1112
Currently supported solvers are:
1213

@@ -79,6 +80,12 @@ You should see the following output::
7980
x3 = 0.0
8081
x1 = 33.3333333333
8182

83+
84+
Using a particular solver
85+
----------
86+
If you have more than one solver installed, it's also possible to specify which one to use, by importing directly from the
87+
respective solver interface, e.g. :code:`from optlang.glpk_interface import Model, Variable, Constraint, Objective`
88+
8289
Quadratic programming
8390
----------
8491
A QP problem can be generated in the same way by creating an objective with a quadratic expression. In the above example

‎docs/source/installation.rst

+28-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Install optlang using pip::
55

66
pip install optlang
77

8-
Or, or download the source distribution and run::
8+
Or download the source distribution and run::
99

1010
python setup.py install
1111

@@ -16,15 +16,17 @@ You can run optlang's test suite like this (you need to install nose first thoug
1616
1717
Solvers
1818
----------
19-
In addition to optlang itself, it is necessary to install at least one solver. Optlang interfaces with the solvers
20-
through importable python modules. If the python module corresponding to the solver can be imported without errors
21-
the solver interface should be available as an optlang submodule (e.g. :code:`optlang.glpk_interface`).
19+
To solve optimization problems, at least one supported solver must be installed.
20+
Installing optlang using :code:`pip` will also automatically install GLPK. To use other solvers (e.g. commercial solvers) it is necessary
21+
to install them manually. Optlang interfaces with all solvers through importable python modules. If the python module corresponding
22+
to the solver can be imported without errors the solver interface should be available as an optlang submodule (e.g.
23+
:code:`optlang.glpk_interface`).
2224

2325
The required python modules for the currently supported solvers are:
2426

25-
- GLPK: :code:`swiglpk`
27+
- GLPK: :code:`swiglpk` (automatically installed by :code:`pip install optlang`)
2628

27-
- GLPK is an open source Linear Programming library. Swiglpk can be installed from binary wheels or from source. Installing from source requires swig and GLPK
29+
- GLPK is an open source Linear Programming library. Swiglpk can be installed from binary wheels or from source. Installing from source requires swig and GLPK.
2830

2931
- Cplex: :code:`cplex`
3032

@@ -39,3 +41,23 @@ The required python modules for the currently supported solvers are:
3941
- The SciPy linprog function is a very basic implementation of the simplex algorithm for solving linear optimization problems. Linprog is included in all recent versions of SciPy.
4042

4143
After importing optlang you can check :code:`optlang.available_solvers` to verify that a solver is recognized.
44+
45+
46+
Issues
47+
------
48+
49+
Local installations like
50+
51+
::
52+
53+
python setup.py install
54+
55+
56+
might fail installing the dependencies (unresolved issue with
57+
``easy_install``). Running
58+
59+
::
60+
61+
pip install -r requirements.txt
62+
63+
beforehand should fix this issue.

‎paper/paper.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Optlang: A Python interface to common mathematical optimization solvers'
2+
title: 'Optlang: An algebraic modeling language for mathematical optimization'
33
tags:
44
- Mathematical optimization
55
- Linear programming
@@ -23,16 +23,18 @@ bibliography: paper.bib
2323

2424
# Summary
2525

26-
Optlang is a Python package for solving mathematical optimization problems, i.e. maximizing or minimizing an
27-
objective function over a set of variables subject to a number of constraints. It provides a common native Python
28-
interface to a series of optimization tools, so different solver backends can used and changed in a transparent way.
26+
Optlang is a Python package implementing a modeling language for solving mathematical optimization problems, i.e.,
27+
maximizing or minimizing an objective function over a set of variables subject to a number of constraints. It provides
28+
a common native Python interface to a series of optimization tools, so different solver backends can be used and
29+
changed in a transparent way.
2930

30-
Optlang takes advantage of the symbolic math library SymPy [@Sympy] to allow objective functions and constraints
31-
to be easily formulated algebraically from symbolic expressions of variables. With optlang the user can thus
32-
focus on the science of formulating a problem without worrying about how to solve it.
31+
Optlang's object-oriented API takes advantage of the symbolic math library SymPy [@Sympy] to allow objective functions
32+
and constraints to be easily formulated algebraically from symbolic expressions of variables. Optlang targets
33+
scientists who can thus focus on formulating optimization problems based on mathematical equations derived from domain
34+
knowledge.
3335

34-
Solver interfaces can be added by subclassing the 4 main classes of the optlang API (Variable, Constraint, Objective
36+
Solver interfaces can be added by subclassing the four main classes of the optlang API (Variable, Constraint, Objective,
3537
and Model) and implementing the relevant API functions.
3638

3739

38-
# References
40+
# References

‎requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
sympy>=1.0.0
22
six>=1.9.0
3+
swiglpk>=1.3.0

0 commit comments

Comments
 (0)
Please sign in to comment.