PuLP + GLPK Questions

1,630 views
Skip to first unread message

Sumo

unread,
Apr 8, 2010, 3:04:08 PM4/8/10
to pulp-or-discuss
Hello, I am just getting started using PuLP with GLPK. I was wondering
though after installing PuLP one must include a "solver in the path"
according to the installation instructions. I am a little clueless as
to what is meant by this. Basically am I suppose to install GLPK
somewhere special to get it to work with to PuLP? Currently my sample
code runs without error, but none of the print solution statements at
the end are executed. The sample code is provided below.

Also, I was having some trouble doing this directly in GUSEK (a GLPK
IDE), but is there a way to set up Gap Tolerance? Meaning if the gap
reaches a certain percent, the solver immediate accepts the current
best solution and finishes running any remaining code? Or even better
I guess, having a way to accept the current best solution after a
certain time? I know there have been people who tried to do this in
GLPK, but instead of accepting the current best solution, GLPK simply
terminates the search and does not print or write that solution.

from pulp import *

prob = LpProblem("test1", LpMinimize)

# Variables
x = LpVariable("x", 0, 4)
y = LpVariable("y", -1, 1)
z = LpVariable("z", 0)

# Objective
prob += x + 4*y + 9*z

# Constraints
prob += x+y <= 5
prob += x+z >= 10
prob += -y+z == 7

GLPK().solve(prob)

# Solution
for v in prob.variables():
print v.name, "=", v.varValue

print "objective=", value(prob.objective)

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To post to this group, send email to pulp-or...@googlegroups.com.
To unsubscribe from this group, send email to pulp-or-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pulp-or-discuss?hl=en.

Stuart Mitchell

unread,
Apr 8, 2010, 5:28:52 PM4/8/10
to pulp-or...@googlegroups.com
See below
On Fri, 2010-04-09 at 07:04 +1200, Sumo wrote:
> Hello, I am just getting started using PuLP with GLPK. I was wondering
> though after installing PuLP one must include a "solver in the path"
> according to the installation instructions. I am a little clueless as
> to what is meant by this. Basically am I suppose to install GLPK
> somewhere special to get it to work with to PuLP? Currently my sample
> code runs without error, but none of the print solution statements at
> the end are executed. The sample code is provided below.
Does CoinMP work for you?
what are the results for
>>> import pulp
>>> pulp.pulpTestAll()

by installing GLPK on the path I meant that at the command line should
give the following output (I am assuming a linux system here windows may
look different). For windows just add the directory where the
glpksol.exe is to your path (or you can alter the pulp.cfg.win file)

$ glpsol
GLPSOL: GLPK LP/MIP Solver 4.38
No input problem file specified; try glpsol --help
>
> Also, I was having some trouble doing this directly in GUSEK (a GLPK
> IDE), but is there a way to set up Gap Tolerance? Meaning if the gap
> reaches a certain percent, the solver immediate accepts the current
> best solution and finishes running any remaining code? Or even better
> I guess, having a way to accept the current best solution after a
> certain time? I know there have been people who tried to do this in
> GLPK, but instead of accepting the current best solution, GLPK simply
> terminates the search and does not print or write that solution.
Hmm if this is a GLPK problem I'm not sure that I can help, apart from
recommending that you use cbc or coinMP from www.coin-or.org, which in
my opinion is a better solver.

The code below works for me.
but if you do not have GLPK installed properply I can see what your
problem is.

Stu

Sumo

unread,
Apr 9, 2010, 12:55:11 PM4/9/10
to pulp-or-discuss
I am actually using windows (sorry about that) and I guess if gap
tolerance or even time termination cannot be implemented glpk probably
isn't the solver I should use.
In any case, below is the results of the pulpTestAll.

Since I am limited to only using an open source programs in my project
I guess COIN would be the best solver then. However according to the
test, it seems that coinmp.dll is available yet COIN_CMD is not. Do I
need to have both to be available in this case to handle a MIP? And
also, how would you then implement a gap or time limit in coin?

I know some of these seem trivial and I apologize (I'm still pretty
novice at these kinds of stuff).

>>> pulp.pulpTestAll()
Solver pulp.solvers.CPLEX_DLL unavailable.
Solver pulp.solvers.CPLEX_CMD unavailable.
Solver pulp.solvers.COIN_CMD unavailable.
Testing continuous LP solution
Testing maximize continuous LP solution
Testing unbounded continuous LP solution
Error in CoinMP it reports Optimal
Testing MIP solution
Testing MIP relaxation
Testing feasibility problem (no objective)
Testing an infeasible problem
Testing an integer infeasible problem
Error in CoinMP to be fixed, reports Optimal
Testing column based modelling
Testing column based modelling with empty constraints
Testing dual variables and slacks reporting
Testing resolve of problem
Testing Sequential Solves
Testing fractional constraints
Testing elastic constraints (no change)
Testing elastic constraints (freebound)
Testing elastic constraints (penalty unchanged)
Testing elastic constraints (penalty unbounded)
* Solver pulp.solvers.COINMP_DLL passed.
Solver pulp.solvers.GLPK_CMD unavailable.
Solver pulp.solvers.XPRESS unavailable.
Solver pulp.solvers.GUROBI unavailable.

On Apr 8, 5:28 pm, Stuart Mitchell <s.mitch...@auckland.ac.nz> wrote:

> recommending that you use cbc or coinMP fromwww.coin-or.org, which in

Stuart Mitchell

unread,
Apr 10, 2010, 5:19:54 AM4/10/10
to pulp-or...@googlegroups.com
See below

On Sat, 2010-04-10 at 04:55 +1200, Sumo wrote:
> I am actually using windows (sorry about that) and I guess if gap
> tolerance or even time termination cannot be implemented glpk probably
> isn't the solver I should use.
Windows is fine most people seem to use it :-)


> In any case, below is the results of the pulpTestAll.
>
> Since I am limited to only using an open source programs in my project
> I guess COIN would be the best solver then. However according to the
> test, it seems that coinmp.dll is available yet COIN_CMD is not. Do I
> need to have both to be available in this case to handle a MIP? And
> also, how would you then implement a gap or time limit in coin?

Yes I need to update the documentation for these options and probably
standardise them for each solver.
But I have just added the following documentation for the COINMP_DLL
solver

"""
The COIN_MP LP MIP solver (via a DLL or linux so)

:param timeLimit: The number of seconds before forcing the solver to
exit
:param epgap: The fractional mip tolerance
"""

use
>>> prob.solve(COINMP_DLL(timeLimit = 500, epgap = 0.10)
for a 500sec timelimit and a epgap of 10%

Vinaka
Stu

Reply all
Reply to author
Forward
0 new messages