pivot-libre/tideman 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pivot-libre/tideman

Composer 安装命令:

composer require pivot-libre/tideman

包简介

Implementation of the Tideman ranked pairs algorithm

README 文档

README

Travis status Coveralls coverage Codacy Badge PDD status

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

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.git
      • git remote add upstream https://github.com/pivot-libre/tideman.git
  • 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 see BUILD 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, and commit your 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.x
    • git 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 pivot-libre/tideman 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 64
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 10
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-04-07