0

For the purpose of coding a production planning problem, I am using "Julia". In the formulations, there is a formula with a lower bound which is a vector . Please have a look to the attachment

attachment.

When I want to enter this vector as the lower bound of summation the software gives me the error that summation bounds should be scaler

screenshot of Julia.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75

1 Answers1

0

The bracketed syntax got deprecated some time back - in a current version of Julia and JuMP (Julia 0.6.0, JuMP 0.18.0), the following works when I run it:

using JuMP
using Cbc
bar = Model(solver=CbcSolver())

# data 
N = 3
M = 3
W = 3
K = 3
T = 77
s = ones(3,3) 

@variable(bar, x[1:N,1:M,1:K,1:T],Bin)
p = reshape( [
  [[9,7,12]; [10,6,8]; [8,10,9]]; 
  [[6,5,9]; [8,4,6]; [6,8,6]];
  [[4,4,5]; [4,3,4]; [5,3,5]]],
  3,3,3)

for t = 1:T
  @constraint(bar, 
    sum( ( ( (x[i, j, k, t] * k 
      for h = t:t + p[i, j, k] + 1 ) 
        for j = 1:M) 
          for k = 1:K) 
            for i = 1:N) == 0)
end

solve(bar)

If using the current versions is not an option, plain old for loops should also work:

(... same stuff as before up to the for loop ...)

for t = 1:T
  s = 0.0
  for j = 1:M
    for k = 1:K
      for i = 1:N
        for h = t:t + p[i, j, k] + 1
          s += k*x[i,j,k,t]
        end
      end
    end
  end
  @constraint(bar, s == 0)
end

Which is arguably more readable than the first formulation anyway. Let me know if none of these versions work out for you, then we can look further.

P.S. If you ask something about a snippet of code, a screenshot is good, but actual code is better, then we don't have to type everything again :)

sm.swi
  • 1
  • 1