Monthly Archive for July, 2005

Python module for Constraint Solving Problems

The constraint module presented in PyCon Brasil and later on EuroPython 2005 is now available. Here is a trivial example, solving the classical rooks problem:

problem = Problem()
numpieces = 8
cols = range(numpieces)
rows = range(numpieces)
problem.addVariables(cols, rows)
for col1 in cols:
    for col2 in cols:
        if col1 < col2:
            problem.addConstraint(lambda row1, row2: row1 != row2,
                                  (col1, col2))
solutions = problem.getSolutions()

Have fun!

Update: It was also presented in FISL 2006.