Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97869
| From | Martin Schöön <martin.schoon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How to rearrange array using Python? |
| Date | 2015-10-21 18:47 +0000 |
| Organization | @ Home |
| Message-ID | <d8q4trF6285U1@mid.individual.net> (permalink) |
| References | (2 earlier) <1468455.P0rGZF1LBf@PointedEars.de> <d224qaFr1aeU1@mid.individual.net> <d3f15cF6mctU1@mid.individual.net> <d8nh3vFg8bvU1@mid.individual.net> <mailman.60.1445369216.878.python-list@python.org> |
Den 2015-10-20 skrev Ian Kelly <ian.g.kelly@gmail.com>:
>>
>> 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)
Bingo!
Just what I needed but didn't know where to look for. Now I 'only' have
to read
https://docs.python.org/dev/library/collections.html#counter-objects
to understand what's really going on in the code :-)
Then I will try less benign examples.
/Martin
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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