Skip to main content

Problem with reciprocal constraints in Gurobi

Answered

Comments

2 comments

  • Official comment
    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.
  • Jaromił Najman
    • 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

Post is closed for comments.