# The error of using GLPKMathProgInterface pkg

**URL:** <https://discourse.julialang.org/t/the-error-of-using-glpkmathproginterface-pkg/34142>\
**Category:** Optimization (Mathematical)\
**Created:** [February 4, 2020, 3:11am UTC](https://discourse.julialang.org/t/the-error-of-using-glpkmathproginterface-pkg/34142 "2020-02-04T03:11:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahsap58](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mahsap58/32/11370_2.png) [@mahsap58](https://discourse.julialang.org/u/mahsap58)\
**Post date:** [February 4, 2020, 3:11am UTC](https://discourse.julialang.org/t/the-error-of-using-glpkmathproginterface-pkg/34142/1 "2020-02-04T03:11:33Z")

</div>

i have faced to this error in using GLPKMathProgInterface pkg please help me to fix that.  
Failed to precompile GLPK [60bf3e95-4087-53dc-ae20-288a0d20c6a6]

---

<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:** [February 4, 2020, 4:03am UTC](https://discourse.julialang.org/t/the-error-of-using-glpkmathproginterface-pkg/34142/2 "2020-02-04T04:03:45Z")

</div>

Hi there!

Step 1: read [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757). In particular, please post what you have tried and the full print-out of the error.

Step 2: You should use `GLPK` instead of `GLPKMathProgInterface` (GLPKMathProgInterface was for an old release with JuMP). To use GLPK with JuMP 0.20, use:

```nohighlight
import Pkg
Pkg.add("GLPK")
using JuMP
using GLPK
model = Model(with_optimizer(GLPK.Optimizer))

```

---

<div class="post-metadata">

**Author:** ![mahsap58](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mahsap58/32/11370_2.png) [@mahsap58](https://discourse.julialang.org/u/mahsap58)\
**Post date:** [February 5, 2020, 8:46pm UTC](https://discourse.julialang.org/t/the-error-of-using-glpkmathproginterface-pkg/34142/3 "2020-02-05T20:46:38Z")

</div>

I use this pkg (GLPKMathProgInterface) to get dual variables of master problem in column generation method. I send my codes for you. I did the way you suggested, but I faced the same error. (Failed to precompile GLPK [60bf3e95-4087-53dc-ae20-288a0d20c6a6])  
using JuMP  
using GLPKMathProgInterface  
W=100  
cardinalityM=5  
M=[1:cardinalityM]  
A=eye(cardinalityM)  
p=zeros(5)  
w=[11; 15; 19; 23; 27]  
b=[97; 140; 191; 85; 129]  
@time begin # time measurement begins  
cutstockMain = Model() # Model for the master problem  
Jprime=[1:size(A,2)] # Intial number of variables  
@defVar(cutstockMain, 0 \<= x[Jprime] \<= 1000000) # Defining the variables  
@setObjective(cutstockMain, Min, sum{1\*x[j],j in Jprime}) # Setting the objective  
@addConstraint(cutstockMain, consRef[i=1:cardinalityM], sum{A[i,j]\*x[j], j in Jprime}==b[i])  
solve(cutstockMain)  
getDual(consRef)  
for i in M  
p[i] = getDual(consRef)[i]  
end  
cutstockSub=Model() # Model for the subproblem  
@defVar(cutstockSub, 0 \<= Ajstar[M] \<= 1000000, Int )  
@setObjective(cutstockSub, Min, 1-sum{p[i]\*Ajstar[i],i in M})  
@addConstraint(cutstockSub, sum{w[i]\*Ajstar[i], i in M} \<= W)  
solve(cutstockSub)  
minReducedCost=getObjectiveValue(cutstockSub)  
Anew=Float64  
for (i in 1:cardinalityM)  
push!(Anew, getValue(Ajstar)[i])  
end  
xNewArray=Variable  
k=1  
while (minReducedCost \< 0)  
@defVar(cutstockMain, 0 \<= xNew \<= 1000000, objective=1, inconstraints=consRef, coefficients=Anew)  
push!(xNewArray, xNew)  
setName(xNew, string(“x[”,size(A,2)+k,“]”))  
k=k+1  
statusControlFlow=solve(cutstockMain)  
getDual(consRef)  
for i in M  
p[i] = getDual(consRef)[i]  
end  
@defVar(cutstockSub, 0 \<= Ajstar[M] \<= 1000000, Int )  
@setObjective(cutstockSub, Min, 1-sum{p[i]\*Ajstar[i],i in M})  
@addConstraint(cutstockSub, sum{w[i]\*Ajstar[i], i in M} \<= W)  
solve(cutstockSub)  
minReducedCost=getObjectiveValue(cutstockSub)  
Anew=Float64  
for (i in 1:cardinalityM)  
push!(Anew, getValue(Ajstar)[i])  
end  
end

```
end
println("Objective value: ", getObjectiveValue(cutstockMain))
println("Current Solution is: ", getValue(x))
println("With ", length(xNewArray), " variables added by flow control:")
for i in 1:length(xNewArray)
    println("[",size(A,2)+i,"] = ",getValue(xNewArray[i]))
end
println("Reduced cost of the current solution is ", getObjectiveValue(cutstockSub))

```

---

<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:** [February 5, 2020, 10:21pm UTC](https://discourse.julialang.org/t/the-error-of-using-glpkmathproginterface-pkg/34142/4 "2020-02-05T22:21:36Z")

</div>

A few things:

1. You’re using a very old version of JuMP.

- You should consult the documentation: [Introduction · JuMP](https://www.juliaopt.org/JuMP.jl/stable/)
- There are also lots of examples: [JuMP.jl/examples at v0.20.1 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/tree/v0.20.1/examples).
- I recommend you start with the [Quickstart Guide](https://www.juliaopt.org/JuMP.jl/stable/quickstart/), which shows how to use GLPK.

1. Take another read of the [PSA](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757).

- In particular, point 1 describes how to format your code.
- Point 4 is also important: simplify your code as much as possible. Try to reduce it to the minimum amount of code necessary to reproduce the error.
