How to use Solver Gurobi while using python as the coding language

2,178 views
Skip to first unread message

arjun...@stellium.com

unread,
Jun 21, 2017, 6:00:12 AM6/21/17
to or-tools-discuss
Hi Team,

I want to use Gurobi solver to solve a MILP and MLQP problem with python as the coding language. I just wanted to understand if it is possible for me to do so. I want to know how would I call the Gurobi solver in python? I do not see Gurobi in any of the folders of OR-tools for python, how does the code interact with gurobi?

Do I need to buy a license for Gurobi?

Also does anybody have any information on the number of variables I can use in Gurobi?

PS: I am a novice to optimization tools.

Jon Orwant

unread,
Jun 21, 2017, 9:10:35 AM6/21/17
to or-tools-discuss
Hi Arjun,

In addition to providing Google's solvers, OR-tools also provides wrappers around other solvers, including Gurobi for MILP (but not MLQP) problems. 

Gurobi is a commercial solver and you do need a license to use it. IIRC the license is free for educational use.

After you install Gurobi on your machine, you can use OR-tools to invoke it from Python as follows:

solver
= pywraplp.Solver('SolveIntegerProblem',
                           pywraplp
.Solver.GUROBI_MIXED_INTEGER_PROGRAMMING);

Jon

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

arjun...@stellium.com

unread,
Jul 4, 2017, 2:29:39 AM7/4/17
to or-tools-discuss
Thank you for the information Jon. :-)
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

Roman Istomin

unread,
May 24, 2019, 9:29:35 AM5/24/19
to or-tools-discuss
a follow-up question:
would C++ solver for the same purpose be constructed with the same solver name ("GUROBI_MIXED_INTEGER_PROGRAMMING")
and can Gurobi be used from under ORtools for other problems?
Especially this one:
operations_research::SimpleMinCostFlow()
if yes, what should I specify as solver for those problems?


On Wednesday, June 21, 2017 at 9:10:35 AM UTC-4, orwant wrote:
Hi Arjun,

In addition to providing Google's solvers, OR-tools also provides wrappers around other solvers, including Gurobi for MILP (but not MLQP) problems. 

Gurobi is a commercial solver and you do need a license to use it. IIRC the license is free for educational use.

After you install Gurobi on your machine, you can use OR-tools to invoke it from Python as follows:

solver
= pywraplp.Solver('SolveIntegerProblem',
                           pywraplp
.Solver.GUROBI_MIXED_INTEGER_PROGRAMMING);

Jon
On Wed, Jun 21, 2017 at 6:00 AM, <arju...@stellium.com> wrote:
Hi Team,

I want to use Gurobi solver to solve a MILP and MLQP problem with python as the coding language. I just wanted to understand if it is possible for me to do so. I want to know how would I call the Gurobi solver in python? I do not see Gurobi in any of the folders of OR-tools for python, how does the code interact with gurobi?

Do I need to buy a license for Gurobi?

Also does anybody have any information on the number of variables I can use in Gurobi?

PS: I am a novice to optimization tools.

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools...@googlegroups.com.

Laurent Perron

unread,
May 24, 2019, 9:33:07 AM5/24/19
to or-tools-discuss
MinCostFlow is a polynomial algorithm. It does not use any MIP solver.

To use Gurobi in any language, you need to recompile from source or-tools with Gurobi installed 

See https://developers.google.com/optimization/install/python/source_linux (mac and windows are also available).
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/a9306646-511d-421b-89f0-4e9bb5ba9ec6%40googlegroups.com.

Roman Istomin

unread,
May 24, 2019, 9:37:29 AM5/24/19
to or-tools...@googlegroups.com
Thanks,
So, do I understand correctly that Gurobi could only be used for Integer Programming problems?

Also, I did make third party with Gurobi installed, but to use Gurobi solver, do I need to explicitly tell ORtools to use it or does it use Gurobi by default when compiled with a thirdparty option?


For more options, visit https://groups.google.com/d/optout.


