Skip to main content

coopgame (Python バインディング)

Rust ライブラリ coopgame の機能を Python から使うためのバインディング (PyO3)。 Python 3.9 以降で動く (abi3)。

インストール

PyPI での配布名は coopgame-py で、import 名は coopgame である (PyPI の coopgame は別のパッケージが使っている)。

pip install coopgame-py

ビルド

python3 -m venv .venv && . .venv/bin/activate
pip install maturin pytest
cd python
maturin develop --release   # 現在の環境にインストール
pytest tests                # 文献の数値例などのテスト

例

from fractions import Fraction
import coopgame

# 辞書式順 ({1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}) で与える。既定はビット順 (order="binary")。
game = coopgame.Game([0, 0, 0, 10, 0, 0, 2], order="lex")
coopgame.nucleolus(game)["allocation"]                      # [1.0, 1.0, 0.0]
coopgame.prenucleolus(game)["allocation"]                   # [3.0, 3.0, -4.0]
coopgame.certify(game, [3, 3, -4], "preimputation")         # {'allocation': [Fraction(3, 1), ...], 'satisfied': True, ...}
coopgame.kernel_set(game, "preimputation")["pieces"]        # 多面体の一覧

coopgame.talmud(100, [100, 200, 300], exact=True)           # [Fraction(100, 3)] * 3

# JSON・CSV の提携はプレイヤー番号 (0 始まり) で書く。
loaded = coopgame.parse_game('{"values": {"0": 0, "1": 0, "0,1": 4}}')
coopgame.nucleolus(loaded["game"])["allocation"]            # [2.0, 2.0]

# 全提携を列挙できないゲームは Python の関数で与える (提携はプレイヤー番号のタプル)。
majority = coopgame.FunctionGame(101, lambda s: float(len(s) >= 51))
coopgame.shapley_sampling(majority, 2000, seed=0)           # values, standard_errors, evaluations
coopgame.sampled_nucleolus(majority, 500, seed=0)           # サンプルした提携だけで解いたプレ仁

API

関数 内容
Game(values, order="binary" or "lex"), Game.from_function(n, f), Game.weighted_voting, Game.bankruptcy, Game.bnf 明示ベクトルのゲーム (30 人まで)。value, values, is_convex などのメソッドを持つ
FunctionGame(n, f) Python の関数で値を返すゲーム。サンプリング系の関数だけが受け付ける
nucleolus(game, domain="imputation", method="cg" or "full"), prenucleolus, least_core 仁・プレ仁・最小コア
per_capita_nucleolus, proportional_nucleolus, modiclus 仁の変種
kernel_point, kernel_violation, is_in_kernel, kernel_set(..., merge=False) カーネル・プレカーネル
bargaining_set(game, x, domain) 交渉集合 (プレ交渉集合) への所属と、反論のない異議
InducedSubgraphGame(n, edges) 誘導部分グラフゲーム (重みは非負、構造的に凸、人数の上限なし)
convex_nucleolus(game, assume=False, verify=True) 凸ゲームの手法で仁。assume=True は凸と仮定して試し、verdict に検証結果
auto_nucleolus(game) 保証のある手法のうち最も速いものを選ぶ
cost_nucleolus(game), airport(costs), spanning_tree(costs), linear_production(technology, prices, resources) 費用ゲームと、構造を持つ費用ゲーム (空港・最小全域木・線形生産)
uncertainty(game, relative=0.1) / uncertainty(lower, upper=upper), influence(game) 値の不確かさによる配分の分布と、提携の値に対する感度
explain(game, x, levels=3), compare(game, [配分, ...]) 配分の説明と比較 (text に日本語の説明)。compare の rows は入力と同じ順
verify_solution(game, allocation, domain) 配分が仁 (プレ仁) かを事後検証 (certified・refuted・undecided)
parse_game(text, format="json", missing="error"), partial_nucleolus(text, format) JSON・CSV の読み込み (提携はプレイヤー番号) と、値が分かる提携だけで解いた仁
aumann_dreze(game, blocks), owen(game, unions), structured_nucleolus(game, blocks) 提携構造・事前の連合のもとでの解
plot_svg(game, kernel=True, shapley=True, points=None, title=None) 3-4 人の配分集合の図。points は配分のリスト。SVG 文字列とコアの頂点などを辞書で返す
shrink(game, predicate) 反例 (predicate(game) が真) のまま、ゲームを小さく単純にする
nucleolus_exact(values, domain, order) 有理数だけの逐次 LP による厳密な仁 (10 人まで)
certify_rational(values, x, domain, order) 有理数の値 (Fraction・"8/3"・"0.1") のゲームで厳密に検証
verify, certify Kohlberg 基準による検証 (浮動小数点、有理数)
shapley, banzhaf, normalize, shapley_sampling, banzhaf_sampling Shapley 値・Banzhaf 値
disruption_nucleolus(game) disruption nucleolus (Littlechild & Vaidya 1976、コアが空なら ValueError)。per_capita_nucleolus と同じ形の辞書
anti_prenucleolus(game), anti_nucleolus(game), dual(game) anti-prenucleolus・anti-nucleolus (双対ゲームのプレ仁・仁、Funaki & Meinhardt 2006) と双対ゲーム。anti の 2 つは nucleolus と同じ形の辞書
solidarity(game) solidarity 値 (Nowak & Radzik 1994)
tau_value(game), utopia_payoffs(game) tau 値 (Tijs 1981、準平衡でなければ ValueError)。理想の支払いと最小の権利
gately_point(game) Gately 点 (Gately 1974)
myerson(game, edges), graph_restricted(game, edges) 通信グラフ (プレイヤー番号の組の列) のもとでの Myerson 値と、グラフ制限ゲーム
power_indices(game) 単純ゲームの Johnston・Deegan–Packel・Public Good (Holler)・Coleman の指数、決定票の数、最小勝利提携
sampled_nucleolus, sampled_least_core サンプルした提携による仁・最小コア
talmud, constrained_equal_awards, constrained_equal_losses 破産問題の規則 (exact=True で Fraction)
  • プレイヤーは 0 始まりの番号で表す。提携はプレイヤー番号のリスト (Python の関数にはタプル) で受け渡す。
  • domain は "imputation" (仁・カーネル) か "preimputation" (プレ仁・プレカーネル)。
  • 結果は辞書で返す。キーは Rust の結果の構造体のフィールド名と同じ。guarantee に保証の種類が入る。
  • Python の関数が例外を投げると、計算を打ち切ってその例外をそのまま送出する。
  • 入力の誤りは ValueError、LP の失敗などは RuntimeError になる。

