PuLP requires Python >= 2.5. Or with some extra requirements Python2.4 can work.
PuLP uses bzr and launchpad for development and is found on https://launchpad.net/pulp-or
Pulp can be downloaded from the CheeseShop
The examples require at least a solver in your PATH or a shared library file. CoinMP is bundled with the CheeseShop install.
Install pulp by following the instructions on http://www.coin-or.org/PuLP/ or use easy_install as follows
$ easy_install -U pulp
PuLP uses bzr and launchpad for version control to get the latest version of PuLP
$ bzr branch lp:pulp-or pulp-or
Coin-or hosts the svn archive for PuLP so to download from coin
$ svn co https://projects.coin-or.org/svn/PuLP/stable/x.y pulp
where the stable version x.y is the latest version (currently 1.4)
In python when PuLP has been installed
>>> import pulp
Use pulp.LpVariable() to create new variables. To create a variable 0 <= x <= 3
>>> x = pulp.LpVariable("x", 0, 3)
To create a variable 0 <= y <= 1
>>> y = pulp.LpVariable("y", 0, 1)
Use pulp.LpProblem() to create new problems. Create "myProblem"
>>> prob = pulp.LpProblem("myProblem", pulp.LpMinimize)
Combine variables to create expressions and constraints and add them to the problem.
>>> prob += x + y <= 2
If you add an expression (not a constraint), it will become the objective.
>>> prob += -4*x + y
Solve a problem
>>> status = prob.solve()
Or choose a solver and solve the problem.
>>> status = prob.solve(GLPK(msg = 0))
Display the status of the solution
>>> pulp.LpStatus[status] 'Optimal'
You can get the value of the variables using value(). ex:
>>> pulp.value(x) 2.0
- LpProblem -- Container class for a Linear programming problem
- LpVariable -- Variables that are added to constraints in the LP
- LpConstraint -- A constraint of the general form a1x1+a2x2 ...anxn (<=, =, >=) b
- LpConstraintVar -- Used to construct a column of the model in column-wise modelling
- value() -- Finds the value of a variable or expression
- lpSum() -- given a list of the form [a1*x1, a2x2, ..., anxn] will construct a linear expression to be used as a constraint or variable
- lpDot() --given two lists of the form [a1, a2, ..., an] and [ x1, x2, ..., xn] will construct a linear epression to be used as a constraint or variable