Nonlinear Convex Objective (Natural Log)
AnsweredAssuming the latest version of Gurobi, I'm curious what modeling approaches I can take with natural log functions in an objective. Should I follow piece-wise linearization related documentation, or does Gurobi include solver support for these situations? I tried formulating with NLExpr but this threw "gurobipy._exception.GurobiError: Objective must be linear or quadratic". Are NLExpr's only supported in constraints? Thank you ahead of time for your help.
-
Hi Ethan,
As you saw in the error, Gurobi accepts a linear or quadratic function as the objective function. NLExpr is only available for constraints. However, you can use auxiliary variables to set the nonlinear function to the objective function like follows:
# x,y are arguments to log(x+y)
# z = log(x+y)
model.addConstr(z == nlfunc.log(x+y))
model.setObjective(z)Thanks,
Ryuta1
Please sign in to leave a comment.
Comments
1 comment