# How do I find the shadow price of anonymous constraints?

**URL:** <https://discourse.julialang.org/t/how-do-i-find-the-shadow-price-of-anonymous-constraints/29349>\
**Category:** Optimization (Mathematical)\
**Created:** [October 1, 2019, 4:07am UTC](https://discourse.julialang.org/t/how-do-i-find-the-shadow-price-of-anonymous-constraints/29349 "2019-10-01T04:07:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonardo\_Rivera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leonardo_rivera/32/10562_2.png) [@Leonardo\_Rivera](https://discourse.julialang.org/u/Leonardo_Rivera)\
**Post date:** [October 1, 2019, 4:07am UTC](https://discourse.julialang.org/t/how-do-i-find-the-shadow-price-of-anonymous-constraints/29349/1 "2019-10-01T04:07:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [October 1, 2019, 8:24am UTC](https://discourse.julialang.org/t/how-do-i-find-the-shadow-price-of-anonymous-constraints/29349/2 "2019-10-01T08:24:50Z")

</div>

You need to use the constraint references returned by the `@constraint` macro, e.g.

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![Leonardo\_Rivera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leonardo_rivera/32/10562_2.png) [@Leonardo\_Rivera](https://discourse.julialang.org/u/Leonardo_Rivera)\
**Post date:** [July 8, 2021, 7:59pm UTC](https://discourse.julialang.org/t/how-do-i-find-the-shadow-price-of-anonymous-constraints/29349/3 "2021-07-08T19:59:45Z")

</div>

Thanks a lot. Your answer worked perfectly!
