Hi, I am setting up a non-linear objective which contains both quadratic and non-linear terms. However, I am getting the following error
Unexpected quadratic expression 378.5346047250809 e² + 378.5346047250809 f² + 378.5346047250809 e² + 378.5346047250809 f² - 757.0692094501618 e*e - 757.0692094501618 f*f in nonlinear expression. Quadratic expressions (e.g., created using @expression) and nonlinear expressions cannot be mixed.
Now, the thing is I am setting non-linear constraints as well which contains both quadratic and non-linear expressions using @NLconstraint macro but I am not getting the above mentioned error. For the objective function, I need the summation of non-linear expression, therefore, I set up a loop and store all non-linear expressions in an array, and then I am using the ‘sum’ function in order to get the final expression. However, when I give this final expression to @NLobjective macro, I am getting the above-mentioned error. Why is that? and what would be the possible solutions to overcome this error?
The code for objective function is as follows:
ploss =  for i in 1:nLines rline = nw_lines[i].line_r gij_line = real(yij_line[i,1]) bij_line = imag(yij_line[i,1]) lcrnt = (gij_line^2+bij_line^2)*((e[nw_lines[i].line_from]^2+f[nw_lines[i].line_from]^2)+(e[nw_lines[i].line_to]^2+f[nw_lines[i].line_to]^2) -2(e[nw_lines[i].line_from]*e[nw_lines[i].line_to]+f[nw_lines[i].line_from]*f[nw_lines[i].line_to])) push!(ploss,lcrnt) end loss_expr = sum(ploss[j] for j in 1:size(ploss,1)) @NLobjective(acopf,Min,loss_expr)