Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code implementation for retrieving the number of produced usercuts in a Infocallback #160

Closed
CBongiova opened this issue Oct 2, 2018 · 1 comment · Fixed by #346
Closed
Labels
wontfix Wrapper: MathProgBase Issue is specific to MPB wrapper

Comments

@CBongiova
Copy link

Hello,

I would like to propose an addition to the function "MPBWrapper.jl" to retrieve the number of generated usercuts during the B&B search. This is following the discussion at https://discourse.julialang.org/t/does-anyone-know-how-to-retrieve-the-number-of-generated-cuts-in-the-informational-callback/15370

Note that a Method to retrieve the number of generated cuts with Gurobi already exists in function "grb_callbacks.jl" (https://github.com/JuliaOpt/Gurobi.jl/blob/120d606da08facffb206d73d932dbb0bf7d7001d/src/grb_callbacks.jl#L110)

Then, the only addition to be made is in the wrapper (https://github.com/JuliaOpt/Gurobi.jl/blob/120d606da08facffb206d73d932dbb0bf7d7001d/src/MPBWrapper.jl#L570)

function cbgetmipcutcnt(d::GurobiCallbackData)
    @assert d.state == :Intermediate
    return cbget_mip_cutcnt(d.cbdata, d.where)
end

function cbgetmipcutcnt(d::GurobiCallbackData,output)
    @assert d.state == :Intermediate
    return cbget_mip_cutcnt(d.cbdata, d.where, output)
end

Then one could retrieve the number of generated usercuts in an Infocallback as follows:

#Produce an info callback
bbdata = Vector{Float64}[]
function infocallback(cb)
node = MathProgBase.cbgetexplorednodes(cb)
obj = MathProgBase.cbgetobj(cb)
bestbound = MathProgBase.cbgetbestbound(cb)
gap=(abs(bestbound-obj)/abs(obj))*100
**numcuts = Gurobi.cbgetmipcutcnt(cb)**
push!(bbdata, [time(), node, obj, bestbound, gap, numcuts])
end
addinfocallback(m, infocallback, when = :Intermediate)

I don't know how to make a pull request. Could anyone help me on that?

@odow
Copy link
Member

odow commented Jan 31, 2019

Hi @CBongiova,

Sorry for missing this. If you're still interested, the easiest way to make a pull request is through the web-interface. Here are the steps

  1. Make the changes locally and test that they work.
  2. Navigate to a file like grb_callbacks.jl in the web-interface
  3. Click the pencil in the top-right of the file (the edit button)
  4. Make the changes in the file
  5. Scroll to the bottom of the page, select the "Create a new branch for this commit and start a pull request" option, and then click "Propose file change".
  6. Follow the directions!

Once the PR is open, we can make some comments. You might have to change a few things, but you can do that through the web-interface as well. Good luck!

p.s., if you want to know how to submit a PR using Git, the JuMP contributing guide has a list of tutorials where you can learn.

@odow odow added the Wrapper: MathProgBase Issue is specific to MPB wrapper label Jan 31, 2019
@odow odow added the wontfix label Sep 11, 2019
@odow odow closed this as completed in #346 Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix Wrapper: MathProgBase Issue is specific to MPB wrapper
Development

Successfully merging a pull request may close this issue.

2 participants