--
Best, Roman Istomin

Laurent Perron

unread,
May 24, 2019, 9:42:12 AM5/24/19
to or-tools-discuss
Yes, and yes.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Henry

unread,
Jun 2, 2020, 6:25:12 PM6/2/20
to or-tools-discuss
Follow up question: I have a working version of gurobi and a license. I downloaded the or-tools source and did the following:

make third_party

Add the following to Makefile.local
UNIX_GUROBI_DIR = /Library/gurobi902/
GUROBI_LIB_VERSION = 90

Make python

However, when I try to create a solver using GUROBI_MIXED_INTEGER_PROGRAMMING, it says that this attribute doesn’t exist.

Best,

Henry




Mizux Dev

unread,
Jun 3, 2020, 3:59:30 AM6/3/20
to or-tools-discuss
did you run `make clean_python` before ?
otherwise the enum should be generated in ortools/gen/ortools/linear_solver/pywraplp.py ~line100
can try to grep it:
```sh
grep -rn "GUROBI_" ortools/gen/ortools/linear_solver/pywraplp.py
```

Henry Robbins

unread,
Jun 4, 2020, 1:09:34 PM6/4/20
to or-tools...@googlegroups.com
At what point should I run make clean_python? Another person in my team has been able to successfully install on Windows. He said he had to use make install_python before everything worked. I have tried doing both and still get the error:

AttributeError: type object 'Solver' has no attribute ‘GUROBI_MIXED_INTEGER_PROGRAMMING'

What is the exact order I should preform these commands? Do you have any other ideas why this might not be working? By the way, I am using the master branch not the latest stable release.

Thanks!

Henry

-- 
You received this message because you are subscribed to a topic in the Google Groups "or-tools-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/or-tools-discuss/-3JoricwMQQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/5fc3efda-1188-4182-96da-ae4daecdcc9b%40googlegroups.com.

Laurent Perron

unread,
Jun 4, 2020, 1:16:45 PM6/4/20
to or-tools-discuss
make third_party
edit Makefile.local
make clean
make python
make install_python

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/5D67BCE2-6841-4F0A-A778-912765ECFF5F%40cornell.edu.

Henry Robbins

unread,
Jun 4, 2020, 1:51:33 PM6/4/20
to or-tools...@googlegroups.com
Just tried this and received the same error. Here is some additional information that may be helpful in trouble shooting (attached). Thanks for the help! I really appreciate it!

Best,

Henry

Makefile.local
Screen Shot 2020-06-04 at 1.48.38 PM.png

Xiang Chen

unread,
Jun 4, 2020, 5:12:38 PM6/4/20
to or-tools...@googlegroups.com
How are you running your program?

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

Henry Robbins

unread,
Jun 4, 2020, 5:14:44 PM6/4/20
to or-tools...@googlegroups.com
I have tried running both from command line and through my Jupyter Notebook

Henry Robbins

unread,
Jun 5, 2020, 12:26:09 PM6/5/20
to or-tools...@googlegroups.com
If this helps, I tried running make test and this message was at the end:

makefiles/Makefile.dotnet.mk:36: Cannot find 'dotnet' command which is needed for build. Please make sure it is installed and in system path.
DOTNET_BIN =
Or-tools have been built and tested for C++ , Python3.6 , Java

Best,

Henry

On Jun 4, 2020, at 5:12 PM, Xiang Chen <xiang10...@gmail.com> wrote:

Laurent Perron

unread,
Jun 5, 2020, 1:58:08 PM6/5/20
to or-tools-discuss
If you are not compiling for dotnet, you can ignore this warning.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Henry Robbins

unread,
Jun 5, 2020, 2:22:06 PM6/5/20
to or-tools...@googlegroups.com
Ok. Is there other information I can send to help troubleshoot? I followed the steps you outlined but am still receiving the same error.
Thanks again for the help!

Best,

Henry
Reply all
Reply to author
Forward
0 new messages