Hi Malcolm,
I would consider something like the following (pseudocode):
from random import shuffle
buckets = []
bucket_count = 3
class Bucket:
tot_qty = 0
items = []
for i in range(bucket_count):
buckets.append(Bucket())
# Sort the input_table by qty descending.
# Append each item to the bucket that currently has the lowest
# total quantity.
for record in input_table:
min_bucket = None
for bucket in buckets:
if min_bucket is None or bucket.tot_qty < min_bucket.tot_qty:
min_bucket = bucket
min_bucket.append(record)
min_bucket.tot_qty += record.qty
# We now have each bucket as balanced as possible. Now, randomize
# each bucket (if this is a true requirement):
for bucket in buckets:
shuffle(bucket.items)
On 6/13/14, 10:45 AM, Malcolm Greene wrote:
Matt,
Good questions. I don't care how many records are in each bucket as long
as the sum total of all quantity fields in each bucket are balanced as
much as possible.
Taking the extreme case, if I had 999,999 records with a quantity value
of 1, one record with a quantity value of 1,000,000 and two buckets, I
would put the 999,999 records in one bucket and the single value of 1
million in another bucket and consider the buckets as evenly balanced as
possible (999,999 vs. 1,000,000).
In other words, the basis for what I consider balanced is the total sum
of each bucket's quantity values vs. the number of records in each
bucket.
Malcolm
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.