-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Common bin packing heuristics -- -- An implementation of the first-fit, modified-first-fit, last-fit, -- best-fit, worst-fit, and almost-last-fit bin packing heuristics. Items -- can be packed in order of both decreasing and increasing size (and, of -- course, in unmodified order). -- -- The module supports both the standard (textbook) minimization problem -- (How many bins do I need?) and the more practical fitting -- problem (I've got n bins; which items can I take?). -- -- The API is simple and the module is documented with Haddock (complete -- with examples). The implementation of the above-mentioned heuristics -- is complete and partially tested with QuickCheck. However, note that -- speed has not been a primary concern to date. -- -- Patches and feedback are very welcome. @package Binpack @version 0.3 -- | This module implements a number of common bin packing heurstics: -- FirstFit, LastFit, BestFit, WorstFit, and -- AlmostWorstFit. In addtion, the not-so-common, but analytically -- superior (in terms of worst-case behavior), ModifiedFirstFit -- heuristic is also supported. Items can be packed in order of both -- Decreasing and Increasing size (and, of course, in -- unmodified order; see AsGiven). -- -- The module supports both the standard (textbook) minimization problem -- ("How many bins do I need to pack all items?"; see -- minimizeBins and countBins) and the more practical -- fitting problem ("I've got n bins; which items can I take?"; -- see binpack). -- -- The well-known heuristics are described online in many places and are -- not further discussed here. For example, see -- http://www.cs.arizona.edu/icon/oddsends/bpack/bpack.htm for an -- overview. A description of the ModifiedFirstFit algorithm is -- harder to come by online, hence a brief description and references are -- provided below. -- -- Note that most published analysis assumes items to be sorted in some -- specific (mostly Decreasing) order. This module does not -- enforce such assumptions, rather, any ordering can be combined with -- any placement heuristic. -- -- If unsure what to pick, then try FirstFit Decreasing as -- a default. Use BestFit (in combination with binpack) if -- you want your bins filled evenly. -- -- A short overview of the ModifiedFirstFit heuristic follows. -- This overview is based on the description given in (Yue and Zhang, -- 1995). -- -- Let lst denote the list of items to be bin-packed, let -- x denote the size of the smallest element in lst, -- and let cap denote the capacity of one bin. lst is -- split into the four sub-lists, lA, lB, lC, -- lD. -- --
-- minimizeBins FirstFit Increasing length 11 (words "Bin packing heuristics are a lot of fun!") -- ~~> ([1,4,4,2],[["heuristics"],["packing"],["fun!","lot"],["are","Bin","of","a"]]) ---- --
-- minimizeBins FirstFit Decreasing id 11 [3,7,10,3,1,3,2,4] -- ~~> ([0,0,0],[[2,3,3,3],[4,7],[1,10]]) --minimizeBins :: (Num a, Ord a) => PlacementPolicy -> OrderPolicy -> Measure a b -> a -> [b] -> ([a], [Bin b]) -- | Wrapper around minimizeBins; useful if only the number of -- required bins is of interest. See minimizeBins for a -- description of the arguments. -- -- Examples: -- --
-- countBins FirstFit Increasing length 11 (words "Bin packing heuristics are a lot of fun!") -- ~~> 4 ---- -- -- --
-- countBins FirstFit Decreasing id 11 [3,7,10,3,1,3,2,4] -- ~~> 3 --countBins :: (Num a, Ord a) => PlacementPolicy -> OrderPolicy -> Measure a b -> a -> [b] -> Int -- | Bin pack with a given limit on the number (and sizes) of bins. Instead -- of creating new bins, this version will return a list of items that -- could not be packed (if any). -- -- Example: We have two bins, one of size 10 and one of size 12. Which -- words can we fit in there? -- --
-- binpack WorstFit Decreasing length [10, 12] (words "Bin packing heuristics are a lot of fun!") -- ~~> ([0,0],[["heuristics"],["a","fun!","packing"]],["of","lot","are","Bin"]) --binpack :: (Num a, Ord a) => PlacementPolicy -> OrderPolicy -> Measure a b -> [a] -> [b] -> ([a], [Bin b], [b]) instance Show PlacementPolicy instance Eq PlacementPolicy instance Ord PlacementPolicy instance Show OrderPolicy instance Eq OrderPolicy instance Ord OrderPolicy instance Arbitrary PlacementPolicy instance Arbitrary OrderPolicy