Algorithm Search⌘K

Definitioncore

Potential game

Also called exact potential game, Monderer-Shapley potential game.

A game with a function on profiles whose change under any unilateral deviation equals the change in the deviator's cost.

A potential game is a game with one function on the strategy profiles that tracks the cost of whichever player moves: when one player changes strategy, the function changes by exactly the change in that player's cost. It is the property, not a result. The finite improvement property is a weaker property of the dynamics that every finite potential game has. Rosenthal's theorem is the result that every atomic congestion game is a potential game, and congestion games are the main example: Monderer and Shapley showed that every finite exact potential game is isomorphic to one.

Definition

A game in normal form has players 1,…,n1, \ldots, n, strategy sets S1,…,SnS_1, \ldots, S_n, and costs ci:S→Rc_i : S \to \mathbb{R} on the profiles S=S1×⋯×SnS = S_1 \times \cdots \times S_n. Each player minimizes its own cost. For a profile ss, a player ii and a strategy si′∈Sis_i' \in S_i, the profile (si′,s−i)(s_i', s_{-i}) is a unilateral deviation of ii.

A function Φ:S→R\Phi : S \to \mathbb{R} is an exact potential of the game if for every profile ss, every player ii and every si′∈Sis_i' \in S_i,

Φ(si′,s−i)−Φ(s)=ci(si′,s−i)−ci(s).\Phi(s_i', s_{-i}) - \Phi(s) = c_i(s_i', s_{-i}) - c_i(s).

The game is an (exact) potential game if it has an exact potential. Monderer and Shapley also defined three weaker forms. In each, the condition is on every unilateral deviation from ss to s′=(si′,s−i)s' = (s_i', s_{-i}):

  • Weighted potential, with weights wi>0w_i > 0: ci(s′)−ci(s)=wi(Φ(s′)−Φ(s))c_i(s') - c_i(s) = w_i (\Phi(s') - \Phi(s)).
  • Ordinal potential: ci(s′)<ci(s)c_i(s') < c_i(s) if and only if Φ(s′)<Φ(s)\Phi(s') < \Phi(s).
  • Generalized ordinal potential: ci(s′)<ci(s)c_i(s') < c_i(s) implies Φ(s′)<Φ(s)\Phi(s') < \Phi(s).

Each form implies the next. Monderer and Shapley wrote payoffs that players maximize; with costs the signs flip, and players move to lower values of Φ\Phi.

The definition has four direct consequences, each with a short proof.

  1. Uniqueness. Any two exact potentials differ by a constant. Two profiles are joined by a chain of unilateral deviations, one coordinate at a time, and along the chain the change of Φ\Phi is fixed by the costs.
  2. Equilibria are local minima. Call ss a local minimum of Φ\Phi if no unilateral deviation lowers Φ\Phi. With an ordinal potential, ss is a pure Nash equilibrium if and only if it is a local minimum, because a deviation lowers the deviator's cost exactly when it lowers Φ\Phi. With a generalized ordinal potential every local minimum is an equilibrium. So a finite game with a generalized ordinal potential has a pure equilibrium: a global minimum of Φ\Phi.
  3. Coordination plus dummy. A game has an exact potential Φ\Phi if and only if ci=Φ+dic_i = \Phi + d_i for functions did_i that do not depend on sis_i. If Φ\Phi is an exact potential, set di=ci−Φd_i = c_i - \Phi; a deviation of ii changes cic_i and Φ\Phi by the same amount, so it does not change did_i. The converse is immediate. So every potential game is a game of identical costs Φ\Phi plus, for each player, a cost that the player cannot influence.
  4. The cycle test. In a finite game, an exact potential exists if and only if, for every two players i≠ji \ne j, every profile ss and every a≠sia \ne s_i, b≠sjb \ne s_j, the four deviations s→(a,s−i)→(a,b,s−ij)→(b,s−j)→ss \to (a, s_{-i}) \to (a, b, s_{-ij}) \to (b, s_{-j}) \to s, made by ii, jj, ii, jj in turn, have deviators' cost changes that sum to zero.

Proof of the cycle test. If Φ\Phi exists, the four changes are the four changes of Φ\Phi around a closed path, which sum to zero. For the converse, number the strategies of each player from 0, let s0=(0,…,0)s^0 = (0, \ldots, 0), and define Φ(s)\Phi(s) as the sum of the deviators' cost changes along the canonical path from s0s^0 to ss that sets coordinate 1 to s1s_1, then coordinate 2 to s2s_2, and so on, skipping steps that change nothing. Two observations hold for any path of unilateral deviations. Swapping two adjacent steps of different players, both of which change something, does not change the sum, by the 4-cycle condition. Merging two adjacent steps of the same player, a→b→ca \to b \to c, into one step a→ca \to c does not change the sum, because both give ci(…c…)−ci(…a…)c_i(\ldots c \ldots) - c_i(\ldots a \ldots), and a merged step a→aa \to a contributes 0 and can be dropped. Now let t=(ti,s−i)t = (t_i, s_{-i}) with ti≠sit_i \ne s_i. The canonical path to ss followed by the step s→ts \to t goes from s0s^0 to tt. Swap the last step back past the steps of players n,n−1,…,i+1n, n - 1, \ldots, i + 1, then merge it with the step of player ii. The result is the canonical path to tt, with the same sum. So Φ(t)=Φ(s)+ci(t)−ci(s)\Phi(t) = \Phi(s) + c_i(t) - c_i(s), and Φ\Phi is an exact potential. □\square

Testing a finite game

The proof of uniqueness gives a direct test: fix the value at one profile, spread values along unilateral deviations, and check every deviation.

  1. EXACT-POTENTIAL(S_1, ..., S_n, c)
  2. 1Φ(s0) ← 0 for the profile s0 = (0, ..., 0); Q ← [s0]
  3. 2while Q is not empty: take a profile s from Q
  4. 3for each player i and each s_i' ≠ s_i, with t = (s_i', s_-i):
  5. 4if Φ(t) is not set: Φ(t) ← Φ(s) + c_i(t) - c_i(s); put t in Q
  6. 5else if Φ(t) ≠ Φ(s) + c_i(t) - c_i(s): return "no exact potential"
  7. 6return Φ

The search takes O(∣S∣∑i∣Si∣)O(|S| \sum_i |S_i|) steps, which is linear in the size of the cost table times ∑i∣Si∣\sum_i |S_i|. The file proofs/correctness.md proves that it returns a potential exactly when one exists. With exact rational costs no tolerance is needed.

Examples and non-examples

The prisoner's dilemma. In cost form, with C to cooperate and D to defect, the costs (player 1, player 2) are (1,1)(1, 1) at (C, C), (3,0)(3, 0) at (C, D), (0,3)(0, 3) at (D, C) and (2,2)(2, 2) at (D, D). The function Φ(C,C)=2\Phi(\text{C}, \text{C}) = 2, Φ(C,D)=Φ(D,C)=1\Phi(\text{C}, \text{D}) = \Phi(\text{D}, \text{C}) = 1, Φ(D,D)=0\Phi(\text{D}, \text{D}) = 0 is an exact potential: each change from C to D lowers the deviator's cost by 1 and lowers Φ\Phi by 1. Its minimum (D, D) is the only pure equilibrium, although (C, C) has a lower total cost, so the potential is not the social cost.

Congestion games. In an atomic congestion game, Φ(s)=∑e∑j=1xe(s)ce(j)\Phi(s) = \sum_e \sum_{j=1}^{x_e(s)} c_e(j), where xe(s)x_e(s) is the number of players on resource ee, is an exact potential. This is Rosenthal's theorem. The routing games of selfish routing with finitely many players and the Shapley network design game are special cases.

Identical costs. If all players have the same cost function ci=Fc_i = F, then FF is an exact potential. Coordination games are of this type.

An ordinal potential that is not exact. Two players choose A or B. Player 1 pays 0 at (A, A), 1 at (B, A), 0 at (A, B) and 2 at (B, B). Player 2 pays 0 at (A, A), 1 at (A, B), 0 at (B, A) and 1 at (B, B). Around the cycle (A, A), (B, A), (B, B), (A, B), (A, A), the deviators' cost changes are 11, 11, −2-2 and −1-1, which sum to −1-1, so by the cycle test there is no exact potential. But each player pays more when it plays B, so the number of players who play B is an ordinal potential, and (A, A) is the unique pure equilibrium.

Matching pennies. Player 1 pays 0 when the two coins match and 1 otherwise, and player 2 pays the opposite. From every profile one player gains by switching, so the four profiles form a cycle of strict improvements, and there is no pure equilibrium. By consequence 2, the game has no generalized ordinal potential.

An infinite non-example. One player picks s∈(0,1]s \in (0, 1] and pays ss. Then Φ(s)=s\Phi(s) = s is an exact potential, but no strategy is best and there is no equilibrium. The existence of a pure equilibrium needs a finite game, or a compact strategy space with a continuous potential.

Weighted congestion games. If players have weights and the cost of a resource depends on the total weight on it, the game can have no pure equilibrium and then has no potential (Libman and Orda 2001; Goemans, Mirrokni and Vetta 2005). With affine costs it has a weighted potential (Fotakis, Kontogiannis and Spirakis 2005).

  • Finite improvement property: every path of strict unilateral improvements is finite. A finite game has it if and only if it has a generalized ordinal potential (Monderer and Shapley 1996).
  • Pure Nash equilibrium: in a potential game, the local minima of the potential, as shown above.
  • Best-response dynamics: in a finite potential game it stops at an equilibrium, because Φ\Phi falls at each step. The number of steps can be exponential: computing a pure equilibrium of a congestion game is PLS-complete.
  • Beckmann potential: the potential of nonatomic selfish routing, an integral in place of a sum; its minimizers are the Wardrop equilibria.
  • Price of stability: the potential function method bounds it. If Φ(s)≤C(s)≤A Φ(s)\Phi(s) \le C(s) \le A\, \Phi(s) for the social cost CC and every profile ss, then a global minimizer s∗s^* of Φ\Phi has C(s∗)≤A Φ(s∗)≤A Φ(o)≤A C(o)C(s^*) \le A\, \Phi(s^*) \le A\, \Phi(o) \le A\, C(o) for an optimum oo, so the price of stability is at most AA. The harmonic bound for network design comes from this argument.
  • Fictitious play: Monderer and Shapley also showed that fictitious play converges in beliefs in games with identical interests (Journal of Economic Theory 68 (1996), 258-265), and so in weighted potential games, which have the same best responses.
Proof: The search over unilateral deviations finds an exact potential exactly when one existsfull

Let a finite cost game have players 1,…,n1, \ldots, n, strategy sets S1,…,SnS_1, \ldots, S_n and costs ci:S→Qc_i : S \to \mathbb{Q}, where S=S1×⋯×SnS = S_1 \times \cdots \times S_n. Call two profiles neighbours if they differ in the strategy of exactly one player ii; for neighbours ss and tt that differ in player ii, write δ(s,t)=ci(t)−ci(s)\delta(s, t) = c_i(t) - c_i(s). Then δ(t,s)=−δ(s,t)\delta(t, s) = -\delta(s, t). A function Φ\Phi on SS is an exact potential if and only if Φ(t)−Φ(s)=δ(s,t)\Phi(t) - \Phi(s) = \delta(s, t) for all neighbours s,ts, t.

Every profile gets a value. From the start profile s0s^0, any profile ss is reached by changing the coordinates one at a time, so the neighbour graph is connected. Line L4 gives a value to each new neighbour of a profile taken from the queue and puts it in the queue, so, unless line L5 stops the search, every profile of the connected graph gets a value and is taken from the queue once.

If the code returns Φ\Phi, it is an exact potential. Let ss and tt be neighbours. Both are taken from the queue at some time. When ss is taken, line L3 looks at tt. Either tt has no value yet and line L4 sets Φ(t)=Φ(s)+δ(s,t)\Phi(t) = \Phi(s) + \delta(s, t), or it has one and line L5 checks the same equation. So Φ(t)−Φ(s)=δ(s,t)\Phi(t) - \Phi(s) = \delta(s, t) holds for every pair of neighbours.

If the code returns None, no exact potential exists. Suppose Ψ\Psi is an exact potential. By induction on the order in which line L4 sets values, Φ(s)=Ψ(s)−Ψ(s0)\Phi(s) = \Psi(s) - \Psi(s^0) for every profile with a value: it holds at s0s^0, and line L4 sets Φ(t)=Φ(s)+δ(s,t)=Ψ(s)−Ψ(s0)+Ψ(t)−Ψ(s)\Phi(t) = \Phi(s) + \delta(s, t) = \Psi(s) - \Psi(s^0) + \Psi(t) - \Psi(s). So every check of line L5 compares Ψ(t)−Ψ(s0)\Psi(t) - \Psi(s^0) with Ψ(s)−Ψ(s0)+δ(s,t)\Psi(s) - \Psi(s^0) + \delta(s, t), which are equal, and line L5 never returns None.

Uniqueness. The same induction shows that any two exact potentials differ by a constant, because both are fixed by their value at s0s^0 along the search tree.

Cost. Each profile is taken from the queue once and has ∑i(∣Si∣−1)\sum_i (|S_i| - 1) neighbours, so the search does O(∣S∣∑i∣Si∣)O(|S| \sum_i |S_i|) steps. ■\blacksquare

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

potential_game.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/potential-game/. The authors are listed in prov/9E88DE.jsonl.

