pivot-libre/tideman
Composer 安装命令:
composer require pivot-libre/tideman
包简介
Implementation of the Tideman ranked pairs algorithm
README 文档
README
Purpose
This algorithm takes a collection of rankings and produces a reasonably fair aggregate ranking using T.N. Tideman's Ranked Pairs Algorithm.
Background
This documentation's intended audience is programmers. See Wikipedia's Ranked Pairs article or Canadian MP Ron McKinnon's condorcet.ca for layperson-oriented explanations.
Summary
This algorithm first computes the difference in popular support between all pairs of candidates across all ballots. This pairwise difference between two candidates is called a margin. Next, the algorithm sorts the margins in order of descending difference. The algorithm then builds a graph data structure by iterating through the sorted list of margins from largest difference to smallest difference, adding an edge that points from the winning candidate to the losing candidate of each margin. If adding a margin's edge would introduce a cycle, the margin is ignored. The winning candidate is the candidate who has no edges pointing at them once the graph has been completed. In other words, the winner is the source node in the completed graph. If multiple winners are desired, then the entire algorithm is repeated without considering candidates that have already won.
Usage
Add pivot-libre/tideman as a dependency in your project's composer.json.
See tests/RankedPairsCalculatorTest.php for example usage.
Details
Papers
- Independence of Clones as a Criterion for Voting Rules. Tideman, T.N. Soc Choice Welfare (1987) 4: 185. https://doi.org/10.1007/BF00433944
- Complete Independence of Clones in the Ranked Pairs Rule. Zavist, T.M. & Tideman, T.N. Soc Choice Welfare (1989) 6: 167. https://doi.org/10.1007/BF00303170
The original 1987 Ranked Pairs paper lacked a tie-breaking rule. The follow-up 1989 paper added a tie-breaking rule.
Pairwise Tie-Breaking
When ranking pairs of candidates, it is possible that the difference in popular support between two candidates is equal to the difference in popular support between two other candidates. In that case, the tie between the pairs of candidates must be broken by a pairwise tie-breaking rule. This library breaks pairwise ties according to a user-specified tie-breaking Ballot object. If the user of the library specifies a tie-breaking Ballot object that contains ties within it (i.e. ties between candidates), the library breaks all of that Ballot object's ties using PHP's default random number generator. The library does not enforce the source of the tie-breaking Ballot object. If a user wished to follow the tie-breaking rule specified in Zavist, Tideman 1989, they should randomly select a Ballot object from among those submitted by the electorate, and use it as the tie-breaking Ballot object.
Additional Reading
- Wikipedia's Ranked Pairs article
- Canadian MP Ron McKinnon's condorcet.ca offers an excellent layperson-oriented survey of Ranked Pairs. Be sure to explore the various in-page dropdown sections and tabs, as some important parts of the site’s content are hidden inside.
- The Cambridge Press Handbook of Computational Social Choice is available as a free pdf. Tideman’s Ranked Pairs Algorithm is described on page 98-101.
- An alternate description of the Tideman-Zavist tie-breaking rule is in an electorama mailing list post by Dr. Markus Schulze. The explanation is just a few lines long, starting with "Thomas Zavist suggested that...".
Contributing
Setup
- Install PHP 7.1 and composer.
- The library is known to work when the following PHP extensions are installed, though the minimal list of extensions is probably shorter (See Issue #51): ctype,curl,dom,iconv,json,mbstring,openssl,pdo,pdo_sqlite,phar,sqlite3,tokenizer,xmlreader,xmlwriter,zlib
Working With the Code
- Fork this repo.
- Clone your fork.
- Add this repo as upstream.
- Examples:
git remote add upstream git@github.com:pivot-libre/tideman.gitgit remote add upstream https://github.com/pivot-libre/tideman.git
- Examples:
- Download the dependencies
composer install
- Build the project
vendor/bin/phing- This command checks the syntax of the files, run tests, checks for formatting conformance, and performs static code quality analysis.
- At the end of the output you should see
BUILD FINISHED. You should not seeBUILD FAILLED.
Visualizing Test Coverage
- Make sure you have installed xdebug.
- Run
vendor/bin/phing coverage- Open a web browser to
file:///<file-path-to-cloned-repo>tideman/build/coverage/index.html - For example:
file:///home/john_doe/src/tideman/build/coverage/index.html
Sharing Your Work
- Git
add, andcommityour local changes - Push your changes to your GitHub fork
git push origin
- Create a pull request between your fork and the PivotLibre/tideman repo.
Getting Updates
git fetch upstream- Depending on whether you are using a merge-based or rebase-based workflow you will run one of:
git merge upstream/0.xgit rebase upstream/0.x
pivot-libre/tideman 适用场景与选型建议
pivot-libre/tideman 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64 次下载、GitHub Stars 达 10, 最近一次更新时间为 2018 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「voting」 「ranked pairs」 「Tideman」 「preferential voting」 「Condorcet」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pivot-libre/tideman 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pivot-libre/tideman 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pivot-libre/tideman 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ratings Plugin for CakePHP.
Complete election manager, providing natively many voting methods including: Condorcet / Borda (+ Nauru variant) / Copeland / Dodgson (2 Approximations) / FTPT / Instant-runoff (alternative vote) / Kemeny–Young / Minimax (+ variants) / Ranked Pairs (+ variants) / Schulze (+ variants), Single Transfe
Create voting campaigns
Pairs implementation
User voting module
Provide a flexible pairs game. You are able to configure the pairs game in many different types. You can assign two cards with the same image, two cards with similar images, two cards with an image and a description of the image or two text cards with the same description (i.e. in different language
统计信息
- 总下载量: 64
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2018-04-07