1

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 Answers1

1

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
Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62
  • It was not clear to me where the constraints in matrix form are. Could you detail a litlle bit more your explanation. I'm a beginner. I would appreciate so much. Thanks. – Rodrigo Costa Jul 28 '20 at 03:29
  • do you think it is better for me download the long stable version instead version 1.4-2? I'm having so much problems with this version. All examples i encounter to study returns an error in this version – Rodrigo Costa Jul 28 '20 at 03:31
  • 1
    The problem is with the version of `JuMP` not the version of Julia. You should use the latest version of JuMP and perhaps from time to time you will run into tutorials for the old version (the JuMP API has completely changed with the version 0.19 and you need to look for tutorials that were created after July 2019) – Przemyslaw Szufel Jul 28 '20 at 07:22
  • 1
    "It was not clear to me where the constraints in matrix form are" - all constraints and data are held in the `m` object that is of type `JuMP.Model`. There are many ways to extract them. Have a look at this SO question: https://stackoverflow.com/questions/62782287/how-to-write-a-jump-constraint-into-a-text-file – Przemyslaw Szufel Jul 28 '20 at 07:26