Skip to content

Commit

Permalink
Merge pull request #230 from opencobra/devel
Browse files Browse the repository at this point in the history
1.5.0
  • Loading branch information
carrascomj authored Mar 17, 2021
2 parents e7728cd + 4c32109 commit 03e2c19
Show file tree
Hide file tree
Showing 25 changed files with 3,151 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox -- --cover-xml
env:
CI: true
- name: Report coverage
shell: bash
run: bash <(curl -s https://codecov.io/bash)
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

Next Release
------------

1.5.0
------------
* removed support for Python 3.5
* added support for Python 3.9
* enabled code coverage in tox
* support symengine 0.7.0
* add [OSQP](https://github.com/oxfordcontrol/osqp) as additional solver
* add [cbc](https://github.com/coin-or/python-mip) as additional solver

1.4.7
-----
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The following are optional dependencies that allow other solvers to be used.
- `cplex <https://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`__ (LP, MILP, QP, MIQP)
- `gurobipy <http://www.gurobi.com>`__ (LP, MILP, QP, MIQP)
- `scipy <http://www.scipy.org>`__ (LP)
- `osqp <https://osqp.org/>`__ (LP, QP)



Expand Down
14 changes: 8 additions & 6 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Currently supported solvers are:
* `CPLEX <http://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/>`_ (LP/MILP/QP)
* `Gurobi <http://www.gurobi.com/>`_ (LP/MILP/QP)
* `inspyred <https://pypi.python.org/pypi/inspyred>`_ (heuristic optimization; experimental)
* `OSQP <https://osqp.org/>`_ (LP/QP) OSQP is an efficient open source solver for Quadratic Programs. Alternatively, optlang can use cuOSQP which provides an experimental cuda-enabled implementation.
* `Cbc <https://github.com/coin-or/Cbc>`_ (LP/MILP)

Support for the following solvers is in the works:

Expand Down Expand Up @@ -46,20 +48,20 @@ Formulating and solving the problem is straightforward
.. code-block:: python
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
Expand Down Expand Up @@ -169,7 +171,7 @@ The GAMS example (http://www.gams.com/docs/example.htm) can be formulated and so
print("")
for var in model.variables:
print(var.name, ":", var.primal)
Outputting the following::

Minimize
Expand All @@ -190,7 +192,7 @@ Outputting the following::
San_Diego_to_Chicago : 0
San_Diego_to_Topeka : 275
San_Diego_to_New_York : 275

Here we forced all variables to have integer values. To allow non-integer values, leave out :code:`type="integer"` in the Variable constructor (defaults to :code:`'continuous'`).

Users's guide
Expand Down
15 changes: 12 additions & 3 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Or download the source distribution and run::
You can run optlang's test suite like this (you need to install nose first though)::

python setup.py test


Solvers
----------
To solve optimization problems, at least one supported solver must be installed.
Expand All @@ -24,7 +24,7 @@ to the solver can be imported without errors the solver interface should be avai

The required python modules for the currently supported solvers are:

- GLPK: :code:`swiglpk` (automatically installed by :code:`pip install optlang`)
- GLPK: :code:`swiglpk` (automatically installed by :code:`pip install optlang`)

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

Expand All @@ -40,6 +40,15 @@ The required python modules for the currently supported solvers are:

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

- OSQP: :code:`osqp | cuosqp`

- OSQP is an efficient open source solver for Quadratic Programs. It is self-contained and can be installed via pip. Alternatively, cuOSQP provides an experimental cuda-enabled implementation.

- Cbc: :code:`mip`

- Cbc (Coin-or branch and cut) is an open-source mixed integer linear programming solver written in C++. It can be installed via mip (python3 only).


After importing optlang you can check :code:`optlang.available_solvers` to verify that a solver is recognized.


Expand Down
16 changes: 15 additions & 1 deletion src/optlang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@
except Exception:
log.error('GUROBI is available but could not load with error:\n ' + str(traceback.format_exc()).strip().replace('\n','\n '))

if available_solvers['COINOR_CBC']:
try:
from optlang import coinor_cbc_interface
except Exception:
log.error('COINOR_CBC is available but could not load with error:\n ' + str(traceback.format_exc()).strip().replace('\n','\n '))

if available_solvers['OSQP']:
try:
from optlang import osqp_interface
except Exception:
log.error('OSQP is available but could not load with error:\n ' +
str(traceback.format_exc()).strip().replace('\n','\n '))

if available_solvers['SCIPY']:
try:
from optlang import scipy_interface
Expand All @@ -58,7 +71,8 @@


# Go through and find the best solver that loaded. Load that one as the default
for engine_str in ['cplex_interface', 'gurobi_interface', 'glpk_interface', 'scipy_interface']:
for engine_str in ['cplex_interface', 'gurobi_interface', 'glpk_interface',
'scipy_interface', 'coinor_cbc_interface']:
# Must check globals since not all interface variables will be defined
if engine_str in globals():
engine = globals()[engine_str]
Expand Down
Loading

0 comments on commit 03e2c19

Please sign in to comment.