Hello! I have a model in which I need to create constraints for the non-zero elements of a sparse matrix (a parameter). I create them as anonymous constraints, but I do not know how to find their dual values after the model runs to optimality. Any help will be appreciated!

I am using Julia 1.04 and JuMP 0.20.

Thanks!

Leonardo Rivera.

You need to use the constraint references returned by the `@constraint`

macro, e.g.

```
con_refs = Dict{Tuple{Int, Int}, JuMP.ConstraintRef}()
for col in 1:size(A, 2)
for k in nzrange(A, col)
row = rowvals(A)[k]
val = nonzeros(A)[k]
con_refs[(row, col)] = @constraint(model, val == 0)
end
end
optimize!(model)
duals = Dict(key => dual(value) for (key, value) in con_refs)
```

3 Likes

Thanks a lot. Your answer worked perfectly!

1 Like