How to retrieve the number of cutting planes added by callback?



1 comment

  • Jaromił Najman


    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 example, you can add the private variable \(\texttt{_cbCuts}\) to the model

    # Optimize model
    m._cbCuts = 0
    m._vars = vars
    m.Params.lazyConstraints = 1

    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 += 1

    After optimization, you can then access the number of added cuts

    print("Added "+str(m._cbCuts)+" cuts.")

    Best regards,

    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk