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 値
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.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.1.0
File Size Uploaded
coopgame_py-0.1.0.tar.gz 191.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for coopgame-py 0.1.0
File
coopgame_py-0.1.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
coopgame_py-0.1.0-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.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
coopgame_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
coopgame_py-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.6 MB

Release files / coopgame_py-0.1.0.tar.gz

Download URL coopgame_py-0.1.0.tar.gz
Size 191.3 kB
Tags Source
SHA-256 checksum
How to use checksums
80322a7b2916baca87b572f6a38dbe31a16c3d69f3f6b812857236a98b78ae7f
BLAKE2b-256 checksum
How to use checksums
a89a061668c15ede14e77618988082eb7792b44f1cd8d0e07f47fb99ba7d3707
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 3, 2026.

Transparency log

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

Download URL coopgame_py-0.1.0-cp39-abi3-win_amd64.whl
Size 829.8 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d66b296b298ace67f6c79c5ba01a98bca1529b6d40c16f4466df7f9d4078bf33
BLAKE2b-256 checksum
How to use checksums
c996a69e3f8ae6c4175c69fd2cec6bad36c0899e310efac01162f196fd384cb6
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 3, 2026.

Transparency log

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

Download URL coopgame_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 929.5 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
60fb366ce8f8689f9624d499d9be6bac4205d1c64468df81ad67b794e1efc644
BLAKE2b-256 checksum
How to use checksums
77d78f1812389f459d46b2e6bef9016392cf3700c9de3cd6fda02769659941a2
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 3, 2026.

Transparency log

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

Download URL coopgame_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 876.5 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2f1b3299b8b4b0c420aa5228851e1b2d3cb19364067b2cb208c502e082ab9e09
BLAKE2b-256 checksum
How to use checksums
419ee22ce1679b1d21b186598a74f1739a57ce01ba6df0071cf2058a73168ce0
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 3, 2026.

Transparency log

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

Download URL coopgame_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Size 840.6 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f9f532769398d0b09a3a648921a735e8b447956bd7ecfdf1f7f107ca4e0aec63
BLAKE2b-256 checksum
How to use checksums
45f7d88c88fd9ca53bb8a1121c9905f86ef91d24490edfa708bf56c1733e7635
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 3, 2026.

Transparency log

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

Download URL coopgame_py-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 890.1 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0f41c82919f470fd287bf1a23208302fc052d3e026fafc3856e92412b3c01ed9
BLAKE2b-256 checksum
How to use checksums
0fb3475429a96869452ad738ac564c28225fddedb5157c14b1c6aef6156f6799
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 3, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.1

6 release files

This release

0.1.0 This release

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