How to rearrange array using Python?

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Oct 20 17:27:14 EDT 2015


On Tue, 20 Oct 2015 20:01 Martin Schöön <martin.schoon at gmail.com> wrote:

It has been a while.
I have mastered solving Kenken and Sudoku using Python-constraint.

I still have no clue on how to tell the solver how to constrain
the number of occupants in rooms: I have made up an simple example
with nine persons and three rooms. Wishes for room mates are
mild in the extreme so it is very easy for a human to place these
nine persons in the three three-bed rooms such that all wishes are
fulfilled. Python-constraint set up by me finds 27 solutions of
which most place more than three persons in at least one room.

Anyone into CSP willing to offer me a hint?



How have you defined your constraints? How have you defined the variables
you want to solve for?

Do you know whether or not the real problem you want to solve typically has
any solutions satisfying all constraints? It won't be possible to answer
that question a priori without looking at the data and the approach to take
differs substantially if the system is overdetermined.

Another approach BTW would be to model the wishes as a directed graph with
children as vertices and wishes as arcs. This way you can partition the
graph into weakly connected components so that your problem is reduced to
placing components into rooms rather than individuals.

--
Oscar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20151020/c8aebcdd/attachment.html>


More information about the Python-list mailing list