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

Separate access to the dual values of various constraints

回答済み

コメント

5件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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.
  • Ronald van der Velden
    • Gurobi Staff

    I would consider using addConstrs() for each of the constraint sets. It gives you back a dictionary, e.g. a mapping of i/j/d indices to constraints. Then you can pass that result to getAttr() and you get back a similar dictionary with duals.

    ca = model.addConstrs( (quicksum(x[i, j, d] for j in J for d in D) <= 1 for i in I), name = "x")
    cb = model.addConstrs( (quicksum(x[i, j, d] for i in I) + y[j, d] == 1 for j in J for d in D), name = "y")
    # Relax and solve
    duals = relaxed.getAttr("Pi", ca)
    print(duals)

     

    0
  • Nico T
    • Gurobi-versary
    • First Question
    • Conversationalist

    Ronald van der Velden Thank you for your help. Sadly it does return this error "gurobipy.GurobiError: Constr not in model". How do i fix that?

    0
  • Ronald van der Velden
    • Gurobi Staff

    Ah, sorry about that - I should have tested your exact scenario in full and had ignored the fact that calling relax() returns a new model where you cannot query attributes based on constraints from the original model. Unfortunately there is not a clean way to map elements from the original model to their counterpart in the relaxed model. Personally I would relax the model in-place using the second method from this article.

    0
  • Nico T
    • Gurobi-versary
    • First Question
    • Conversationalist

    Ronald van der Velden No worries. I tried your approach and initially it didnt work. But updating the model with "model.update()" after assigning names to the constraints did the trick. Thanks

    0

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