The first way of imposing the constraints works. The second way causes the error below. Is there a better way to impose theses constraints?
using JuMP
using LinearAlgebra
v = 64
J = 10
model = Model()
@variable(model, -(v-1) <= Q[1:J,1:J] <= v-1, Int)
@variable(model, 0 <= p[1:J] <= v-1, Int)
# Define p via equality constraints based on manipulations of other variables.
@constraint(model, Q .== repeat(p', outer = [J,1])-repeat(p, outer = [1,J]))
@variable(model, 0 <= uQ[1:J,1:J] <= v-1, Int)
@constraint(model, uQ .== triu(Q+zeros(J,J),1))
@constraint(model, uQ .== triu(Q,1))
Error caused by method 2:
ERROR: MethodError: Cannot `convert` an object of type AffExpr to an object of type VariableRef
Closest candidates are:
convert(::Type{T}, ::T) where T at ~/julia-1.7.3/share/julia/base/essentials.jl:218
VariableRef(::Any, ::Any) at ~/.julia/packages/JuMP/vuP7I/src/variables.jl:203
Stacktrace:
[1] setindex!
@ ./array.jl:905 [inlined]
[2] triu!
@ ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/dense.jl:139 [inlined]
[3] triu(M::Matrix{VariableRef}, k::Int64)
@ LinearAlgebra ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/dense.jl:145
[4] macro expansion
@ ~/.julia/packages/MutableArithmetics/9dpep/src/rewrite.jl:322 [inlined]
[5] macro expansion
@ ~/.julia/packages/JuMP/vuP7I/src/macros.jl:831 [inlined]
[6] top-level scope
@ REPL[20]:1