2

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

lafinstack
  • 23
  • 3

1 Answers1

2

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

Oscar Dowson
  • 2,395
  • 1
  • 5
  • 13
  • When I run this I get: `ERROR: LoadError: At REPL[51]:1: `@constraint(m, [j = 1:3, j = 1:7], sum((x[i, j, k] for i = 1:N)) >= W[j, k])`: The index j appears more than once. The index associated with each set must be unique.` - does this only work for certain models? (I just used `m = Model()` locally to run this) – Nils Gudat Nov 27 '21 at 08:47
  • 1
    The second index should be k. I just made a typo. Fixed now. – Oscar Dowson Nov 27 '21 at 08:51