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


Groups > comp.lang.python > #94792

Re: How to rearrange array using Python?

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.041
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'url:pypi': 0.03; 'subject:Python': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'that?': 0.05; 'lately': 0.07; 'linear': 0.07; 'squares': 0.07; 'subject:How': 0.09; 'any.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:using': 0.09; 'worse': 0.09; 'python': 0.10; '35+': 0.16; 'apreciate': 0.16; 'camp': 0.16; 'guidance.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:array': 0.16; 'younger': 0.16; 'wrote:': 0.16; 'later': 0.16; 'numerical': 0.18; 'language': 0.19; 'martin': 0.22; 'disclaimer': 0.22; 'lawrence': 0.22; 'programming': 0.22; 'code.': 0.23; 'leave': 0.23; 'header :In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'room': 0.27; 'least': 0.27; 'silicon': 0.29; 'sleep': 0.29; 'url:picasaweb': 0.29; 'url:wikipedia': 0.29; 'ago': 0.29; 'array': 0.29; 'random': 0.29; "i'm": 0.30; 'url:wiki': 0.30; 'initially': 0.30; 'certain': 0.31; 'language.': 0.32; 'point': 0.33; 'problem': 0.33; 'url:python': 0.33; 'running': 0.34; 'could': 0.35; 'done': 0.35; 'happened': 0.35; 'something': 0.35; 'according': 0.36; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'possible': 0.36; 'to:addr :python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'whom': 0.37; 'starting': 0.37; 'doing': 0.38; 'busy': 0.38; 'summer': 0.38; 'wrong': 0.38; 'several': 0.38; 'url:en': 0.39; 'along': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'called': 0.40; 'some': 0.40; 'share': 0.61; 'skip:u 10': 0.61; 'show': 0.62; 'real': 0.62; 'further': 0.62; 'total': 0.62; 'back': 0.62; 'charset:windows-1252': 0.62; 'more': 0.63; 'information': 0.63; 'our': 0.64; 'goal': 0.64; 'soon': 0.65; 'differences': 0.66; 'picked': 0.66; 'youth': 0.66; 'here': 0.66; 'note:': 0.66; 'life': 0.67; 'internet': 0.70; 'picture': 0.70; 'wish': 0.71; 'satisfaction': 0.72; 'individuals': 0.73; 'visiting': 0.73; 'training': 0.78; 'friends': 0.82; 'evening': 0.84; 'evenings': 0.84; 'fulfilled.': 0.84; 'kids.': 0.84; 'maximize': 0.84; 'pythonistas,': 0.84; 'rooms': 0.84; 'score.': 0.84; 'absolutely': 0.88; 'played': 0.91; 'scores': 0.91; 'stretch': 0.91; 'grey': 0.93; 'room,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: How to rearrange array using Python?
Date Thu, 30 Jul 2015 23:21:03 +0100
References <d1vftgF65svU1@mid.individual.net>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host host-78-147-187-35.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0
In-Reply-To <d1vftgF65svU1@mid.individual.net>
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.1100.1438294883.3674.python-list@python.org> (permalink)
Lines 69
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1438294883 news.xs4all.nl 2867 [2001:888:2000:d::a6]:47678
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:94792

Show key headers only | View raw


On 30/07/2015 21:31, Martin Schöön wrote:
> Here is a problem I think I should be able to solve using Python but
> after having searched the internet for the better part of this
> evening my head spins and I would apreciate some guidance.
>
> Disclaimer
>
> My formal programming training happened 35+ years ago and
> initially involved F77 and later Pascal. Python is something
> I have picked up lately and for fun. I don't master Python by any
> stretch of imagination. I know some linear algebra and numerical
> methods but don't practice any of this on a daily basis...
>
> Problem background
>
> I am just back from visiting my sisters and the younger of them
> was busy planning a youth orchestra summer camp. For some reason
> the kids are allowed to wish with whom they want to share rooms
> and my sister spent several evenings placing kids in rooms
> according to these wishes. It struck me that at least some of this
> work could be done by silicon running code.
>
> My thinking so far
>
> I have played around a little with something called DSM
> https://en.wikipedia.org/wiki/Design_structure_matrix
> at work and think entering all wishes into a 2D array
> for further processing and overview should be a good idea.
>
> An added piece of information is the number of and sizes
> of rooms. I want to overlay this on the array and re-shuffle
> until as many of the wishes as possible are fulfilled.
>
> Here is a picture that may help understanding what I am after:
> https://picasaweb.google.com/103341501341482571816/Miscellaneous#6177389865951753330
> In this example I have 25 individuals (each allowed two wishes),
> one 5-bed room, two 4-bed rooms and four 3-bed rooms.
> Wishes are marked by "1" so a wants to sleep in the same room
> as i and n etc. The rooms are shown as light grey squares
> along the diagonal. Scores to the right show how many wishes
> are fulfilled in each room and at the bottom right corner I
> have the total score. The goal is to re-shuffle the array
> to maximize this score.
>
> How do I go about doing that?
>
> Note: This example is worse than the real life problem as
> most kids go to this camp with friends and wishes are
> highly coordinated. I used a random number generator to
> create wishes... The real problem involves some 80 kids.
> There are some more differences but let us leave them out
> for now.
>
> TIA
>
> /Martin
>

I'm not absolutely certain but I think you're into what's known as a 
constraint satisfaction problem, in which case this 
https://pypi.python.org/pypi/python-constraint/1.2 is as good a starting 
point as any.  If I'm wrong we'll soon get told :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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? 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