投票算法的python库。
ballotbox的Python项目详细描述
Introduction
关于气囊
ballotbox是一个python库,它试图实现有用的投票 方法论。
这个项目是在对话和实验的基础上开始的 讨论自组织对象网格时放置在ULS-SIG上。
依赖性
当前的实现依赖于以下附加软件 和/或库:
- Python
- zope.interface
- sphinx
- repoze.sphinx.autointerface
其他信息
有关以下内容的信息,请参见章节(或者,如果阅读 工作目录中的这个文件,./docs子目录:
- Installation
- Usage
Installation
发展
如果你想为ballotbox开发或者使用我们正在开发的最新代码, 您可以从源安装。你需要安装bzr,然后 以下内容:
$ bzr branch lp:ballotbox $ cd ballotbox $ sudo python setup.py install
易于安装
您可以使用setuptools easy_install脚本在 系统:
$ sudo easy_install ballotbox
手动下载
您可以通过以下方式从python包索引手动下载源tarball 访问以下网址:
http://pypi.python.org/pypi/ballotbox
你需要解压源代码,将cd压缩到源目录,然后 然后您可以按常规操作:
$ sudo python setup.py install
检查源
一旦安装,只要您在系统上安装了twisted和 在您的路径中,您可以通过执行以下命令来测试源代码 任何位置:
$ trial ballotbox
它将运行测试套件并报告任何单元的成功与失败 测验。
Usage
下面是对api使用的简要介绍。使用的投票方法 在这个例子中是简单多数。简单多数原则投票 对二元决策有用。以下是一些例子,仅涉及两个 选择:
>>> from ballotbox.ballot import BallotBox >>> from ballotbox.singlewinner.simple import MajorityRuleVoting >>> bb = BallotBox(method=MajorityRuleVoting) >>> bb.batch_votes([("alice", 10000), ("bob", 5000)]) >>> bb.get_winner() [(10000, 'alice')] >>> bb = BallotBox(method=MajorityRuleVoting) >>> bb.batch_votes([("bob", 5000), ("carol", 5001)]) >>> bb.get_winner() [(5001, 'carol')]
这种方法会因关系而崩溃,并且不能保证在超过 两种选择:
>>> bb = BallotBox(method=MajorityRuleVoting) >>> bb.batch_votes([("alice", 8000), ("carol", 8000)]) >>> bb.get_winner() []
不返回结果。同样,对于两个以上候选的边缘情况:
>>> bb = BallotBox(method=MajorityRuleVoting) >>> bb.batch_votes([("alice", 5000), ("bob", 4000), ("carol", 3000)]) >>> bb.get_winner() []
TODO
实施
[完成]将条件类转换为使用接口。然后,代替 在投票方法中对它们进行子类化,它们就会实现它们。这个遗嘱 使zope.interface成为依赖项。
[完成]将多doctest文件测试套件代码从txuls/soom复制到此处。
[完成]为每个投票方法添加一个新的docs/methods目录和一个文件。
[进行中]完成单一赢家投票方法的实施。
实施多赢家投票方法。
实现代理投票和随机投票的方法。
进行基于距离的投票研究:
- in particular, defining a metric space for candidates based on a set of preferences
- then taking the square root of the sum of the squares, getting the n-dimensional distance
测试
[进行中]为每个投票方法添加doctest。
添加测试源距离的生成目标:
- create a temp dir
- untar the dist there
- run the unit tests and doctests against that directory
文件
- Change uppercase doc files to lower case (with the exceptions of the standard ones like README, TODO, etc.)
- Updated the sphinx configuration file to use ballotbox.meta
- Add sidebar links in the generated docs
- Autogenerate ReST files for API docs
- the logic that drives this should go in ballotbox.util.docs
- add a make target that imports and calls the appropriate functions to generate the API docs