Lazy constraints : loop does not stop while they are satisfied

Hello !

I am getting troubles using lazy constriants for solving a MILP (using Gurobi).

My code is structured as follows : (here are some parts of it)

# Extract from the code : 

using JuMP
using Gurobi

m = Model(solver=GurobiSolver(Threads=1))

[...]

function correctConstraints(cb)

	# A function has been called and has returned 1 for the variable Err if the lazy constraints
	# have been violated in the solution retriaved from the model (zero otherwise).	

	if Err==0
		println("No error ! The optimal solution has een found !\n \n")
		return
	end

	if Err==1
		println("Adding lazy constraints... \n \n")
		
		# Adding several constraints to the model

		for k in [...]
			@lazyconstraint(cb,***lazy constraint***)
		end
	end
return
end

# Model :

[...]

solve(m),

addlazycallback(m, correctConstraints)

# end of the code section.

When the line “No error ! The optimal solution has een found !” is displayed, I would expect that the
code stops running. However, it appears to loop serveral times, even if I do not remove from my model the constraints that I’d like to add lazily.

It seems that this problem does not come from parallelism.

Thank you already for your help !

Even if you found the optimal solution to a MIP, Gurobi wants to prove the optimality by improving the dual bound. Maybe some more nodes yield integral solutions on the way to close the gap?

Thank you. This would mean that everything is going well ?

Maybe. You could check the solver output for the development of the lower and upper bounds.

Further, you could print the solution candidates, to detect whether your callback is called repeatedly on the same values.