Algorithm-Knapsack

 view release on metacpan or  search on metacpan

lib/Algorithm/Knapsack.pm  view on Meta::CPAN


sub new {
    my $class = shift;
    my $self = {
        capacity    => 0,       # total capacity of this knapsack
        weights     => [],      # weights to be packed into the knapsack
        @_,
        solutions   => [],      # lol of indexes to weights
        emptiness   => 0,       # capacity minus sum of weights in a solution
    };
    bless $self, $class;
}

=item B<compute>

    $knapsack->compute();

Iterates over all possible combinations of weights to solve the knapsack
problem. Note that the time to solve the problem grows exponentially with
respect to the number of items (weights) to choose from.



( run in 0.304 second using v1.01-cache-2.11-cpan-de7293f3b23 )