Query solving time in JuMP v0.19

Hi guys,

I just updated to JuMP v.019, and notice getsolvetime is removed.

I did not find the updated function in JuMP doc. So I turn to MOI doc, where I find the example of MOI.get(optimizer, MOI.TerminationStatus()).

I tried this on a simple example on my PC,

using JuMP,Gurobi,MathOptInterface
env = Gurobi.Env()

m = Vector{Model}( undef, 3 )
m[ 1 ] = Model( with_optimizer( Gurobi.Optimizer , env ) )

@variable( m[ 1 ] , b[ 1:5 ] >= 0  )
@constraint( m[ 1 ] , b[ 1 ] >= 1 )
@objective( m[ 1 ] , Min , b[ 3 ] )

JuMP.optimize!( m[ 1 ] )
println( MathOptInterface.get( m[ 1 ] , MathOptInterface.SolveTime( ) ) )

And julia runs the program and report solving time correctly.

But when I turns in to a more complicated program I meet some errors

m = Vector{Model}( undef, 10 )

# add variables and constraints
# to define feasible region for each subproblem
for k in 1:10   
  m[ k ] = Model( with_optimizer( Gurobi.Optimizer , env ) )
  @variable( m[ k ] , c )
end

# outter loop for update lagrangian dual variables
for it in 1:50
  set up lagrangian dual variable \lambda
  # inner loop for solving decomposed subproblem
  # with modified objective
  for k in 1:100  
    c = m[ k ][ :c ]
    @objective( m[ k ] , Min , c - \lambda )
    JuMP.optimize!( m[ k ] )
    println( MathOptInterface.get( m[ k ] , MathOptInterface.SolveTime() ) )
  end
end

The error is

ERROR: LoadError: MethodError: no method matching get(::Int64, ::MathOptInterface.SolveTime)
Closest candidates are:
  get(::Model, ::MathOptInterface.AbstractModelAttribute) at C:\Users\tommyricardo\.julia\packages\JuMP\jnmGG\src\JuMP.jl:593
  get(::MathOptInterface.Utilities.MockOptimizer, ::MathOptInterface.AbstractModelAttribute) at C:\Users\tommyricardo\.julia\packages\MathOptInterface\5SeJM\src\Utilities\mockoptimizer.jl:167
  get(::MathOptInterface.Utilities.CachingOptimizer, ::MathOptInterface.AbstractModelAttribute) at C:\Users\tommyricardo\.julia\packages\MathOptInterface\5SeJM\src\Utilities\cachingoptimizer.jl:420
  ...
Stacktrace:
 [1] top-level scope at C:\Users\tommyricardo\.julia\packages\JuMP\jnmGG\src\macros.jl:279
 [2] top-level scope at F:\a__top_secret\lagrangian_relaxation_TypeExperiment_SingleUnitQIP.jl:177
in expression starting at F:\a__top_secret\lagrangian_relaxation_TypeExperiment_SingleUnitQIP.jl:171

Can anyone help to explain this? Or provide some methods of query solving time in JuMP?

MethodError: no method matching get(::Int64, ::MathOptInterface.SolveTime)

This suggests that you are passing m[k] is an Int64.

As one potential problem, it looks like you initialize k=10 models, but look through k=100 models in the second loop.

It is hard to say anything else without a minimal working example (MWE). See:

Thanks very much for the reply, and I get your message on Int64.

I just realize I made some syntax error… it is not a problem of julia or JuMP.

I tried to delete my post but turns out I am not allowed to do so :joy:

Sorry for posting such a silly question :sweat_smile: