Pular para conteúdo

tucoopy.games.weighted_voting

Weighted voting games (simple games).

Given weights \(w_i\) and quota \(q\), a coalition \(S\) is winning if \(\sum_{i \in S} w_i \ge q\). The characteristic function takes two values: winning_value and losing_value (with \(v(\varnothing)=0\) enforced).

See Also

tucoopy.power.banzhaf.banzhaf_index tucoopy.power.shapley_shubik.shapley_shubik_index

Examples:

>>> from tucoopy.games.weighted_voting import weighted_voting_game
>>> g = weighted_voting_game([2, 1, 1], quota=3)
>>> g.value(0b011)
1.0

weighted_voting_game

weighted_voting_game(
    weights,
    quota,
    *,
    player_labels=None,
    winning_value=1.0,
    losing_value=0.0,
)

Construct a weighted voting game (simple game).

Given weights \(w_i\) and quota \(q\), coalition \(S\) is winning if \(\sum_{i \in S} w_i \geq q\). The characteristic function is given by:

\[ v(S) = \begin{cases} w_v, & \text{ if } S \text{ is winning} \\ l_v, & \text{ otherwise} \end{cases} \]

Parameters:

Name Type Description Default
weights Sequence[float]

Player weights.

required
quota float

Winning threshold.

required
player_labels list of str

Optional display labels for players.

None
winning_value float

Value assigned to winning coalitions (default 1.0).

1.0
losing_value float

Value assigned to losing coalitions (default 0.0). The empty coalition is always normalized to 0.0 (TU convention).

0.0

Returns:

Type Description
Game

A TU game with values in {0,1} (by default), suitable for power indices.

Raises:

Type Description
InvalidParameterError

If fewer than 1 player is provided.

Notes

Commonly: winning_value=1, losing_value=0. The TU convention \(v(\varnothing)=0\) is enforced even if losing_value is non-zero.

Examples:

>>> from tucoopy.games.weighted_voting import weighted_voting_game
>>> g = weighted_voting_game([2, 1, 1], quota=3)
>>> g.value(0b011)  # 2+1 meets quota
1.0
>>> g.value(0b001)
0.0