Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.2 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    Algorithm::BinPack 0.5

    Download button

    No screenshots available
    Downloads: 422  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Carey Tilden | More programs
    Perl Artistic License / FREE
    May 16th, 2007, 20:05 GMT [view history]
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    Algorithm::BinPack description

    A Perl module that can efficiently pack items into bins.

    Algorithm::BinPack is a Perl module that can efficiently pack items into bins.

    SYNOPSIS

    Algorithm::BinPack efficiently packs items into bins. The bins are given a maximum size, and items are packed in with as little empty space as possible. An example use would be backing up files to CD, while minimizing the number of discs required.

    my $bp = Algorithm::BinPack->new(binsize => 4);

    $bp->add_item(label => "one", size => 1);
    $bp->add_item(label => "two", size => 2);
    $bp->add_item(label => "three", size => 3);
    $bp->add_item(label => "four", size => 4);

    for ($bp->pack_bins) {
    print "Bin size: ", $_->{size}, "n";
    print " Item: ", $_->{label}, "n" for @{ $_->{items} };
    }


    METHODS

    new

    Creates a new Algorithm::BinPack object. The maximum bin size is specified as a named argument 'binsize', and is required. A fudge factor may be specified as a named argument 'fudge'. If a fudge factor is specified, item sizes will be rounded up to a number divisible by the fudge factor. This can help keep items with similar sizes in order by their labels.

    my $bp = Algorithm::BinPack->new(binsize => 4);
    my $bp = Algorithm::BinPack->new(binsize => 100, fudge => 10);

    add_item

    Adds an item to be packed into a bin. Required named arguments are 'label' and 'size', but any others can be specified, and will be saved. An optional 'bin' argument can be used to manually put an item into the specified bin.

    $bp->add_item(label => 'one', size => 1);
    $bp->add_item(label => 'two', size => 2, desc => 'The second numeral');
    $bp->add_item(label => 'zero', size => 3, bin => 0);
    $bp->add_item(qw(label three size 3));
    $bp->add_item(qw(label four size 4 random key));


    prefill_bin

    (Deprecated method) add_item now knows how to handle the 'bin' argument directly, so this method is redundant.

    pack_bins

    Packs the items into bins. This method tries to leave as little empty space in each bin as possible. It returns a list of hashrefs with the key 'size' containing the total bin size, and 'items' containing an arrayref holding the items in the bin. Each item is in turn a hashref containing the keys 'label', 'size', and any others added to the item. If a fudge factor was used, each item will contain a key 'fudgesize', which is the size this item was fudged to.

    for my $bin ($bp->pack_bins) {
    print "Bin size: ", $bin->{size}, "n";

    for my $item (@{ $bin->{items} }) {
    printf " %-6s %-20sn", $_, $item->{$_} for keys %{ $item };
    print " ---n";
    }
    }


    Product's homepage

    Requirements:

    · Perl

    What's New in This Release: [ read full changelog ]

    · add_item can handle specified bin number
    · deprecated prefill_bin

      


    TAGS:

    pack items | bin creator | Perl module | module | pack | items

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM