Skip to main content

gurobipy.GurobiError: Divisor must be a constant

Answered

Comments

3 comments

  • Official comment
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Dividing by a variable (or a sum of variables) is currently not supported in Gurobi. However, with a few auxiliary variables and equality constraints, it is possible to formulate your objective function in Gurobi.

    To formulate a division by an optimization variable, you should introduce an auxiliary variable \(z_n\) for the numerator expression and an auxiliary variable \(z_d\) for the denominator expression, i.e., add equality constraints \(z_n = \text{numerator}\) and \(z_d = \text{denominator}\).
    Next, you can follow the instructions in How do I divide by a variable in Gurobi? to model the division \(\frac{1}{z_d} = x\).
    You can then finally use \(x\) and \(z_n\) in your objective function as \(z_n \cdot x\).
    Please note that your model is nonconvex and you have to set the NonConvex parameter.

    Best regards, 
    Jaromił

     

    0
  • Danning Xie
    • Gurobi-versary
    • Conversationalist
    • First Question

    Thank you! It helps. 

     

     

    Danning

    0

Post is closed for comments.