Can the callback function combine two check mechanism?(TSP subtour elimination + Bender's decomposition)
AnsweredHello, 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
# ...
# ...
else:
# 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:
model.terminate()
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???
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
I have verified that all the lazy constraints' formulations are correct。。。
0 -
Hi Jacob,
Could you briefly explain what is \(\texttt{N}\) in your code snippet?
The case \(\texttt{len(tour) == N}\) cannot be reached because it always lands in \(\texttt{len(tour) < N+1}\).
Best regards,
Jaromił0
Post is closed for comments.
Comments
3 comments