Skip to main content

Modelling Nonlinear Objective function/Constraint

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 why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff

    Dear Suyog,

    The documentation of the addGenConstrPow method explicitly states that the lower bound of the \(x\) variable has to be nonnegative. This is mainly to avoid domain error caused when non-integer values are used in the exponent.

    To model \(x^3\) with \(x \in [-1,1]\), you can use the addGenConstrPoly method. Your constraint can be model as

    import gurobipy as gp 
    from gurobipy import GRB

    m = gp.Model("test")

    x = m.addVar(lb=-1, ub=1, vtype=GRB.CONTINUOUS, name="x")
    z = m.addVar(lb=-1, ub=1, vtype=GRB.CONTINUOUS, name="z")

    # z = 1.0 * x^3 constraint
    m.addGenConstrPoly(x, z, [1,0,0,0])

    Best regards,
    Jaromił

    0
  • Suyog Nigudkar
    • Gurobi-versary
    • First Comment
    • First Question

    Thanks a lot Jaromil. 

    0

Post is closed for comments.