Module: Apportion::Algorithm::EqualProportions

Defined in:
lib/apportion/algorithm/equal_proportions.rb

Overview

Selects the next recipient

Constant Summary collapse

BIG_FIXNUM =
2 ** 30

Class Method Summary collapse

Class Method Details

.next_recipient(weights, portions) ⇒ Symbol

Selects the next recipient by sorting the equal proportions rank-index of the recipients

see Balinski, M. and H. Young, The Quota Method of Apportionment, Amer. Math. Monthly 82 (1975) 701-730.

Examples:

next_recipient({a: 41, b: 32, c: 27}, {a: 4, b: 3, c: 2})
# => :c

Parameters:

  • weights (Hash)

    relative integer proportions

  • portions (Hash)

Returns:

  • (Symbol)

    recipient having the highest equal proportions rank-index



21
22
23
# File 'lib/apportion/algorithm/equal_proportions.rb', line 21

def next_recipient(weights, portions)
  weights.max_by { |k, v| recipient_rank(v, portions[k]) }[0]
end