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

# 全提携を列挙できないゲームは 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, names=None), compare(game, [(名前, 配分), ...]) 配分の説明と比較 (text に日本語の説明)
verify_solution(game, allocation, concept) 配分が仁 (プレ仁) かを事後検証 (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, names=None, kernel=True, shapley=True, points=None, title=None) 3-4 人の配分集合の図。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)
  • domain は "imputation" (仁・カーネル) か "preimputation" (プレ仁・プレカーネル)。
  • 結果は辞書で返す。キーは Rust の結果の構造体のフィールド名と同じ。guarantee に保証の種類が入る。
  • Python の関数が例外を投げると、計算を打ち切ってその例外をそのまま送出する。
  • 入力の誤りは ValueError、LP の失敗などは RuntimeError になる。

Metadata

Release files for coopgame-py 0.1.1

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.1.1
File Size Uploaded
coopgame_py-0.1.1.tar.gz 206.3 kB Details

Built distributions (wheels)

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

Total release size: 4.7 MB

Release files / coopgame_py-0.1.1.tar.gz

Download URL coopgame_py-0.1.1.tar.gz
Size 206.3 kB
Tags Source
SHA-256 checksum
How to use checksums
532ad14fb5d0d5a6a37bcbb6aee033ec5106df77b36ca9dd7371d60b3aac1105
BLAKE2b-256 checksum
How to use checksums
6d648e233d2ba23b08fb6d07e9b6c19ae409947386b416532f214fd7d1fdd19a
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 4, 2026.

Transparency log

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

Download URL coopgame_py-0.1.1-cp39-abi3-win_amd64.whl
Size 849.5 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
edd6f6c973a3b74963f8c88c7b2d6e8c37279276c1bc25d0848e9ec5afd31333
BLAKE2b-256 checksum
How to use checksums
b3b2a01304f70d73a86ed2f379f5a8e2ef2ef45a8dd4768cf64a278e5bb2a19a
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 4, 2026.

Transparency log

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

Download URL coopgame_py-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 948.1 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
4661db1d564d7e3b8c389db0a0898965bac0056a92aafe925f422b6066d2f2e1
BLAKE2b-256 checksum
How to use checksums
8dff31b202e22147eb81e7c32cb11b038f7db56bd77306ab461e20cc32a05877
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 4, 2026.

Transparency log

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

Download URL coopgame_py-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 895.9 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
28b629010f10acbad9de4e0e7db893dda48a58d0023e76078293cb57ea09d359
BLAKE2b-256 checksum
How to use checksums
4f741a7811bd8f6a61fd5b54eda00a8cd3d32c27ffda88685e00637ed011a993
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 4, 2026.

Transparency log

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

Download URL coopgame_py-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Size 858.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6baa9d2ef067fda1e2e5ed9e69ded6596be3f88b6363414cc68ce9fbb24e8da2
BLAKE2b-256 checksum
How to use checksums
c8d61f02e783b3cce0ddab51b05c3555929031b9a8de6c25d76540653c5364cb
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 4, 2026.

Transparency log

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

Download URL coopgame_py-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 907.1 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8b28fde492cd8c7a974583081ed324ae7ee8905d7fea78b6ffb47d8c0d9fc1f3
BLAKE2b-256 checksum
How to use checksums
e6dea2568237f690728e849f094196d87e789a81ff6b9bba73a19b2cb55c6442
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 4, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

6 release files

0.1.0

6 release files

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