Hi I came across this issue while migrating my code from Julia 0.6 to Julia 1.0. I don't know if this is intentional as my code runs fine in Julia 0.6. Here is some code:
using LinearAlgebra;
using JuMP;
using Gurobi;
m = Model(solver=GurobiSolver())
@variable(m, x[i=1:3], lowerbound=0, upperbound=1);
Q = [1 0 0; 0 1 0; 0 0 1;];
c = [3,2,1];
@objective(m, Min, x'*(Q+Matrix(Diagonal([1,2,3])))*x + c'*x - sum(i*x[i] for i=1:3));
status = solve(m);
will trigger the following error (Julia 0.7):
ERROR: LoadError: in setobjective: array of size (1,) passed as objective; only scalar objectives are allowed
However, everything works fine with the following equivalent code, which defines a quadratic expression first before putting into macro "@objective":
using LinearAlgebra;
using JuMP;
using Gurobi;
m = Model(solver=GurobiSolver())
@variable(m, x[i=1:3], lowerbound=0, upperbound=1);
Q = [1 0 0; 0 1 0; 0 0 1;];
c = [3,2,1];
qobj = x'*(Q+Matrix(Diagonal([1,2,3])))*x + c'*x - sum(i*x[i] for i=1:3) ;
@objective(m, Min, qobj);
status = solve(m);
Hi I came across this issue while migrating my code from Julia 0.6 to Julia 1.0. I don't know if this is intentional as my code runs fine in Julia 0.6. Here is some code:
will trigger the following error (Julia 0.7):
However, everything works fine with the following equivalent code, which defines a quadratic expression first before putting into macro "@objective":