Installing or-tools with SCIP and GLPK in a Python 3.7 virtual environment on Linux

I decided to participate in the competition and it was necessary to use packages for him to solve optimization problems. I chose the Google tool or-tools, which is an interface for different solvers (or solved? Solvers?). It contains several optimization tools, but the creators claim support for several external packages, including commercial Gurobi and CPLEX. However, we are not rich people, and we will use free SCIP and GLPK (from a domestic developer, by the way). To my surprise, not a single instruction on how to make all this splendor work in a virtual python environment, I did not find on the open spaces of both our and English-speaking segments of the Internet and I had to tinker a bit. For those in a hurry, read right here, I suggest the rest to get acquainted with the dubious quality of my graphomania, which describes the ups and downs of installing Google software. Yes, I forgot to say right away that everything was installed in Manjaro Linux.


First steps


All three packages exist in the python repository, so we install from via pip.

Each of them has its own interface, and or-tools was chosen just in order to try various packages, without significant rewriting of the program, so the task is for or-tools to pick up these solvers and let them run through itself. And what do you think? Installed via pip or-tools does not see installed solvers through pip, and they do not see it (who would have thought). So, you still need to look at what they write in the documentation .
In the docks they write what needs to be collected from source so that or-tools picks up external packages. We try to collect, and nothing comes out, because the solvers installed through pip are not visible.
Accordingly, the easiest ways to install all packages through pip do not work, because or-tools does not pull solvers, solvers do not install libraries as or-tools wants, everyone pours errors at you, they call you stupid and laugh in every possible way.

Further in the docks they write that it is necessary to collect solvers from source codes, then from-source to collect or-tools itself. No sooner said than done! Installed SCIP, installed GLPK, but the question arose not described in the documentation was how to put or-tools in a virtual environment.

The only make python command on the docks installs the package globally on the system (surprisingly, huh?).

However, I was lucky: in the course of an engineering search using the endless monkey method, I accidentally typed make help and I was given a list of all or-tools build options, among which was the opportunity to build a wheel package. This is the make python_package command, if that (I will repeat it again at the end). So, is it time to build and launch?



Looking for a problem


Nothing works at the or-tools build phase, it swears at the bad GLPK libraries.



Build with SCIP with the parameters from the documentation is successful, but or-tools still refuses to work at the time of import.



I could not find a solution to these problems on my own, so I went to the github for the developers to ask why the installation according to their instructions produces errors somewhere inside their code.


Hmm, thanks for the clarification.

While I was waiting for an answer on the github, I rummaged around the Internet, hoping to find something that would help me. And as it is not surprising, I found it. It was a project team lead blog where he wrote on how to link GLPK with or-tools. And this method finally worked! Now, if you build everything without SCIP, but with GLPK, then you can even work with this. Already progress.

However, the or-tools team lead did not advise using GLPK, saying that the results are not important, and I still want to defeat SCIP and make it work. Neighboring post in the blog came across the idea that Google release package works with specific versions. We look at the list of release changes and see explicit indication of version 6.0.0 there. Despite the fact that version 6.0.2 is indicated in the makefile, we are trying to install an older version and voila!

And now again, a working sequence of actions.

Installation sequence


  1. Download archive SCIP, making sure that there is clearly indicated support for the version that you download (in my case developers.google.com/optimization/support/release_notes#support-for-scip-6.0.0 ) and unpack.
  2. Download GLPK (at the time of post the latest version 4.65) and unzip.
  3. Install SCIP command

    make GMP=false READLINE=false TPI=tny ZIMPL=false scipoptlib install INSTALLDIR=<path>/scipoptsuite-6.0.0
    
  4. Install GLPK with the command:

    ./configure --prefix=<install_path> --with-pic --enable-shared
    make
    make install
    
  5. Download OR-Tools from github

    git clone https://github.com/google/or-tools
  6. Install OR-Tools with the commands:

    make third_party
    make python_package
    

    If the last command does not work, install wheel with the command:

    pip install wheel
  7. To activate the virtual environment go to the folder with the Python package and install it from there.

    If you need to install not in a virtual environment, but globally for the whole system instead:

    make python_package

    execute the command:

    make python
    

All Articles