'Quadratic objective function in Gurobi

I am building a model with a quadratic objective function. But I am having trouble on how to code it.

v is a matrix of coefficients.

This is the original objective:

 x = m.addMVar(shape=n, vtype=GRB.BINARY, name="x")  # binary var
 m.setObjective(v @ x, GRB.MAXIMIZE)

And I need to transform it in : max [(v*x)^2] I tried this, but it gives an error:

 x = m.addMVar(shape=n, vtype=GRB.BINARY, name="x")  # binary var
 m.setObjective(x @ v @ x, GRB.MAXIMIZE)

Could someone help me with this? Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source