- home
- code
- rdoc
-
FIX (url)
- bugs
- C-lib
A ranking is a partial order that, given some set of alternatives, places some before others. A preference graph, given some number of rankings, expresses the combination of all of those rankings. It is a directed, weighted graph in which the nodes represent the alternatives and the edges represent preferences.
Use this to build a preference graph from individual rankings and compute a Kemeny order, aggregated preference that minimizes the number of pair-wise disagreements with the individual rankings.
This is a Ruby binding built around a C language implementation of Davenport’s algorithm, found on github at wbreeze/davenport
Please see github.com/wbreeze/davenport-ruby/issues for a list of any issues and add your own there, or contact the author.
pg = Davenport::PreferenceGraph.new(4) pg.add_preference([1, 3, 2, 4]); pg.add_preference([1, 2, 2, 4]); pg.add_preference([2, 1, 3, 4]); pg.add_preference([1, 3, 2, 4]); pg.davenport => [1, 3, 2, 4]
The single array parameter for ‘add_preference` has a rank number for the item at the corresponding index. For example, with four items, `[1, 2, 2, 4]` assigns rank 1 to the first item, 2 to the second and third items, and 4 to the final item. The preference, `[2, 2, 2, 1]` ranks the last item first and all of the others equally after it.
See .ruby-version for the version of Ruby used in development.
This requires the Davenport library installed according to wbreeze/davenport
gem install davenport
After checking out the source, run:
$ rake newb
This task will install any missing dependencies, run the tests/specs, and generate the RDoc.
GNU Lesser General Public License v3 (LGPL-3.0)
See the file, LICENSE for the full text.
Copyright © 2019 Douglas Lovell