MissingH-1.4.0.1: Large utility library

CopyrightCopyright (C) 2008-2011 John Goerzen
LicenseBSD3
MaintainerJohn Goerzen <jgoerzen@complete.org>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

Data.BinPacking

Description

Tools for packing into bins

Written by John Goerzen, jgoerzen@complete.org

This module is designed to solve this type of problem: Given a bunch of objects of varying sizes, what is the best possible way to pack them into fixed-size bins? This can be used, for instance, by the datapacker program to pack files onto CDs or DVDs; by manufacturing environments to pack physical items into physicl bins; etc.

A description of bin packing algorithms can be found at http://en.wikipedia.org/wiki/Bin_packing_problem.

Synopsis

Documentation

type BinPacker = forall size obj. (Num size, Ord size, Show size, Show obj) => [size] -> [(size, obj)] -> Either (BinPackerError size obj) [[(size, obj)]] Source #

The primary type for bin-packing functions.

These functions take a list of size of bins. If every bin is the same size, you can pass repeat binSize to pass an infinite list of bins if the same size. Any surplus bins will simply be ignored.

[size] is the sizes of bins
[(size, obj)] is the sizes and objects
result is Either error or results

data (Num size, Ord size, Show size, Show obj) => BinPackerError size obj Source #

Potential errors returned as Left values by BinPacker functions. Calling show on this value will produce a nice error message suitable for display.

Constructors

BPTooFewBins [(size, obj)]

Ran out of bins; attached value is the list of objects that do not fit

BPSizeTooLarge size (size, obj)

Bin size1 exceeded by at least the given object and size

BPOther String

Other error

Instances

(Eq obj, Num size, Ord size, Show size, Show obj) => Eq (BinPackerError size obj) Source # 

Methods

(==) :: BinPackerError size obj -> BinPackerError size obj -> Bool #

(/=) :: BinPackerError size obj -> BinPackerError size obj -> Bool #

(Num size, Ord size, Read size, Read obj, Show size, Show obj) => Read (BinPackerError size obj) Source # 
(Num size, Ord size, Show size, Show obj) => Show (BinPackerError size obj) Source # 

Methods

showsPrec :: Int -> BinPackerError size obj -> ShowS #

show :: BinPackerError size obj -> String #

showList :: [BinPackerError size obj] -> ShowS #

(Num size, Ord size, Show size, Show obj) => Error (BinPackerError size obj) Source #

Let us use this as part of the Either monad

Methods

noMsg :: BinPackerError size obj #

strMsg :: String -> BinPackerError size obj #

packByOrder :: BinPacker Source #

Pack objects into bins, preserving order. Objects will be taken from the input list one by one, and added to each bin until the bin is full. Work will then proceed on the next bin. No attempt is made to optimize allocations to bins. This is the simplest and most naive bin-packing algorithm, but may not make very good use of bin space.

packLargeFirst :: BinPacker Source #

Pack objects into bins. For each bin, start with the largest objects, and keep packing the largest object from the remainder until no object can be found to put in the bin. This is substantially more efficient than packByOrder, but requires sorting the input.