How to retrieve the number of cutting planes added by callback?
Answered-
Is there any API aimed for counting the number of cutting planes added by user defined callback?
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 why not try our AI Gurobot?. -
Hi,
There is no dedicated attribute or API call to retrieve the number of cutting planes added by a user defined callback but it is possible to make the bookkeeping on your own.
For example, to count the number of added cuts in the tsp.py example, you can add the private variable \(\texttt{_cbCuts}\) to the model
...
# Optimize model
m._cbCuts = 0
m._vars = vars
m.Params.lazyConstraints = 1
m.optimize(subtourelim)
...and increase it by 1 every time a cut gets added to the problem in the callback
def subtourelim(model, where):
...
if len(tour) < n:
# add subtour elimination constr. for every pair of cities in tour
model.cbLazy(gp.quicksum(model._vars[i, j]
for i, j in combinations(tour, 2))
<= len(tour)-1)
model._cbCuts += 1After optimization, you can then access the number of added cuts
print("Added "+str(m._cbCuts)+" cuts.")Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments