Search code examples
juliaglpkjulia-jump

Julia "no method matching supports_default_copy_to(::GLPK.Optimizer, ::Bool)" declaring Model


I am new to Julia and tried to run the first example script in the Second Edition of Julia Programming for Operations Research, but the first two lines:

using JuMP, GLPK
m = Model(with_optimizer(GLPK.Optimizer))

throw the following error:

julia> m = Model(with_optimizer(GLPK.Optimizer))
ERROR: MethodError: no method matching supports_default_copy_to(::GLPK.Optimizer, ::Bool)
Closest candidates are:
  supports_default_copy_to(::MathOptInterface.Utilities.AbstractModel, ::Bool) at /home/mepstein/.julia/packages/MathOptInterface/C1XBe/src/Utilities/model.jl:693
  supports_default_copy_to(::MathOptInterface.Utilities.MockOptimizer, ::Bool) at /home/mepstein/.julia/packages/MathOptInterface/C1XBe/src/Utilities/mockoptimizer.jl:521
  supports_default_copy_to(::MathOptInterface.Utilities.CachingOptimizer, ::Bool) at /home/mepstein/.julia/packages/MathOptInterface/C1XBe/src/Utilities/cachingoptimizer.jl:165

In case it's relevant, using JuMP, GLPK threw the following warning:

┌ Warning: Replacing module MathOptInterface
└ @ Base loading.jl:942

And my versions are:

Julia: 1.3.1 (latest stable)
  "GLPK" => v"0.12.0"
  "JuMP" => v"0.20.1"

Solution

  • Issue solved by the book author at https://github.com/chkwon/jpor_codes/issues/4

    Running ] up from the julia interpreter upgraded GLPK to 12.1 from 12.0. Interesting because I had just installed GLPK in the first place only a couple hours ago. In fact I'm not even sure I 'upgraded' the installed version; from the log it looks like ] up made certain config files consistent with the version that was already installed?

    julia>
    (v1.3) pkg>  up
      Updating registry at `~/.julia/registries/General`
      Updating git-repo `https://github.com/JuliaRegistries/General.git`
     Resolving package versions...
     Installed GLPK ─ v0.12.1
      Updating `~/.julia/environments/v1.3/Project.toml`
      [60bf3e95] ↑ GLPK v0.12.0 ⇒ v0.12.1
      Updating `~/.julia/environments/v1.3/Manifest.toml`
      [60bf3e95] ↑ GLPK v0.12.0 ⇒ v0.12.1
      Building GLPK → `~/.julia/packages/GLPK/HjJiX/deps/build.log`
    

    In any case, the code in the question above now works and gives the following output:

    julia> using JuMP, GLPK
    
    julia> m = Model(with_optimizer(GLPK.Optimizer))
    A JuMP Model
    Feasibility problem with:
    Variables: 0
    Model mode: AUTOMATIC
    CachingOptimizer state: EMPTY_OPTIMIZER
    Solver name: GLPK```