I want to solve a maximisation problem with objective
f(x, y, z) = 0.5 * (x^2 + y^2 + z^2)
with x, y, z in [0, 1].
However when feeding this problem to CPLEX with the code below, it prompts an error saying that my objective is non-convex.
Also I should say that I checked the .lp file to be sure that I have correctly stated the problem.
import cplex
p = cplex.Cplex()
p.objective.set_sense(p.objective.sense.maximize)
p.variables.add(ub=[1, 1, 1],
names=["x", "y", "z"])
qmat = [[[0], [1.]],
[[1], [1.]],
[[2], [1.]]]
p.objective.set_quadratic(qmat)
p.write("qpex.lp")
p.solve()
I don't understand why since my function f is definitely convex (the Hessian is the identity matrix). What am I doing wrong?
Notice that when you specify the objective
p.objective.set_sense(p.objective.sense.maximize)
You have specified it to be a maximization problem.
To make it a convex optimization problem, you should be solving a minimization problem instead.
Minimizing a convex function is a convex optimization problem, maximizing a convex function in general is not a convex optimization problem.