# Using GLPKSolverLP

**URL:** <https://discourse.julialang.org/t/using-glpksolverlp/9575>\
**Category:** Optimization (Mathematical)\
**Created:** [March 7, 2018, 7:11pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575 "2018-03-07T19:11:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 7, 2018, 7:11pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/1 "2018-03-07T19:11:50Z")

</div>

How use the solver GLPKSolverLP ?

---

<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:** [March 7, 2018, 8:05pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/2 "2018-03-07T20:05:59Z")

</div>

```julia
using JuMP, GLPKMathProgInterface

m = Model(solver = GLPKSolverLP())
...
solve(m)

```

There is a README [https://github.com/JuliaOpt/GLPKMathProgInterface.jl](https://github.com/JuliaOpt/GLPKMathProgInterface.jl)

If you have integer variables, you will need to use `GLPKSolverMIP()`.

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [March 8, 2018, 5:55pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/4 "2018-03-08T17:55:39Z")

</div>

Could you give us the errors that you see ?

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 8, 2018, 7:08pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/6 "2018-03-08T19:08:29Z")

</div>

This is the error message

: **UndefVarError: GLPKSolverLP not defined**

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 8, 2018, 7:12pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/7 "2018-03-08T19:12:15Z")

</div>

using JuMP  
using GLPKMathProgInterface

myModel = Model(solver=GLPKSolverLP()) \*\*  
**UndefVarError: GLPKSolverLP not defined**

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [March 8, 2018, 7:27pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/8 "2018-03-08T19:27:47Z")

</div>

Just to be safe do `Pkg.update("JuMP"); Pkg.update("GLPKMathProgInterface")`. Then do `Pkg.status("GLPKMathProgInterface")` and make sure that it returns `0.4.0`. (The current package manager is extremely wonky, don’t worry, it is being replaced relatively soon.)

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 8, 2018, 7:48pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/10 "2018-03-08T19:48:53Z")

</div>

returned this error message for the update:  
METADATA cannot be updated. Resolve problems manually in C:\Users\raquel.santos\Documents\JuliaPro-0.6.2.1\pkgs-0.6.2.1\v0.6\METADATA.

And for the Pkg.status, returned this error message:

GitError(Code:ENOTFOUND, Class:Repository, Could not find repository from ‘DocStringExtensions’)

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [March 8, 2018, 8:11pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/11 "2018-03-08T20:11:39Z")

</div>

Ugh, yeah sounds like the package manager has gotten badly screwed up. Unfortunately it’s way to easy for that to happen right now, like I said, it will be fixed but it’s still a bit of a ways off.

Ok, I think you should do the following

```julia
Pkg.update() # may error
# at this point try `GLPKSolverLP()` one more time
# if it doesn't work, do the following:
Pkg.rm("GLPKMathProgInterface")
Pkg.rm("JuMP")
Pkg.update() # hopefully won't error now
Pkg.add("JuMP")
Pkg.add("GLPKMathProgInterface")

```

Hopefully this will clean up your package metadata.

Do you by any chance have uncommitted changes in your METADATA or other packages? If so, the package manager avoids wiping those, so you will have to manually get everything on a real commit.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 9, 2018, 1:56pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/12 "2018-03-09T13:56:38Z")

</div>

Now I saw that the Julia can’t find the file GLPK.ji. I’ve tryed to find this file manually but seems that it simply doesn’t exist. I’ve search in all the directories, but i had no success.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 9, 2018, 1:57pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/13 "2018-03-09T13:57:05Z")

</div>

Now I saw that the Julia can’t find the file GLPK.ji. I’ve tryed to find this file manually but seems that it simply doesn’t exist. I’ve search in all the directories, but i had no success.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 9, 2018, 1:59pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/14 "2018-03-09T13:59:35Z")

</div>

using JuMP  
using GLPKMathProgInterface

myModel = Model(solver=GLPKSolverLP()) **UndefVarError: GLPKSolverLP not defined** # the error  
#myModel = Model(solver=GLPKSolverMIP())  
solve(myModel)

#VARIABLES  
@defVar(myModel, x1 \>= 0)  
@defVar(myModel, x2 \>= 0)

#OBJECTIVE  
@setObjective(myModel, Max, 12x1 + 60x2)  
#CONSTRAINTS  
@addConstraint(myModel, 0.25x1 + 0.5x2 \<= 36)  
@addConstraint(myModel, 0.1x1 + 0.75x2 \<= 22)  
@addConstraint(myModel, 0.1x1 + 0.4x2 \<= 15)

#THE MODEL IN A HUMAN-READABLE FORMAT  
println(“The optimization problem to be solved is:”)  
print(myModel)

#SOLVE IT AND DISPLAY THE RESULTS  
status = solve(myModel) # solves the model  
println("Objective value: ", getObjectiveValue(myModel))  
println("x1 = ", getValue(x1))  
println("x2 = ", getValue(x2))

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [March 9, 2018, 2:57pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/15 "2018-03-09T14:57:25Z")

</div>

I’m very confused. It shouldn’t need to find any `*.ji` files, it should just recompile them. Have you made changes to the Julia directory structure? Assuming you are on 0.6, you should see `.julia/lib/v0.6` (this stores the `*.ji` binaries) and `.julia/v0.6` (stores source code). You can try deleting `lib` regardless, as Julia should just recompile anything that it doesn’t find there. Can you please post the explicit errors you are getting?

Also, your problem declaration doesn’t look right to me, see the [JuMP documentation](http://www.juliaopt.org/JuMP.jl/0.18/index.html). Also note that you can do pretty much anything in your variable and constraint macros that you’d be able to do in regular Julia code, so for example, your problem could be

```julia
A = [0.25 0.50;
     0.10 0.75;
     0.10 0.40]

b = [36, 22, 15]

c = [12, 60]

@variable(m, x[1:2] ≥ 0)

@objective(m, Max, c⋅x)

@constraint(m, A*x .≤ b)

```

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 9, 2018, 3:41pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/16 "2018-03-09T15:41:27Z")

</div>

Sorry, I could not explain with clarity the error that was happening, but through your help I was able to compile the model that I needed. Thanks

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 9, 2018, 3:43pm UTC](https://discourse.julialang.org/t/using-glpksolverlp/9575/17 "2018-03-09T15:43:17Z")

</div>

Sorry, I could not explain with clarity the error that was happening, but through your help I was able to compile the model that I needed. Thanks.