"""Exact potentials of finite cost games.

A game is a pair (sizes, cost). sizes[i] is the number of pure strategies of player i,
numbered from 0, and cost maps each profile (a tuple) to the tuple of the players' costs,
which each player minimizes. An exact potential is a function phi on profiles with
phi(t) - phi(s) = cost[t][i] - cost[s][i] whenever t differs from s only in the strategy of i.
"""

import itertools
from fractions import Fraction


def profiles(sizes):
    """All pure profiles, in lexicographic order."""
    return list(itertools.product(*[range(k) for k in sizes]))


def deviations(sizes, s):
    """Yield (i, t) for every profile t that differs from s only in the strategy of player i."""
    for i, k in enumerate(sizes):
        for a in range(k):
            if a != s[i]:
                yield i, s[:i] + (a,) + s[i + 1 :]


def exact_potential(sizes, cost):
    """Return an exact potential as a dict from profiles to Fraction, with value 0 at the first profile, or None."""
    start = tuple(0 for _ in sizes)
    phi = {start: Fraction(0)}  # @line L1
    queue = [start]
    while queue:  # @line L2
        s = queue.pop()
        for i, t in deviations(sizes, s):  # @line L3
            value = phi[s] + Fraction(cost[t][i]) - Fraction(cost[s][i])
            if t not in phi:  # @line L4
                phi[t] = value
                queue.append(t)
            elif phi[t] != value:  # @line L5
                return None
    return phi  # @line L6


def is_exact_potential(sizes, cost, phi):
    """Check the defining equation on every unilateral deviation, exactly."""
    return all(
        phi[t] - phi[s] == cost[t][i] - cost[s][i] for s in profiles(sizes) for i, t in deviations(sizes, s)
    )


def four_cycle_sums(sizes, cost):
    """Return the set of sums of the deviators' cost changes around all 4-cycles of two players."""
    sums = set()
    for s in profiles(sizes):
        for i, j in itertools.combinations(range(len(sizes)), 2):
            for a in range(sizes[i]):
                for b in range(sizes[j]):
                    if a == s[i] or b == s[j]:
                        continue
                    p = s[:i] + (a,) + s[i + 1 :]
                    q = p[:j] + (b,) + p[j + 1 :]
                    r = s[:j] + (b,) + s[j + 1 :]
                    total = (
                        (cost[p][i] - cost[s][i])
                        + (cost[q][j] - cost[p][j])
                        + (cost[r][i] - cost[q][i])
                        + (cost[s][j] - cost[r][j])
                    )
                    sums.add(Fraction(total))
    return sums


def pure_nash(sizes, cost):
    """All pure Nash equilibria, by brute force over unilateral deviations."""
    return [s for s in profiles(sizes) if all(cost[t][i] >= cost[s][i] for i, t in deviations(sizes, s))]
test_potential_game.py 111 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/potential-game/. The authors are listed in prov/9E88DE.jsonl.

import itertools
import random
from fractions import Fraction

from potential_game import (
    deviations,
    exact_potential,
    four_cycle_sums,
    is_exact_potential,
    profiles,
    pure_nash,
)

C, D = 0, 1
PD = {(C, C): (1, 1), (C, D): (3, 0), (D, C): (0, 3), (D, D): (2, 2)}
MATCHING_PENNIES = {(0, 0): (0, 1), (1, 1): (0, 1), (0, 1): (1, 0), (1, 0): (1, 0)}
ORDINAL_ONLY = {(0, 0): (0, 0), (1, 0): (1, 0), (0, 1): (0, 1), (1, 1): (2, 1)}


def shifted(phi, s):
    return {t: v - phi[s] for t, v in phi.items()}


def test_prisoners_dilemma():
    phi = exact_potential((2, 2), PD)
    phi = {t: v + 2 for t, v in phi.items()}
    assert phi == {(C, C): 2, (C, D): 1, (D, C): 1, (D, D): 0}
    assert pure_nash((2, 2), PD) == [(D, D)]


def test_no_exact_potential():
    assert exact_potential((2, 2), MATCHING_PENNIES) is None
    assert pure_nash((2, 2), MATCHING_PENNIES) == []
    assert exact_potential((2, 2), ORDINAL_ONLY) is None
    assert four_cycle_sums((2, 2), ORDINAL_ONLY) == {1, -1}
    count_b = {s: sum(s) for s in ORDINAL_ONLY}
    for s in ORDINAL_ONLY:
        for i, t in deviations((2, 2), s):
            assert (ORDINAL_ONLY[t][i] < ORDINAL_ONLY[s][i]) == (count_b[t] < count_b[s])


