-
-
Notifications
You must be signed in to change notification settings - Fork 411
Update callbacks.jl #2127
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
Update callbacks.jl #2127
Conversation
Related to #2123 : A small update on example_lazy_constraint() function to make sure the cuts are added only at integral solutions (see https://www.juliaopt.org/JuMP.jl/dev/callbacks/#Lazy-constraints-1)
| elseif y_val + x_val > 3 + 1e-6 | ||
| con = @build_constraint(y - x <= 1) | ||
| MOI.submit(model, MOI.LazyConstraint(cb_data), con) | ||
| if (isinteger.(x_val) == true) && (isinteger.(y_val) == true) # Add the cut only on integral solutions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isinteger(x_val) && isinteger(y_val)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using isinteger isn't correct. If you don't use the same integrality tolerance as the solver, then you might fail to add cuts on a solution that the solver thinks is integral. Maybe we need to provide better support for adding a lazy constraint callback that is called only at integer solutions. We previously had the fractional keyword argument:
https://github.com/JuliaOpt/JuMP.jl/blob/a9de4d0de1b34b85d35c3624bea236afec7e5bec/src/callbacks.jl#L32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a callback_status(cb_data) which returns an enum CBNODE_FRACTIONAL, CBNODE_INTEGER, or CBNODE_UNKNOWN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't thought through all the implications, but that could work also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for something like MOI.CallbackNodeStatus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that isinteger was just a hack for that simple example which was there. I actually wrote my own function to handle the integrality tolerance for my problem. It would be ideal to invoke lazy callback at only integral solutions, which was also my original concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think callback function form function callback_function(cb_data, cb_where) can be a proper choice, cb_where can be used to control where we can add constraints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YP-Ye, currently cb_where is for solver-dependent callbacks. We're looking at introducing a way for solver-independent callbacks (which only take (cb_data)) to identify where they are being called from.
|
The failure on Julia v1.1 seems to be jump-dev/MathOptInterface.jl#980 |
|
Closing as out-dated. The fix for #2123 is to support jump-dev/MathOptInterface.jl#1199. |
Related to #2123 : A small update on example_lazy_constraint() function to make sure the cuts are added only at integral solutions (see https://www.juliaopt.org/JuMP.jl/dev/callbacks/#Lazy-constraints-1)