# Error using getvalue

**URL:** <https://discourse.julialang.org/t/error-using-getvalue/53546>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [January 18, 2021, 3:16pm UTC](https://discourse.julialang.org/t/error-using-getvalue/53546 "2021-01-18T15:16:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [January 18, 2021, 3:16pm UTC](https://discourse.julialang.org/t/error-using-getvalue/53546/1 "2021-01-18T15:16:37Z")

</div>

Hello!!

Whenever I try to use getvalue the following error appears to me:  
`MethodError: no method matches getvalue (:: ConstraintRef {Model, JuMP.GenericRangeConstraint {JuMP.GenericAffExpr {Float64, Variable}}})`

Could someone explain to me how this error came about?  
Is there another method for printing the results of the decision variables?

Thanks

```julia
using JuMP, MathOptInterface, GLPK, GLPKMathProgInterface
ModeloD = Model(solver = GLPKSolverMIP())

a = 4
t = 4
w = 2
i = 2

A = 1:a
T = 1:t
W = 1:w
I = i:i

Q = [8780 0; 0 11310; 1000 0; 0 2000]
RD = [1, 2, 3, 1]
DL = [2, 4, 4, 3]
RHE = [150, 151]
OHE = [25, 26]
NE = [14, 53]
WH = [2489 1447 3513 20914; 11073 5414 1523 16282]
CR = [11, 12]
CO = [50, 51]
WA = [1, 2, 1, 2]

@variable(ModeloD,x[A,T]<=0)
@variable(ModeloD,s[A,T]<=0)
@variable(ModeloD,er[W,T]<=0)
@variable(ModeloD,r[A,T] <=0)
@variable(ModeloD,wr[W,T]<=0)
@variable(ModeloD,o[A,T]<=0)
@variable(ModeloD,c[A],Bin)

@objective(ModeloD,Min,sum(CR[WA[a]]*(r[a,t]+o[a,t])+CO[WA[a]]*o[a,t] for a in A, t in T))

for w = 1:w,t=1:t
    m = @constraint(ModeloD,sum(r[a,t]+wr[w,t] for a in A)==RHE[w]*er[w,t])
    println(m)
end

for a = 1:a, w = 1:w,t= 1:t
    if Q[a,w]>0
      p1 = @constraint(ModeloD,sum(s[a,t] for t = RD[a]:DL[a])==Q[a,w]*(1-c[a]))
      #println(p1)
    end
end

for w = 1:w,t= 1:t
    r = @constraint(ModeloD,sum(Q[a,w]*x[a,t] for a in A)-sum(s[a,t] for a in A)<=(RHE[w]+OHE[w])*NE[w]-WH[w,t])
    #println(r)
end

print(ModeloD)

println("r = ", JuMP.getvalue(r))

```

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [January 18, 2021, 5:17pm UTC](https://discourse.julialang.org/t/error-using-getvalue/53546/2 "2021-01-18T17:17:30Z")

</div>

Could you provide a bit more context? Maybe the code that you are executing 🙂

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [January 18, 2021, 5:21pm UTC](https://discourse.julialang.org/t/error-using-getvalue/53546/3 "2021-01-18T17:21:02Z")

</div>

Hi @impressium, thanks for the suggestion

I just edited my question and now with the model I’m trying to compile

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [January 18, 2021, 5:55pm UTC](https://discourse.julialang.org/t/error-using-getvalue/53546/4 "2021-01-18T17:55:44Z")

</div>

Your last loop is overwriting the variable `r` with the constraint `r`, the message is clear, the value inside `r` is a constraint not a variable. Also, `getvalue` is from old `JuMP` versions (0.18 and before). I recommend creating a new project/environment where you install `JuMP` first to get the latest version and use it. For example:

```julia
$ mkdir my_project
$ cd my_project
$ julia
julia> import Pkg
julia> Pkg.activate(".") # this will create Project.toml and Manifest.toml in the folder
julia> Pkg.add("JuMP")
julia> Pkg.add("GLPK") # do not add GLPKMathProgInterface this is obsolete
julia> include("your_code.jl") # to run your code

```

When you open the REPL again you need to repeat the two first steps to enter the right environment. Also, you should not have all these variables and for loops in global scope, put then inside a function and then you can redefine the function however you like inside the REPL itself.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [January 18, 2021, 8:35pm UTC](https://discourse.julialang.org/t/error-using-getvalue/53546/5 "2021-01-18T20:35:09Z")

</div>

Hi @Henrique_Becker  
Solved model, thank you!!!