def random_congestion_game(rng, n, r, k):
    """n players, r resources with cost tables, k strategies (nonempty resource sets) per player."""
    table = [[rng.randint(0, 6) for _ in range(n)] for _ in range(r)]
    subsets = [frozenset(c) for size in range(1, r + 1) for c in itertools.combinations(range(r), size)]
    strategies = [rng.sample(subsets, k) for _ in range(n)]
    sizes = tuple(k for _ in range(n))
    cost, rosenthal = {}, {}
    for s in profiles(sizes):
        load = [sum(1 for i in range(n) if e in strategies[i][s[i]]) for e in range(r)]
        cost[s] = tuple(sum(table[e][load[e] - 1] for e in strategies[i][s[i]]) for i in range(n))
        rosenthal[s] = Fraction(sum(table[e][j] for e in range(r) for j in range(load[e])))
    return sizes, cost, rosenthal


def test_congestion_games_have_the_rosenthal_potential():
    rng = random.Random(1973)
    for _ in range(40):
        n = rng.randint(2, 4)
        sizes, cost, rosenthal = random_congestion_game(rng, n, rng.randint(2, 4), rng.randint(2, 3))
        for s in profiles(sizes):
            for i, t in deviations(sizes, s):
                assert rosenthal[t] - rosenthal[s] == cost[t][i] - cost[s][i]
        phi = exact_potential(sizes, cost)
        assert phi is not None
        start = profiles(sizes)[0]
        assert shifted(phi, start) == shifted(rosenthal, start)
        low = min(phi.values())
        minimizers = [s for s in phi if phi[s] == low]
        assert set(minimizers) <= set(pure_nash(sizes, cost))


def test_coordination_plus_dummy():
    rng = random.Random(1996)
    for _ in range(40):
        sizes = tuple(rng.randint(2, 4) for _ in range(rng.randint(2, 3)))
        base = {s: rng.randint(-5, 5) for s in profiles(sizes)}
        dummy = [dict() for _ in sizes]
        cost = {}
        for s in profiles(sizes):
            parts = []
            for i in range(len(sizes)):
                key = s[:i] + s[i + 1 :]
                if key not in dummy[i]:
                    dummy[i][key] = rng.randint(-5, 5)
                parts.append(base[s] + dummy[i][key])
            cost[s] = tuple(parts)
        phi = exact_potential(sizes, cost)
        assert is_exact_potential(sizes, cost, phi)
        start = profiles(sizes)[0]
        assert shifted(phi, start) == shifted({s: Fraction(v) for s, v in base.items()}, start)


def test_four_cycle_characterization():
    rng = random.Random(44)
    seen = {True: 0, False: 0}
    for trial in range(150):
        sizes = tuple(rng.randint(2, 3) for _ in range(rng.randint(2, 3)))
        base = {s: rng.randint(0, 4) for s in profiles(sizes)}
        cost = {s: tuple(base[s] for _ in sizes) for s in base}
        if trial % 2:
            s = rng.choice(profiles(sizes))
            i = rng.randrange(len(sizes))
            cost[s] = cost[s][:i] + (cost[s][i] + rng.randint(1, 3),) + cost[s][i + 1 :]
        exists = exact_potential(sizes, cost) is not None
        assert exists == (four_cycle_sums(sizes, cost) <= {0})
        seen[exists] += 1
    assert seen[True] > 0 and seen[False] > 0

References

  1. Dov Monderer and Lloyd S. Shapley, Potential games, Games and Economic Behavior 14(1) (1996), 124-143, Section 2 (exact, weighted, ordinal and generalized ordinal potentials, the finite improvement property, the cycle test and the uniqueness of the potential) and the isomorphism between finite potential games and congestion games
  2. Robert W. Rosenthal, A class of games possessing pure-strategy Nash equilibria, International Journal of Game Theory 2 (1973), 65-67, congestion games and the potential function that proves they have pure equilibria
  3. Tim Roughgarden, Twenty Lectures on Algorithmic Game Theory, Cambridge University Press, 2016, Lecture 13 (potential games and the existence of pure Nash equilibria) and Lecture 16 (best-response dynamics)
  4. Noam Nisan, Tim Roughgarden, Eva Tardos and Vijay V. Vazirani (eds.), Algorithmic Game Theory, Cambridge University Press, 2007, Chapter 19 (Eva Tardos and Tom Wexler, Network formation games and the potential function method)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH2 full proof
  • correctness: no review record reviews/9E88DE/proof-correctness.yaml
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/9E88DE/text.yaml