[Numpy-discussion] Linear programming

Paulo J. S. Silva pjssilva at ime.usp.br
Tue Mar 29 18:45:31 EST 2005

Em Ter, 2005-03-29 às 17:19 +0200, Magnus Lie Hetland escreveu:
> Is there some standard Python (i.e., numarray/Numeric) mapping for
> some linear programming package out there? Might be rather useful...


I have written a very simple wrapper to COIN/CLP (www.coin-or.org) based
on swig. I am using this code in my own research. It is simple, but it
is good enough for me.

I will clean it up a little and "release" it this week. Please enter in
contact by Friday with me.

Here is a sample code using the wrapper:

--- Sample code ---

from numarray import *
import Coin

s = Coin.OsiSolver()

# Define objective and variables bounds
ncols = 2
obj = array([-1.0, -1.0])
col_lb = array([0.0, 0.0])
col_ub = s.getInfinity()*array([1.0, 1.0])

# Define constraints
nrows = 2
row_lb = -s.getInfinity()*array([1.0, 1.0])
row_ub = array([3.0, 3.0])
matrix = Coin.CoinPackedMatrix(0, 0, 0)
matrix.setDimensions(0, ncols)
row1 = Coin.CoinPackedVector()
row1.insert(0, 1.0)
row1.insert(1, 2.0)
row2 = Coin.CoinPackedVector()
row2.insert(0, 2.0)
row2.insert(1, 1.0)

# Load Problem
s.loadProblem(matrix, col_lb, col_ub, obj, row_lb, row_ub)

# Write mps model.

# Solve problem

# Print optimal value.
print 'Optimal value: ', s.getObjValue()

print 'Solution: ', s.getColSolution()

--- End sample ---

Note that I am using the COIN's sparce matrix and vector so as to use
sparcity in the CLP solver.



Paulo José da Silva e Silva
Professor Assistente do Dep. de Ciência da Computação
(Assistant Professor of the Computer Science Dept.)
Universidade de São Paulo - Brazil

e-mail: pjssilva at ime.usp.br       Web: http://www.ime.usp.br/~pjssilva
Teoria é o que não entendemos o   (Theory is something we don't)
suficiente para chamar de prática.(understand well enough to call

More information about the NumPy-Discussion mailing list