Hello, I use callback function to optimize a MIP problem.
if where == GRB.Callback.MIPSOL:
selected = gb.tuplelist((i, j) for i in range(N + 1) for j in range(N + 1)
if model.cbGetSolution(model.getVarByName('r_' + str(i) + str(j))) > 0.5)
# find the shortest cycle in the selected edge list
tour = self.subtour(selected)
if len(tour) < N+1:
# Add the subtour elimination constraint
# Bender's cut
LB = model.cbGet(GRB.Callback.MIPSOL_OBJBND)
status, UB = sub_problem(z_1)
if status == 3:
# Add the feasibility cut
if status == 2:
if abs(UB - LB) >= 0.1:
# Add the optimality cut
elif len(tour) == N:
The logic is quite clear. However, it doesn't terminate according to the termination condition. It ends automatically and the length of tour is less than N. I don't know what's wrong with my code... And I want to know why the callback process would end by itself???
Please sign in to leave a comment.