-
Notifications
You must be signed in to change notification settings - Fork 81
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
Gurobi's "Warning for adding constraints: zero or small (< 1e-13) coefficients, ignored" is printed upon JuMP.@constraint() rather than during JuMP.optimize!() #598
Comments
It looks like a combination of map_coefficients_inplace! and drop_zeros! would do the trick for cleaning up your linear expressions before adding them as lazy constraints. I would be cautious here though. Gurobi is warning you about this for a reason. Sure, you can clean out the 1e-13 coefficients to avoid the warning, but then it seems likely you are also introducing many 1e-12 or similar-sized coefficients which may then cause numerical trouble. You really need to understand the source of these small coefficients and whether they are actually important to the constraint you are adding. |
The docs for map_coefficients and drop_zeros imply they should work on any expression, so I don't see a reason this wouldn't work when building an expression within a callback. Try inspecting the expressions in your callback before adding them. The warnings are printed by Gurobi. Normally when building a model they would be displayed only once, even if multiple constraints had this problem. We'll take a look and see if we can improve this behaviour for lazy constraints. I'm not aware of a way to filter specific output lines within Julia's REPL. I would try writing to a log file instead, then the lines can be easily filtered using grep or a similar tool. |
function grb_set_silent(m)
return Gurobi.GRBsetintparam(Gurobi.GRBgetenv(JuMP.backend(m)), Gurobi.GRB_INT_PAR_OUTPUTFLAG, 0)
end |
@simonbowly Thanks, I've known the reason. The explanation is updated, in my first comment. |
@WalterMadelim for the future, please do not delete/overwrite your original questions when editing your initial post and comments. It is now impossible for anyone to follow this discussion. Better practice is to append additional comments if you want to give more context, rather than rewriting. I will assume from your later comments that the warnings were in fact not coming from the addition of the lazy constraints, but occurred once for each of the models you were building to derive the lazy constraints. In which case, this is not a Gurobi bug, but a valid warning. |
@simonbowly Yes. This issue is not related to callback function with lazy constraints. function jvr6(x) return round(JuMP.value(x); digits = 6) end
function jdr6(x) return round( JuMP.dual(x); digits = 6) end To locate information in the context of multiple models, we can use file logging. function clear_log_file(file_string) return open(io -> nothing, file_string, "w") end # open, truncate, close
function set_logfile_for_model(file_string, model) # optional
JuMP.set_attribute(model, "OutputFlag", 1)
JuMP.set_attribute(model, "LogToConsole", 0)
JuMP.set_attribute(model, "LogFile", file_string)
end An successful example can be found at https://github.com/WalterMadelim/p8f.jl/blob/main/src/UnitCom_workable1.jl |
JuMP.set_silent(model)
immediately after creating thatmodel
.JuMP.set_silent(model)
just beforeJuMP.optimize!(model)
, you may still see the warning information being printed.For a programmer, the 2. choice is helpful in that you can detect problems. If you are confident there's no problem, then you can switch to 1. style, in this way you won't be bothered.
The text was updated successfully, but these errors were encountered: