Printing Cut Types and Count

439 views
Skip to first unread message

Andrew Orso

unread,
Oct 6, 2014, 4:51:59 PM10/6/14
to gur...@googlegroups.com
Hi,

This may be extraordinarily simple though I can't find the appropriate attribute. After a MIP solve, I want to be able to write the type and number of Gurobi cuts (which is displayed in the log file) to a text file. Is there some attribute of the model that lets me do this?

Thanks,

Andrew

Greg Glockner

unread,
Oct 6, 2014, 5:10:12 PM10/6/14
to gur...@googlegroups.com
There is no attribute for this, but you can parse the log (using a message callback to capture the info).

Andrew Orso

unread,
Oct 6, 2014, 5:39:47 PM10/6/14
to gur...@googlegroups.com
Ok, sounds good. Thanks!

Carleton Coffrin

unread,
Mar 29, 2017, 3:54:13 PM3/29/17
to Gurobi Optimization
This post is a bit old, so I would like to double check that as of v7.0, this is still the easiest way to count the number of cuts generated?

Sonja Mars

unread,
Mar 30, 2017, 12:48:08 AM3/30/17
to gur...@googlegroups.com
Hi,

This is still the way to go:

> There is no attribute for this, but you can parse the log (using a message callback to capture the info).

Best regards,
Sonja


----
Dr. Sonja Mars
Gurobi Optimization - Technical Support






Carleton Coffrin

unread,
Mar 31, 2017, 12:35:57 AM3/31/17
to Gurobi Optimization
Hi Sonja,

Thanks for the update.  Could you provide a list of all the string names that can be printed out under the "Cutting planes:" output?  It is not immediately clear to me how the cut names in the parameters documentation translate into the names displayed in this log.

Cheers,
-Carleton

Sonja Mars

unread,
Mar 31, 2017, 12:55:25 AM3/31/17
to gur...@googlegroups.com
Hi Carleton,

We have the following types that are printed in the log:

User
Learned
Gomory
Cover
Implied bound
Projected Implied bound
Clique
MIR
StrongCG
Flow cover
Flow path
GUB cover
Inf proof
Zero half
Mod-K
Network
Lazy constraints

Carleton Coffrin

unread,
Mar 31, 2017, 11:24:36 AM3/31/17
to Gurobi Optimization
Thanks Sonja.

For others who might want to do this, here is some python code that is working for me as of v7.0.

m = Model()
...
m._cut_count = 0
m.optimize(cut_counter)
print(m._cut_count)

def cut_counter(model, where):
    cut_names = {
        'Clique:', 'Cover:', 'Flow cover:', 'Flow path:', 'Gomory:', 
        'GUB cover:', 'Inf proof:', 'Implied bound:', 'Lazy constraints:', 
        'Learned:', 'MIR:', 'Mod-K:', 'Network:', 'Projected Implied bound:', 
        'StrongCG:', 'User:', 'Zero half:'}
    if where == GRB.Callback.MESSAGE:
        # Message callback
        msg = model.cbGet(GRB.Callback.MSG_STRING)
        if any(name in msg for name in cut_names):
            model._cut_count += int(msg.split(':')[1])

Reply all
Reply to author
Forward
0 new messages