Am 21.03.2014 16:42, schrieb jbiskofski:
I have 6 elevators, and 50 people. These people weigh between 120 and
350lbs.
How can I find the optimal way of distributing these people into the 6
elevators so that each elevator carries approximately the same weight ?
Hopefully the proposed solutions are "use XYZ::FOO::BAR module from
cpan" rather than 60 lines of crazy algorithm perl code :)
Indeed there is a CPAN module
https://metacpan.org/pod/Algorithm::Bucketizer
that does what you want,
the following snippet works decent for me.
#!/usr/bin/perl
use strict;
use warnings;
use Algorithm::Bucketizer;
my $bucketizer = Algorithm::Bucketizer->new(bucketsize => 1200);
# or whatever any of your cabine can transport
$bucketizer->add_bucket() for 1..6;
$bucketizer->add_item(120+3.5*$_ => 120+3.5*$_) for 1..60;
# here I just assume an easy uniform distribution of weights,
# of course here you'd have to fit your real weights in case
$bucketizer->optimize(algorith => 'random', maxtime => 10);
foreach my $bucket ($bucketizer->buckets()) {
print join("+",$bucket->items()), "=",$bucket->level(),"\n";
}
I used the random method for optimizing as your problem will always fail
when working with enough items/buckets as it as NP-hard as someone else
already suggested.
Greetings,
Janek
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/