メインコンテンツへスキップ

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

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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?.
  • Jaromił Najman
    • Gurobi Staff

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

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

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

    Best regards,
    Jaromił

    0

投稿コメントは受け付けていません。