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

Problem with reciprocal constraints in Gurobi

回答済み

コメント

1件のコメント

  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    The error is thrown, because \(\texttt{frac_expression}\) is already a quadratic expression. So you would be generating an expression with a trilinear product. To avoid this, you can introduce \(\texttt{rhs_expression}\) as an auxiliary variable.

    # Define the entire right-hand side expression raised to the power of -1
    rhs_expression = m.addVar(lb = -GRB.INFINITY, name ="rhs_expression")
    m.addConstr(rhs_expression == sum_expression + frac_expression)

    Please note that an explicit definition of

    frac_expression = gp.LinExpr(0)

    is missing in your current code. It would be better to add this to avoid any compiler and modeling issues.

    Right now your model is infeasible. Please refer to How do I determine why my model is infeasible? for more information on how to tackle infeasibility.

    It is always a good idea to use the write method to write the built model to a human-readable LP file

    model.write("myModel.lp")

    You can open the file \(\texttt{myModel.lp}\) in any standard text editor and check whether it looks as expected.

    Best regards, 
    Jaromił

    0

サインインしてコメントを残してください。