opencobra / optlang

optlang - sympy based mathematical programming language
http://optlang.readthedocs.org/
Apache License 2.0
253 stars 52 forks source link

[Planned feature] COIN-OR Cbc interface #212

Closed braceal closed 3 years ago

braceal commented 4 years ago

I have just started working on implementing an interface to the COIN-OR Cbc solver. My intent is to introduce an open-source MILP solver to optlang for use in the wider COBRApy community. This is mainly intended for those who can't use the academic/commercial license solvers.

Cbc already has a python interface so all that's needed is to wrap it in optlang. https://github.com/coin-or/python-mip

Please let me know if anyone would like to contribute to this effort. If anyone has familiarity with the optlang code base it would be very helpful to have a discussion about my approach.

I've already got a start in implementing the Variable, Objective and Model classes.

My fork and branch: https://github.com/braceal/optlang/tree/feature-coin-or-cbc

braceal commented 4 years ago

I'm also planning to add an optlang interface to the SCIP solver. I'll post this as a separate issue when I start. I just wanted to give a heads up in case anyone is thinking of doing this and wants to collaborate. https://scip.zib.de/

cdiener commented 4 years ago

I recently added a new interface to optlang (for OSQP) and could help you out circumventing some of the caveats after you started. Regarding SCIP: the ZIB is notorious for having very weird licences that are usually incompatible with any open source license due to the tracking clause. You are usually not allowed to distribute compiled code from those solvers and can't wrap it into a python package. See https://github.com/SBRG/soplex_cython/pull/4.

braceal commented 4 years ago

I see, I don't have much experience with licensing but I was aiming to wrap this python interface which has an MIT license. We can leave this conversation for the future to keep this issue related to COIN-OR. https://github.com/SCIP-Interfaces/PySCIPOpt

It's great to hear you have QSQP working, I was thinking of looking into that as well. I will take a look at your implementation for guidance.

I'm currently aiming to get some basic examples running for CBC. I am hoping to be there by mid next week. The main pitfalls I see stem from not fully understanding the interface classes for Model, Constraint, Variable and Objective and how they are communicating. I'd like to do a minimal implementation to start and then add features as I go.

KristianJensen commented 4 years ago

Great idea with an open source MILP solver! I'll be happy to help if you encounter any problems or have any questions.

For a minimal implementation of a solver interface you can have a look at the Model, Variable, Constraint and Objective classes in scipy_interface.py. Most of the interactions between the different classes are handled by interface.py, so the solver-specific implementation mainly needs to handle the communication with the underlying solver bindings.

braceal commented 4 years ago

Thank you for offering your help.

Currently I have Model, Variable, Constraint and Objective implemented and correctly solving a few example problems posted here https://python-mip.readthedocs.io/en/latest/examples.html

I am now running and debugging the optlang test suite. Once I have everything passing I will post a pull request for code review and discussion.

braceal commented 4 years ago

I just added the PR for coinor_cbc. Shall we move this discussion to #213 ?