Gurobi in Python/IDLE

219 views
Skip to first unread message

Tal

unread,
Jan 4, 2011, 4:17:00 AM1/4/11
to Gurobi Optimization
I'm using Python version 2.6.6 / win64 and installed Gurobi as a
library (as explained in http://www.gurobi.com/doc/40/quickstart/node8.html,
at the bottom of the page).

When using the character based command line environment of python all
the examples work fine
However, when trying the graphical environment (IDLE), Gurobi produces
no output.
E.g., when typing m.optimize() the model is solved successfully but no
text is displayed.

How can I change this behavior of IDLE?

Greg Glockner

unread,
Jan 5, 2011, 2:05:33 PM1/5/11
to gur...@googlegroups.com
Unfortunately, there is no simple solution for this. The Gurobi engine is natively compiled and is run as a shared library (DLL on Windows, .so on Linux and Mac). It sends the log information to standard output (stdout), which isn't captured by IDLE.

Perhaps the easiest workaround is to inspect the contents of the log file. Or go back to using the command-line Python rather than IDLE.

lleeoo

unread,
Jan 6, 2011, 5:39:57 AM1/6/11
to Gurobi Optimization
If you must use idle, I unfortunately don't have anything productive
to add. But I would like to suggest that you try ipython. Although it
is based on the command-line, it is IMHO an easier to use interface
than idle.

Cheers,
Leo.

Greg Glockner

unread,
Jan 6, 2011, 6:45:47 PM1/6/11
to gur...@googlegroups.com
After some thought, we realize there is a way to get Gurobi logfile information to the display in IDLE: use a Message callback to print the message string to Python's standard output. Here is a simple callback function to do this:

def messageCB(model, where):
if where == GRB.Callback.MESSAGE:
print model.cbGet(GRB.Callback.MSG_STRING),

Then you can call:

model.optimize(messageCB)

replacing "model" by the name of your model object. You can automate this via a technique called a "monkey patch", replacing the optimize method in the Model class:

def logoptimize(self):
self.__optimize(messageCB)

Model.__optimize = Model.optimize
Model.optimize = logoptimize

Then, you can simply call optimize() on your Model object, and the output will be sent to the IDLE display.

Reply all
Reply to author
Forward
0 new messages