Skip to main content

Calculates power indices (Banzhaf/Penrose, Shapley/Shubik) via binary decision diagrams

Project description

power_bdd

Creates the ROBDD of a weighted game and calculates power indices according to Banzhaf/Penrose and Shapley/Shubik. This method allows to easily connect bdds with AND or OR and is also suited for voting systems with multiple layers. The method was published by S. Bolus:

Usage

Installation

pip install power_bdd

Import

from power_bdd.bdd import BDD, WeightedGame

one-tier games

This example calculates the power indices for the electoral college, 1996.

w = [54, 33, 32, 25, 23, 22, 21, 18, 15, 14, 13, 13, 12, 12, 11, 11, 11, 11, 10, 10, 9, 9, 8, 8, 8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3]                
q = 270
game = WeightedGame(q, w)
bdd = BDD(game)
banzhaf = bdd.calc_banzhaf()
shapley = bdd.calc_shapley()
print(banzhaf)
print(shapley)

multi-tier games

This example calculates the power-indices for the U.S. federal system, which can represented by the weighted voting systems G = (G1 and G2 and G3) or (G1 and G4 and G5 and G3) or (G6 and G7), see https://www.fernuni-hagen.de/stochastik/downloads/voting.pdf.

game1 = WeightedGame(218, [0, 0] + [0] * 100 + [1] * 435)
game2 = WeightedGame(51,  [0, 0] + [1] * 100 + [0] * 435)
game3 = WeightedGame(1,   [1, 0] + [0] * 100 + [0] * 435)
game4 = WeightedGame(50,  [0, 0] + [1] * 100 + [0] * 435)
game5 = WeightedGame(1,   [0, 1] + [0] * 100 + [0] * 435)
game6 = WeightedGame(290, [0, 0] + [0] * 100 + [1] * 435)
game7 = WeightedGame(67,  [0, 0] + [1] * 100 + [0] * 435)

federal_system = BDD(game1) & BDD(game2) & BDD(game3) | BDD(game1) & BDD(game4) & BDD(game5) & BDD(game3) | BDD(game6) & BDD(game7)
banzhaf = federal_system.calc_banzhaf()
print(banzhaf)

Complexities

Listed complexities are expected complexities for the computation of all voters. At first glance, the complexities seem partly worse than other methods (e.g. using dynamic programming), but there are several hidden benefitial properties, for instance q is not necessary the q input q, but the smallest integer that is possible to use as quota to represent the game (with any weights).

one-tier games:

power-index     | time          | space       
------------    | ------------- | ------------
Banzhaf/Penrose | O(nq log(q))  | O(nq)
Shapley/Shubik  | O(n^3q)       | O(n^2q)

multi-tier games with m tiers:

power-index     | time                   | space       
------------    | -------------          | ------------
Banzhaf/Penrose | O(n prod_{t=1}^m q^t)  | O(n prod_{t=1}^m q^t)
Shapley/Shubik  | O(n^3 prod_{t=1}^m q^t)| O(n^2 prod_{t=1}^m q^t)

Remarks

  • My java-version is much faster (somewhere between 10-100 times) so there should be plenty of room for optimization in python.
  • The original version uses an AVL-tree for the create-method. I have replaced that by a SortedList form the sortedcontainers-library.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

power-bdd-0.0.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

power_bdd-0.0.1-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file power-bdd-0.0.1.tar.gz.

File metadata

  • Download URL: power-bdd-0.0.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0

File hashes

Hashes for power-bdd-0.0.1.tar.gz
Algorithm Hash digest
SHA256 547cd4035ac6b04221ec1e0ae38297edc5703c0f480314fb13385b9f75de26da
MD5 bc350384fd6af972ac32f54bd658fb6f
BLAKE2b-256 d559f58bf705a26db3aa4268939b62a23c065d7e9458d7d89481de653fd4a734

See more details on using hashes here.

File details

Details for the file power_bdd-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: power_bdd-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0

File hashes

Hashes for power_bdd-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb458bcb5f52b400cca381404a6fbdd8c6749055df15f349c6978bd0f9bb1a99
MD5 a06be30bdde90af0213e211e0f2ca56b
BLAKE2b-256 a376200dc62e0ee40ffb6b0aa66d7bc8b807e5d6d660f9cd325ddb4f0ea87505

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page