How to retrieve the number of cutting planes added by callback?
AnsweredComments
1 comment
-
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ł
Please sign in to leave a comment.
Is there any API aimed for counting the number of cutting planes added by user defined callback?