Method: ColumnPack::BinPacker#initialize

Defined in:
lib/column_pack/bin_packer.rb

#initialize(total_bins, options = {}) ⇒ BinPacker

Uses a fixed number of bins (total_bins).

Options: :algorithm specify a different bin packing algorithm (default :best_fit_decreasing)

available algorithms are :best_fit_decreasing, :best_fit_increasing

:shuffle_in_col after packing columns, shuffle the elements in each column (defaults to true)

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/column_pack/bin_packer.rb', line 14

def initialize(total_bins, options = {})
  raise ArgumentError.new("Must choose a number of bins greater than zero") if total_bins <= 0

  @total_bins = total_bins
  @algorithm  = options[:algorithm] || :best_fit_decreasing

  if options.has_key? :shuffle_in_col
    @shuffle_in_col = options[:shuffle_in_col]
  else
    @shuffle_in_col = true
  end

  @elements       = []
  @needs_packing  = true
end