Metadata

Release files for coopgame-py 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coopgame-py 0.3.0
File Size Uploaded Provenance Actions
coopgame_py-0.3.0.tar.gz 261.0 kB With provenance Details for coopgame_py-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for coopgame-py 0.3.0
File Actions
coopgame_py-0.3.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for coopgame_py-0.3.0-cp39-abi3-win_amd64.whl
coopgame_py-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for coopgame_py-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
coopgame_py-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for coopgame_py-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
coopgame_py-0.3.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for coopgame_py-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
coopgame_py-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for coopgame_py-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 4.9 MB

Release files / coopgame_py-0.3.0.tar.gz

Download URL coopgame_py-0.3.0.tar.gz
Size 261.0 kB
Tags Source
SHA-256 checksum
How to use checksums
160eb19c61cee89a47a085a576ca9960d5a21b2ccd11bd7cc198e66921e5fa4a
BLAKE2b-256 checksum
How to use checksums
799df260b9527211ef4e9a23bccf662b93a6886696dd02fbc04c3d20632234ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / coopgame_py-0.3.0-cp39-abi3-win_amd64.whl

Download URL coopgame_py-0.3.0-cp39-abi3-win_amd64.whl
Size 893.5 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b4cec4246bed906559940970092c55d1a8bf67a181f12ec9b67559bf10793c9b
BLAKE2b-256 checksum
How to use checksums
2b5d613ac543fd693b4bf963ae707f806fe7039dc8c530f232700f228892fc6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / coopgame_py-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL coopgame_py-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 993.6 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
5e797b5cac7e13e4b5dfc5e8c4a3c71ff249c324b639097150b8a54066828702
BLAKE2b-256 checksum
How to use checksums
c04fe66a094ee819f5020d585fd1cbc7bd05aa2aee001edf144b9f5d44eff199
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / coopgame_py-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL coopgame_py-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 932.1 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
978aa0547ba4fede516a769a4e875a0810443263dc294f67ca512473200f2c93
BLAKE2b-256 checksum
How to use checksums
e7481878c90ab909c575006e39ee920b30ee5b5ede80602a11d8319f75823956
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / coopgame_py-0.3.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL coopgame_py-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
Size 894.4 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
88acfc1e98f7ce036251203665cc4a044442d75166c064365ba07631831494b8
BLAKE2b-256 checksum
How to use checksums
c20c9790401f1b528cf790e392f880f119338e430de3c777ae37ff1e9e753bb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / coopgame_py-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL coopgame_py-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 951.0 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2e7d7831e0771a45c657c561d1e69f775d33b7122d13f6364aac89ea74691b42
BLAKE2b-256 checksum
How to use checksums
cced96badc9711dc47b45dfcb2033f14610cb681745e80d552d427baa433dba9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Security for coopgame-py 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for coopgame_py-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page