I'm trying to implement the following constraint in a JuMP environment:
@constraint(m, ((c*x) + (p*o)) + (r.*z) - d .== g')
Unfortunately, I get the following error ERROR: MethodError: no method matching append
But trying the element-wise multiplication alone does not return any error and implements it correctly into the model.
Here you have the minimal example I'm working with.
m = Model(solver = GLPKSolverLP());
np = 3; #number of products
c = [3 7 5;
6 5 7;
3 6 5;
-28 -40 -32];
g = [200 200 200 -1500];
n = length(g);
o = [1 1 1]';
@variable(m, x[1:np] >= 0);
@variable(m, d[1:n] >= 0);
@variable(m, z[1:n] >= 0);
@variable(m, r[1:n] >= 0);
@variable(m, p[1:n,1:np] >= 0);
@objective(m, Min, sum(d));
@constraint(m, ((c*x) + (p*o)) + (r.*z) - d .== g')
It seems that there is a problem when you add quadratic term to linear term and quadratic term is on right hand side of the addition inside @constraint
macro.
There are two solutions:
A. write the quadratic term as first like this:
@constraint(m, (r.*z) + ((c*x) + (p*o)) - d .== g')
B. define LHS of the equation outside (and now the order of terms does not matter)
constr = ((c*x) + (p*o)) + (r.*z) - d
@constraint(m, constr .== g')
As a side note: your problem is quadratic so GLPKSolverLP
will not solve it as it does not allow such constraints.