Search code examples
juliajulia-jump

How do I set JuMP constraint equal to value in an array?


I'm having difficulty adding a constraint to my model

Sum from i = 1 to N of X_ijk = W_jk for all values of j,k

Heres what I've tried

N = 10
W = [11 12 13 14 15 16 17;
     9 14 21 21 12 15 16;
     14 21 15 13 12 17 17]

for i in 1:N

    @constraint(m, sum(x[i, j, k] for j in 1:3, k in 1:7 ) >= W[j, k])

end

But i keep getting an error telling me that j and k are not defined. Id appreciate some help with the correct syntax


Solution

  • You need:

    @constraint(m, [j=1:3, k=1:7], sum(x[i, j, k] for i in 1:N) >= W[j, k])
    

    Documentation: https://jump.dev/JuMP.jl/stable/manual/constraints/#Constraint-containers