MethodError: no method matching getindex(::VariableRef, ::Int64)

I would guess that LT[j][t] and Z[j][t] should instead be LT[j, t] and Z[j, t]. Otherwise you are getting a VariableRef from your matrix and then trying to index the variable.

Please, if possible use triple backticks to quote your code next time. When using triple backticks:

```
for t in 1:tp
for j in 1:nt
c10= @constraint(p, LT[j][t] - (l[j] * Z[j][t]) == 0)
set_name(c10, “LTConstraint_[$j],[$t]”)
end
end
```

becomes

for t in 1:tp
    for j in 1:nt
        c10= @constraint(p, LT[j][t] - (l[j] * Z[j][t]) == 0)
        set_name(c10, "LTConstraint_[$j],[$t]")
    end
end

What is more legible.

2 Likes