Project

apportion

0.0
No commit activity in last 3 years
No release in over 3 years
Ruby implementation for apportionment
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 5.8
~> 10.5
~> 0.11
~> 0.8

Runtime

~> 1.8
 Project Readme

Apportion travis yard docs code climate

A Ruby implementation for apportionment

Description

Apportionment is most often associated with the US Congressional apportionment, using the Equal Proportions (or Huntington-Hill) method.

In general, apportionment involves the division of a scarce resource among recipients, according to a pre-determined set of recipient weights. Further, a series of apportionments might occur over time, with each new apportionment overlaying the previous.

Different domains might make use of apportionment. One example is the allocation (or distribution) of sellable inventory among a number of retail stores, according to the expected sales rate for each store. For this usage, recipients would likely begin an apportionment with varying quantities of existing inventory.

Other apportionment methods exist, notably the Quota method, that address issues with Equal Proportions.

Installation

Add this line to your application's Gemfile:

gem 'apportion'

And then execute

$ bundle

Or install it yourself as

$ gem install apportion

Usage

Apportion.division(weights, size, options = {})

Returns a hash (a key for each recipient) with the size quantity distributed among recipients (as values)

Parameters

weights (required) a [Hash] of relative integer proportions for each recipient

size (required) an [Integer] quantity to apportion

options (optional) [Hash] keys

  • :prior_portions a [Hash] prior portions for each recipient from a previous apportionment
  • :required_minimum an [Integer] smallest portion for each recipient

Development

To install dependencies

$ bundle

To run the tests

$ rake

License

The gem is available as open source under the terms of the MIT License.