help-glpk
[Top][All Lists]

## RE: [Help-glpk] PuLP: A Python interface for GLPK

 From: Sebastien . deMentendeHorne Subject: RE: [Help-glpk] PuLP: A Python interface for GLPK Date: Tue, 13 Apr 2004 11:24:35 +0200

```Great tool js!

By the way, could you include a construct for constraints (and maybe
variable) like:

"prob +=  3*x + 5*y in (4,10)"
i.e. the in keyword via overwrite of the __contains__ method
to mean
"prob += 4 <= 3*x + 5*y <= 10"
as the expression "a <= x <= b" translated as "(a <= x) and (x <= b)" is
useless in this context.

Is it possible to modify afterward the value of the coefficient in the
constraint matrix or the objective or the bounds ?
That will boost PuLP usefullness tremendously !

thanks
seb

-----Original Message-----
Sent: zaterdag 10 april 2004 17:37
Subject: [Help-glpk] PuLP: A Python interface for GLPK

I'm currrently trying to complete the second version of a free Python
linear modeler which can use GLPK (among other solvers like COIN, CPLEX or
XPRESS) to perform the optimization.

PuLP provides a nice syntax for the creation of linear problems, and a
simple way to call the solvers to perform the optimization. See the
example below.

The software can write LP files and call the various solvers binaries
(like glpsol) but it's more efficient and more reliable to use the
included C modules and avoid writting files.

Distribution of the sources only is not a problem under Unix where a
compiler is almost always available, but is a problem under Windows, so I
would like to provide compiled modules for this platform. The problem is,
I do not have access to a computer running Windows (much less Visual C++).
Would someone be interested in compiling and testing these modules (at
least for GLPK and COIN) ?

I've attached the latest 1.1 beta version which include all the sources.

Thank you very much in advance,

King regards,

js

Example script:

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

prob.solve(GLPK())

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

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

```