Modelling Nonlinear Objective function/Constraint
回答済みDear all,
I am facing issue in modelling a nonlinear constraint in Gurobi : x^3 >= k; (where x is the a variable between [-1,1] and k is a constant)
I am modelling the constraint as shown below:
int b = 3;
model.addGenConstrPow(x, z, b);
model.addConstr(z >= k);
I am facing the following error:
Error code = 10003
lower bound of x variable is less than zero for POW function
Can someone explain how to manage the issue as I cannot change the bounds on the variable to positive values?
-
正式なコメント
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?. -
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 -
Thanks a lot Jaromil.
0
投稿コメントは受け付けていません。
コメント
3件のコメント