Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Partitioning a set into parts of given sizes

by Limbic~Region (Chancellor)
on Nov 21, 2006 at 14:49 UTC ( #585272=note: print w/replies, xml ) Need Help??


in reply to Partitioning a set into parts of given sizes

blokhead,
I recently used your code because Set::Partition seems to be misnamed. According to Wikipedia, there is a difference between Set Partitioning and Ordered Set Partitioning. The latter distinguishing between the order the sets appear. It should probably be named Set::Partition::Ordered.

In any case, I have a few comments. First, why do you require that the block sizes add up to the total number of items? I had to work around this restriction by generating the combinations of a fixed size and then using your code to partition the combinations. It would be nice if that restriction were @sum @block_size <= @items.

The second comment is about availability on CPAN. I think this is something that might be of great value to others. I had intended to simplify my code but would love to make this a collaborative effort. Your thoughts?

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Partitioning a set into parts of given sizes
by blokhead (Monsignor) on Nov 21, 2006 at 15:07 UTC
    First, why do you require that the block sizes add up to the total number of items?
    Otherwise what you get is not a partition according to most definitions. You can somewhat get around this by partitioning into groups and letting one group be a "trash" group that is not output. But for that you must have one distinguished group (as in ordered partition) and the rest undifferentiated (as in unordered partition), so it would be trickier.

    Now that I'm thinking about it a little more, though, it may be possible to adadpt how it generates RG-sequences internally to support just that by allowing the value "0" to signify "not included in output," where every item (including the first) can take on value 0. I wouldn't be able to code it up for a while, but it seems do-able.

    blokhead

      blokhead,
      I looked at the problem a bit differently. I have a group of N items that I need to group into sets of a smaller size and then partition each set. I think this is a useful enough feature to include it - I am just not sure they way I implemented it is optimal. What are your thoughts on collaborating on CPAN module(s)?

      Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://585272]
help
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-09-28 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (124 votes). Check out past polls.

    Notices?