I cannot use the commands with_optimizer() and getobjectivevalue() with JuMP, Gurobi

Hi, please somebody can help me?
I cannot use this commands when I want to use JuMP and Gurobi:

with_optimizer()
getobjectivevalue()

I recived UndefVarError: … not defined

1 Like

Hi! Can you please provide a minimum working (or in this case, failing) example? It would make it much easier to help you

1 Like

Yes, thank you. I hace JuMP v1.1.1

using JuMP, Clp
m = Model(with_optimizer(Clp.Optimizer, LogLevel = 0)) 

R = [r for r=1:3] #Reactores
MP= ["A","B","C"] #Materia Prima
Pr=["E","F","G"] #Productos

@variable(m, F[mp in MP, r in R] >= 0)
@variable(m, P[p in Pr]>= 0)

@constraint(m, r1, sum(F["A",r] for r in R)<= D["A"]) 
@constraint(m, r2, sum(F["B",r] for r in R)<= D["B"])
@constraint(m, r3, sum(F["C",r] for r in R)<= D["C"])
@constraint(m, r4, P["E"]==1.5*F["A",1])
@constraint(m, r5, P["E"]==3*F["B",1])
@constraint(m, r6, P["F"]==1.5*F["A",2])
@constraint(m, r7, P["F"]==3*F["C",2])
@constraint(m, r8, P["G"]==2*F["A",3])
@constraint(m, r9, P["G"]==4*F["B",3])
@constraint(m, r10, P["G"]==3*F["C",3])
@constraint(m, r11, F["C",1]==0)
@constraint(m, r12, F["B",2]==0)

@expression(m, ganancias, sum(G[p]*P[p] for p in Pr))
@objective(m, Max, ganancias)
optimize!(m)

UndefVarError: with_optimizer not defined

Stacktrace:
[1] top-level scope
@ In[3]:2
[2] eval
@ .\boot.jl:373 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1196

1 Like

I just checked by searching the JuMP documentation, and it seems with_optimizer was deprecated in JuMP v0.21.0. Please refer to the latest tutorial to see how optimizers should be specified :slight_smile:

2 Likes

The bad news is that we changed this syntax a couple of years ago. The good news is that now JuMP is 1.0, the syntax below won’t change in future:

m = Model(optimizer_with_attributes(Clp.Optimizer, "LogLevel" => 0))
1 Like

Should be objective_value(m). See the documentation for syntax.

1 Like

¡Muchas gracias!

¡Muchas gracias! Now it works

2 Likes