How to use @constraintref correctly? In Julia Language

217 Views Asked by At

guys,I wrote the code and got the following error: @constraint is not defined. What did I wrong. How to fix it? Thanks

@constraintref restrição[1:2]
for j=1:2
@constraint(m, restrição[j], sum(A[j,i]*x[i] for i=1:3) <= b[j])`
end
```
1

There are 1 best solutions below

4
Przemyslaw Szufel On

You are using an old syntax that was valid in JuMP 0.18 (you can see the link for more details)

As of today you can just use an assignment operator instead of @constraintref macro and your code could look like this:

using GLPK
m = Model(with_optimizer(GLPK.Optimizer))
@variable(m, x[1:5] >= 0)
myCons = Vector{ConstraintRef}(undef, 5)
for i = 1:5
    myCons[i] = @constraint(m, x[i] >= i)
end