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

Using addGenConstrAnd leads to "max general constraint violation"

回答済み

コメント

6件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff 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?.
  • Hans Kirchner
    • Gurobi-versary
    • Conversationalist
    • First Question

    I have a relatively small minimal example, once with the built-in "_and" and once with my custom "logical_and". Both models are clearly feasible but with the built-in "_and" I get this "max general constraint violation" warning.

     

    I'm happy to send it to you if you are interested.

    0
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    Hi Hans,

    Could you post your minimal working example? Thanks!

    Eli

     

    0
  • Hans Kirchner
    • Gurobi-versary
    • Conversationalist
    • First Question

    I uploaded my model with general-AND constraints to your file uploader at https://www.gurobi.com/upload-a-model/ I hope that was the correct way.

     

    The file is named: minimal_example_genconstr_and.rew.gz

     

    When you run it like this:

     

    m = read("minimal_example_genconstr_and.rew.gz")
    m.optimize()

    for v in m.getVars():
    v.LB = v.X
    v.UB = v.X

    m.optimize()

     

    You will get this for the first optimize():

     

    Solution count 1: 0

    Optimal solution found (tolerance 1.00e-04)
    Warning: max constraint violation (1.0000e+00) exceeds tolerance
    Warning: max general constraint violation (1.0000e+00) exceeds tolerance
    (model may be infeasible or unbounded - try turning presolve off)
    Best objective 0.000000000000e+00, best bound 0.000000000000e+00, gap 0.0000%

     

    And then this for the second optimize():

     

    Solution count 0

    Model is infeasible

     

     

     

    However, when you replace all the AND-constraints with my custom implementation:

     

    from gurobipy import *

    def main():
      m = read("minimal_example_genconstr_and.rew.gz")
      gencons = m.getGenConstrs()
      for gc in gencons:
        if gc.getAttr(GRB.Attr.GenConstrType) == GRB.GENCONSTR_AND:
          resvar, vars = m.getGenConstrAnd(gc)
          m.remove(gc)
          logical_and(m, resvar, vars)
      m.optimize()


    def logical_and(m, y, vars):
      n = len(vars)
      m.addConstr(quicksum(vars) - n * y >= 0)
      m.addConstr(quicksum(vars) - n * y <= n - 1)


    if __name__ == "__main__":
      main()

     

    Suddenly, it is feasible and no warning is printed:

     

    Solution count 1: 0

    Optimal solution found (tolerance 1.00e-04)
    Best objective 0.000000000000e+00, best bound 0.000000000000e+00, gap 0.0000%

    0
  • Hans Kirchner
    • Gurobi-versary
    • Conversationalist
    • First Question

    It should be noted that running the model with Presolve turned off does not make the model infeasible or unbounded:

     

    gurobi_cl Presolve=0 minimal_example_genconstr_and.rew.gz

     

    Optimal solution found (tolerance 1.00e-04)
    Best objective 0.000000000000e+00, best bound 0.000000000000e+00, gap 0.0000%

    0
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    Hi Hans,

    Thanks for bringing this to our attention! The underlying issue has been fixed for subsequent releases of Gurobi.

    Eli

    0

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