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

gurobipy.GurobiError: Divisor must be a constant

回答済み

コメント

2件のコメント

  • Jaromił Najman
    • Gurobi Staff 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

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