Callbacks interfering with solver output

Hello all,

I am currently working on a MILP using JuMP and Gurobi. As far as I’m aware my versions are all up to date - Julia 1.6.3, JuMP v0.21.10, Gurobi.jl v0.9.14 (and Gurobi - the solver - 9.1.2).

I’m solving my problem using a branch-and-cut approach with lazy cuts. In order to check for cuts, a separation problem is solved - nothing too crazy, the separation problem is rather easy to solve. (I am very grateful for solver-independent callbacks, by the way. Thanks JuMP team !)

Those of you who work with Gurobi might be familiar with a line that appears when you declare your model. In my case it displays the following : Academic license - for non-commercial use only - expires 2022-08-27.

My original problem was that this line appeared every time my callback function was called to, and hence overtook the logs of the main problem - evolution of objective, bound, gap and such was impossible to read. A work-around I’ve used before for such an issue in a cutting planes approach was to temporariliy redirect the output to nothing using the following :

oldstd = stdout
redirect_stdout(open("null", "w"))
separation_model = Model(Gurobi.Optimizer) #Line that produces unwanted output
redirect_stdout(oldstd)

I added this around the model declaration in my callback function, but this severely interferes with the logs of the main optimization problem, as now most of the information is missing. I figure this has to do with the simple fact that the callback function is called many times during branch-and-cut, perhaps on different threads at a time.

Is there perhaps a less barbaric way to prevent this line from being displayed, or did I misunderstand the cause of the issue ?

Thanks for reading.

Re-use an environment:

1 Like

Perfect ! Thank you for your answer, that’s exactly the kind of solution I was looking for.

1 Like