Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97842

Re: How to rearrange array using Python?

Path csiph.com!news.mixmin.net!news.albasani.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.036
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'subject:Python': 0.05; 'subject:How': 0.09; 'collections': 0.09; 'subject:using': 0.09; 'assume': 0.11; 'def': 0.13; 'skip:p 40': 0.15; 'variables': 0.15; '12:57': 0.16; 'hint?': 0.16; 'solver': 0.16; 'subject:array': 0.16; 'wrote:': 0.16; '2015': 0.20; 'martin': 0.22; 'this:': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'room': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'finds': 0.29; 'anyone': 0.32; 'tue,': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'solving': 0.35; 'something': 0.35; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'to:addr:python.org': 0.40; 'still': 0.40; 'easy': 0.60; 'your': 0.60; 'more': 0.63; '20,': 0.66; 'offer': 0.66; 'individuals': 0.73; 'csp': 0.84; 'fulfilled.': 0.84; 'room.': 0.84; 'rooms': 0.84; 'to:name:python': 0.84; 'room,': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=0+LaRERWd51Co/eAq3ooJFTURgFGHmZG0hgSFN/bzMM=; b=lQZAn3aANDbYYlIkAaUnAP5nqhoyjksoJ4ppDwgY/Koo2pn4xkd1msFh9IOJHB+Nkh bl9hgeIK2xiFU1bJOXJ0QSazjU4+r+3bJYFP5Xktl0Jg0FBG2aG8uwn42gl23j1v+7PW MpeXlJ2T1R3C26/9pM3hilVhP1SA3JXFt9DU/uyyPp18epD9xgQfRDO8hp14DLf9AjeZ O8vxG5o8GbuA8IAmS5/q9xn/vOG6wrhgtEuZUTQbwsJYDVQcgs6jmyUIOfqHHjxaT7mY DB9WeU133zY/1lxBWKqcDXNubaYHdLnRiYRIYG6M5TyTbh4hp5gPWhbc/hpSvk58ywAK jFwQ==
X-Received by 10.107.14.196 with SMTP id 187mr6757502ioo.11.1445369210889; Tue, 20 Oct 2015 12:26:50 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <d8nh3vFg8bvU1@mid.individual.net>
References <d1vftgF65svU1@mid.individual.net> <mailman.1100.1438294883.3674.python-list@python.org> <1468455.P0rGZF1LBf@PointedEars.de> <d224qaFr1aeU1@mid.individual.net> <d3f15cF6mctU1@mid.individual.net> <d8nh3vFg8bvU1@mid.individual.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 20 Oct 2015 13:26:11 -0600
Subject Re: How to rearrange array using Python?
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.60.1445369216.878.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1445369216 news.xs4all.nl 23725 [2001:888:2000:d::a6]:49412
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:97842

Show key headers only | View raw


On Tue, Oct 20, 2015 at 12:57 PM, Martin Schöön <martin.schoon@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?

I assume that your variables are the individuals and the domains of
those variables are the rooms. Based on the python-constraint docs,
your constraint could look something like this:

from collections import Counter

ROOM_SIZE = {
    'A': 3,
    'B': 3,
    'C': 4,
    'D': 4,
    'E': 5,
}

def room_size_constraint(*v):
    counter = Counter(v.values())
    return all(count <= ROOM_SIZE[room]
            for room, count in counter.items())

problem.addConstraint(room_size_constraint)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to rearrange array using Python? Martin Schöön <martin.schoon@gmail.com> - 2015-07-30 20:31 +0000
  Re: How to rearrange array using Python? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-30 23:21 +0100
    Re: How to rearrange array using Python? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-31 04:29 +0200
      Re: How to rearrange array using Python? Martin Schöön <martin.schoon@gmail.com> - 2015-07-31 20:40 +0000
        Re: How to rearrange array using Python? Martin Schöön <martin.schoon@gmail.com> - 2015-08-17 21:14 +0000
          Re: How to rearrange array using Python? Martin Schöön <martin.schoon@gmail.com> - 2015-10-20 18:57 +0000
            Re: How to rearrange array using Python? Ian Kelly <ian.g.kelly@gmail.com> - 2015-10-20 13:26 -0600
              Re: How to rearrange array using Python? Martin Schöön <martin.schoon@gmail.com> - 2015-10-21 18:47 +0000
            Re: How to rearrange array using Python? Ian Kelly <ian.g.kelly@gmail.com> - 2015-10-20 13:28 -0600
  Re: How to rearrange array using Python? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-30 23:41 +0100
  Re: How to rearrange array using Python? Robin Koch <robin.koch@t-online.de> - 2015-07-31 03:18 +0200
    Re: How to rearrange array using Python? Martin Schöön <martin.schoon@gmail.com> - 2015-07-31 20:53 +0000

csiph-web