# Problem with optimisation code

**URL:** <https://discourse.julialang.org/t/problem-with-optimisation-code/27936>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 24, 2019, 2:52pm UTC](https://discourse.julialang.org/t/problem-with-optimisation-code/27936 "2019-08-24T14:52:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ajaychat3](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Post date:** [August 24, 2019, 2:52pm UTC](https://discourse.julialang.org/t/problem-with-optimisation-code/27936/1 "2019-08-24T14:52:46Z")

</div>

What is the issue with the following code? I upgraded the packages today and facing the error. It used to work before upgrading.

```julia
using JuMP, Cbc,Ipopt,Optim
m = Model(with_optimizer(Cbc.Optimizer))

@variable(m, 0 <= x <= 2 )
@variable(m, 0 <= y <= 30 )

@objective(m, Max, 5x + 3*y )

@constraint(m, 1x + 5y <= 3.0 )

print(m)

status = optimize!(m)

println("Objective value: ", objective_value(m))
println("x = ", value(x))
println("y = ", value(y))

UndefVarError: with_optimizer not defined

Stacktrace:
 [1] top-level scope at In[8]:2

```

---

<div class="post-metadata">

**Author:** ![Ajaychat3](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Post date:** [August 24, 2019, 2:58pm UTC](https://discourse.julialang.org/t/problem-with-optimisation-code/27936/2 "2019-08-24T14:58:56Z")

</div>

for easy reference here is the package details.

```julia
1.1) pkg> st
    Status `C:\Users\Himanshi\.julia\environments\v1.1\Project.toml`
  [c52e3926] Atom v0.9.1
  [6e4b80f9] BenchmarkTools v0.4.2
  [a076750e] CPLEX v0.5.0
  [336ed68f] CSV v0.5.11
  [49dc2e85] Calculus v0.5.0
  [9961bab8] Cbc v0.6.0
  [e2554f3b] Clp v0.6.2
  [a93c6f00] DataFrames v0.19.2
  [1313f7d8] DataFramesMeta v0.5.0
  [7806a523] DecisionTree v0.8.3
  [39dd38d3] Dierckx v0.4.1
  [31c24e10] Distributions v0.21.1
  [f6369f11] ForwardDiff v0.10.3
  [38e38edf] GLM v1.3.1
  [60bf3e95] GLPK v0.11.0
  [28b8d3ca] GR v0.41.0
  [c91e804a] Gadfly v1.0.1
  [09f84164] HypothesisTests v0.8.0
  [7073ff75] IJulia v1.19.0
  [b6b21f68] Ipopt v0.6.0
  [8c755ed3] JuML v0.0.0 [`C:\Users\Himanshi\.julia\dev\JuML`]
  [4076af6c] JuMP v0.18.6
  [e5e0dc1b] Juno v0.7.2
  [5ab0869b] KernelDensity v0.5.1
  [093fc24a] LightGraphs v1.3.0
  [2fda8390] LsqFit v0.8.1
  [33e6dc65] MKL v0.0.0 #master (https://github.com/JuliaComputing/MKL.jl)
  [cc2ba9b6] MLDataUtils v0.5.0
  [1914dd2f] MacroTools v0.5.1
  [b8f27783] MathOptInterface v0.9.1
  [2774e3e8] NLsolve v4.1.0
  [429524aa] Optim v0.19.2
  [9b87118b] PackageCompiler v0.6.4 #sd-notomls (https://github.com/JuliaLang/PackageCompiler.jl.git)
  [295af30f] Revise v2.1.8
  [3646fa90] ScikitLearn v0.5.1
  [90137ffa] StaticArrays v0.11.0
  [2913bbd2] StatsBase v0.32.0
  [f3b207a7] StatsPlots v0.11.0
  [70df011a] TableReader v0.4.0
  [c17dfb99] WinRPM v0.4.2
  [c2297ded] ZMQ v1.0.0
  [8ba89e20] Distributed
  [de0858da] Printf
  [9a3f8284] Random
  [2f01184e] SparseArrays
  [10745b16] Statistics

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 24, 2019, 3:16pm UTC](https://discourse.julialang.org/t/problem-with-optimisation-code/27936/3 "2019-08-24T15:16:46Z")

</div>

> [@Ajaychat3](#):
>
> with\_optimizer not defined

> [@JuMP - with\_optimizer method not working](https://discourse.julialang.org/t/jump-with-optimizer-method-not-working/17055/2):
>
> What is the original link to the example?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [August 24, 2019, 3:18pm UTC](https://discourse.julialang.org/t/problem-with-optimisation-code/27936/4 "2019-08-24T15:18:57Z")

</div>

Please see [JuMP v0.19.2 ⇒ v0.18.6 - #3 by odow](https://discourse.julialang.org/t/jump-v0-19-2-v0-18-6/27917/3).

This is an unfortunate result of `Pkg` choosing to downgrade JuMP in order to update GLPK. Run

```nohighlight
rm GLPK
up JuMP@0.19
add GLPK@0.10

```

It will be fixed by an upcoming release of JuMP.

---

<div class="post-metadata">

**Author:** ![Ajaychat3](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Post date:** [August 24, 2019, 3:57pm UTC](https://discourse.julialang.org/t/problem-with-optimisation-code/27936/5 "2019-08-24T15:57:12Z")

</div>

Thanks @odow and @jling

I removed GLPK but I was not able to upgrade JuMP to v0.19.2 using the ‘up’ command. I try a couple of time to add or upgrade JuMP v0.19, but it was still picking v0.18.6 somehow. So I removed JuMP and then cloned the JuMP package but then GLPK v0.10 was giving a getconstant error when running the same example. Afterwards I upgraded GLPK to v0.11 and it now it works.

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [August 24, 2019, 6:26pm UTC](https://discourse.julialang.org/t/problem-with-optimisation-code/27936/6 "2019-08-24T18:26:29Z")

</div>

Maybe another solver package (besides GLPK) was forcing the downgrade of JuMP, for similar reasons?
