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.

This entry was posted in Conference, Project, Puzzle, Python. Bookmark the permalink.

5 Responses to Python module for Constraint Solving Problems

  1. Anonymous says:

    Python hackers, lpsolve5 and glpk4.8 need python bindings.

    http://groups.yahoo.com/group/lp_solve/
    http://www.gnu.org/software/glpk/glpk.html

    Use for forestry, ecology, agricultural, mining, manufacturing, etc. management.

    Very useful for developing countries in doing properly time and space management especially in land-based management and natural resources.

  2. Anonymous says:

    Qgis needs you –python hackers!!!

    python is one of solutions for non-programmers to create useful and meaning plugin for qgis. Right now qgis plugins is only c++. No python yet in qgis.

    So python hackers willing to help. Have a look and join.

    http://community.qgis.org/
    http://mrcc.com/logs/

  3. PyCon seems to be very interesting and well done. With it I wrote in 30 minutes a sudoku solver.

    Grates work!!!

  4. That’s indeed a short solver for sudoku. :-)

    I hope you don’t mind if I include that in the examples directory (with credits, of course).

  5. It will be a pleasure for me!

Leave a Reply

Your email address will not be published. Required fields are marked *