Error using getvalue

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

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

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

Hi @impressium, thanks for the suggestion

I just edited my question and now with the model Iā€™m trying to compile

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:

$ 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.

2 Likes

Hi @Henrique_Becker
Solved model, thank you!!!