Algorithm Search⌘K

Algorithmadvanced

Computing an optimal strategy to commit to

Also called Conitzer-Sandholm multiple LPs algorithm.

Finds the leader's optimal mixed commitment in a two-player normal-form game by one linear program per follower action.

Time
poly(m, n, L) worst
Space
O(m n) extra
Where
L = the bit length of the payoffs; m = the number of pure strategies of the leader; n = the number of pure strategies of the follower
Properties
deterministicexactofflineiterative
Origin
Vincent Conitzer, Tuomas Sandholm, 2006

This algorithm computes the best mixed strategy for a leader to commit to in a two-player game in normal form, when the follower sees the commitment and plays a best response. It solves one linear program for each pure strategy jj of the follower: among the mixed strategies to which jj is a best response, find the one that is best for the leader; then take the best of these. The solution concept, the Stackelberg equilibrium, has its own page, and security games are the model in which this computation is used most, with a compact strategy space for the defender. Stackelberg routing is a different use of the word, for a leader who controls part of the traffic in a network.

In plain words

Suppose you must announce how you will randomize before the other player moves, and the other player will then do what is best for them. You can use this to your advantage: you choose your mix so that the reply you like is the one they want. For each possible reply, ask: among all mixes that make this reply a best choice for them, which mix is best for me? Each question is a small linear program. Answer all of them and keep the best. If the other player is indifferent between replies, assume they pick the one you prefer; this is the usual rule, and without it the best mix may not exist.

The problem

Input: an m×nm \times n bimatrix game (A,B)(A, B), where the leader (row player) has mm pure strategies and payoffs AA, and the follower (column player) has nn pure strategies and payoffs BB. Here mm and nn count strategies, not players. The leader commits to x∈Δmx \in \Delta_m. The follower sees xx and plays a best response j∈arg⁡max⁡k(BTx)kj \in \arg\max_k (B^{\mathsf T} x)_k; a pure best response always exists, and ties are broken in the leader's favor. Output: an xx and jj that maximize the leader's payoff (ATx)j(A^{\mathsf T} x)_j, which is a strong Stackelberg equilibrium.

The algorithm

  1. OPTIMAL-COMMITMENT(A, B)
  2. 1for each column j = 1..n:
  3. 2LP_j: maximize Σ_i x_i A[i][j]
  4. subject to Σ_i x_i (B[i][k] - B[i][j]) ≤ 0 for every k ≠ j ▷ j is a best response
  5. Σ_i x_i = 1, x ≥ 0
  6. 3if LP_j is infeasible: skip j ▷ no mixed strategy makes j a best response
  7. 4keep (value of LP_j, its solution x, j) if the value is the largest so far
  8. 5return the kept (value, x, j)

The constraints of LP_j describe the region of the simplex where jj is a best response. These regions cover the simplex, so at least one LP is feasible. Each region is a polytope, and the leader's payoff against jj is linear on it, so each LP has an optimum at a vertex of its region.

Example

Let A=(1302)A = \begin{pmatrix} 1 & 3 \\ 0 & 2 \end{pmatrix} and B=(1001)B = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}, with rows UU, DD for the leader and columns ll, rr for the follower. For the leader, UU strictly dominates DD, so the only Nash equilibrium is (U,l)(U, l), with payoff 1 to the leader.

LP best response region objective optimum
j=lj = l xD≤xUx_D \le x_U xUx_U x=(1,0)x = (1, 0), value 1
j=rj = r xU≤xDx_U \le x_D 3xU+2xD3 x_U + 2 x_D x=(1/2,1/2)x = (1/2, 1/2), value 5/25/2

The algorithm returns x=(1/2,1/2)x = (1/2, 1/2) with the follower playing rr: the follower is indifferent and breaks the tie for the leader, who gets 5/25/2. Committing to the pure strategy DD gives 2, and the Nash equilibrium gives 1. The optimal commitment puts as much weight on UU as it can while rr stays a best response, which is an instance of the indifference principle at the boundary of a region.

Correctness

For every x∈Δmx \in \Delta_m, the follower's choice jj is a best response to xx, so xx is feasible for LP_j, and the leader's payoff (ATx)j(A^{\mathsf T} x)_j is at most the value of LP_j. So no commitment gives more than the largest LP value. Conversely, the optimal xx of the LP with the largest value makes jj a best response, and if the follower has another best response kk that is better for the leader, xx is also feasible for LP_k with a larger value, which is impossible. So with ties broken for the leader, the follower plays a column that gives the leader exactly the largest LP value. The proof file has the details, and also shows that this value is at least the leader's payoff in every Nash equilibrium.

Proof: The best of the n LPs is the leader's optimal commitment, and it is at least every Nash equilibrium payofffull

Let (A,B)(A, B) be an m×nm \times n bimatrix game with the leader as the row player. For x∈Δmx \in \Delta_m let BR(x)=arg⁡max⁡k(BTx)k\mathrm{BR}(x) = \arg\max_k (B^{\mathsf T} x)_k, the set of the follower's pure best responses, and let the leader's commitment payoff be V(x)=max⁡k∈BR(x)(ATx)kV(x) = \max_{k \in \mathrm{BR}(x)} (A^{\mathsf T} x)_k (ties broken for the leader). The goal is V∗=sup⁡x∈ΔmV(x)V^* = \sup_{x \in \Delta_m} V(x) and an xx that attains it. For each jj, let Rj={x∈Δm:j∈BR(x)}R_j = \{x \in \Delta_m : j \in \mathrm{BR}(x)\}, which is the feasible set of LP_j, and let vj=max⁡x∈Rj(ATx)jv_j = \max_{x \in R_j} (A^{\mathsf T} x)_j when Rj≠∅R_j \ne \emptyset.

Lemma 1 (the LPs are well defined). Each RjR_j is a polytope, possibly empty, and the sets R1,…,RnR_1, \ldots, R_n cover Δm\Delta_m. Each LP_j with Rj≠∅R_j \ne \emptyset has an optimum.

Proof. RjR_j is the simplex cut by the n−1n - 1 linear inequalities (BTx)k≤(BTx)j(B^{\mathsf T} x)_k \le (B^{\mathsf T} x)_j, so it is a bounded polyhedron. For every xx, the set BR(x)\mathrm{BR}(x) is nonempty because it is the set of maximizers of a finite list, so xx lies in some RjR_j. A linear function on a nonempty polytope attains its maximum. □\square

Theorem. Let j∗j^* be a column with the largest vjv_j and x∗x^* an optimal solution of LP_j∗j^*, as returned by lines L1 to L5. Then V(x∗)=vj∗=V∗V(x^*) = v_{j^*} = V^*, and the follower's tie-broken best response to x∗x^* gives the leader exactly vj∗v_{j^*}.

Proof. Upper bound: for any xx, let k∈BR(x)k \in \mathrm{BR}(x) be the follower's choice. Then x∈Rkx \in R_k, so (ATx)k≤vk≤vj∗(A^{\mathsf T} x)_k \le v_k \le v_{j^*}. Hence V(x)≤vj∗V(x) \le v_{j^*} for all xx. Attainment: x∗∈Rj∗x^* \in R_{j^*}, so j∗∈BR(x∗)j^* \in \mathrm{BR}(x^*) and V(x∗)≥(ATx∗)j∗=vj∗V(x^*) \ge (A^{\mathsf T} x^*)_{j^*} = v_{j^*}. With the upper bound, V(x∗)=vj∗V(x^*) = v_{j^*}, so V∗=vj∗V^* = v_{j^*} is attained at x∗x^*. If the tie rule picks some k∈BR(x∗)k \in \mathrm{BR}(x^*), the leader gets V(x∗)=vj∗V(x^*) = v_{j^*} by the definition of VV. □\square

Termination. The loop runs nn times, and each LP is solved by the simplex method with Bland's rule, which ends on every input.

Proposition (pure follower responses suffice). If the follower may also play a mixed best response yy, the leader's best payoff for a fixed xx is still V(x)V(x).

Proof. A mixed best response yy puts weight only on BR(x)\mathrm{BR}(x), by the best response condition, so xTAy=∑kyk(ATx)k≤max⁡k∈BR(x)(ATx)k=V(x)x^{\mathsf T} A y = \sum_k y_k (A^{\mathsf T} x)_k \le \max_{k \in \mathrm{BR}(x)} (A^{\mathsf T} x)_k = V(x). □\square

Proposition (commitment beats Nash). For every Nash equilibrium (x^,y^)(\hat x, \hat y) of (A,B)(A, B), V∗≥x^TAy^V^* \ge \hat x^{\mathsf T} A \hat y.

Proof. In the equilibrium y^\hat y is a best response to x^\hat x, so by the previous proposition x^TAy^≤V(x^)≤V∗\hat x^{\mathsf T} A \hat y \le V(\hat x) \le V^*. □\square

The same argument with x^\hat x pure shows that V∗V^* is at least the value of every pure commitment.

Proposition (zero-sum games). If B=−AB = -A, then V∗V^* equals the value vv of the matrix game AA.

Proof. For B=−AB = -A, the follower's best responses to xx minimize (ATx)k(A^{\mathsf T} x)_k, so V(x)=min⁡k(ATx)kV(x) = \min_k (A^{\mathsf T} x)_k and V∗=max⁡xmin⁡k(ATx)kV^* = \max_x \min_k (A^{\mathsf T} x)_k, which is the maximin value. By the minimax theorem it equals vv. □\square

Complexity

The algorithm solves nn linear programs, each with mm variables and nn constraints, so the time is nn times the time of one LP. With a polynomial-time LP method this is polynomial in mm, nn and the bit length LL of the payoffs. The code uses the exact simplex method with rational numbers. The space is O(mn)O(m n) for one LP at a time.

For comparison, finding a Nash equilibrium of a bimatrix game is PPAD-complete, so commitment is easier to compute than a Nash equilibrium of the same game.

Properties

  • At least as good as any Nash equilibrium. The leader's commitment value is at least the leader's payoff in every Nash equilibrium of (A,B)(A, B), and at least the value of the best pure commitment.
  • Zero-sum games. If B=−AB = -A, the commitment value is the value of the game: committing to a maximin strategy is optimal, and the minimax theorem says the leader cannot do better.
  • Exact. All LP data are rational, so the optimal xx is rational and the code finds it exactly.
  • Follower plays pure. It is enough to consider pure best responses: a mixed best response is a mixture of pure ones and gives the leader at most the best of them.

Variants and improvements

  • One LP. The nn LPs can be merged into one LP over a correlated distribution of the pairs (leader action, follower action), with a best response constraint for each recommended follower action. For two players its value equals the best value of the nn LPs: in a feasible distribution, the leader's conditional strategy given each recommended follower action jj is feasible for LP_j, so the leader's payoff is an average of values that are each at most the best LP value.
  • Bayesian followers. With several follower types and a prior over them, finding the optimal commitment is NP-hard (Conitzer and Sandholm). The usual exact method is a mixed integer program with one binary variable for each type and action, as in the DOBSS algorithm of Paruchuri and others; see Bayesian games.
  • Security games. When the leader's pure strategies are allocations of kk resources to TT targets, mm is exponential, but the payoffs depend only on the coverage of each target, so the LPs can be written with TT coverage variables; see security games.
  • Weak Stackelberg. If the follower breaks ties against the leader, the supremum of the leader's payoff need not be attained. The strong value can be approached from inside a region by moving slightly away from its boundary, where the follower's best response is unique.

When to use it

Use it when one player can credibly announce a randomized policy before the other acts, as in patrols, inspections, audits and screening, and the game is given in normal form with a modest number of actions for both players. For many follower types or compact strategy spaces, use the MIP and security game methods instead.

Pitfalls

  • Tie-breaking. The optimum usually makes the follower indifferent between two or more actions, so the tie rule matters. In practice the leader moves a little into the region of the preferred action, at a small loss, so that the follower's best response is strict.
  • Leader's payoffs, follower's constraints. The objective of LP_j uses AA and the constraints use BB; mixing them up gives the follower's commitment problem instead.
  • Not a Nash equilibrium. The pair (x,j)(x, j) need not be a Nash equilibrium of the simultaneous game: in the example, the leader's commitment x=(1/2,1/2)x = (1/2, 1/2) is not a best response to rr.
  • Commitment must be credible. The model assumes the follower observes the mixed strategy, or learns it over time, but not the outcome of the randomization before acting.

Implementations

The Python code builds LP_j for each column and solves it with the shared exact simplex code. A helper computes the follower's best response with ties broken for the leader. The tests check the example above, an infeasible LP for a dominated column, and the tie rule. On 150 random games, the result is compared with a brute-force search over the vertices of all best response regions. The tests also check that the commitment value is at least every Nash equilibrium payoff found by support enumeration and every pure commitment, and that it equals the minimax value on 100 random zero-sum games.

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.

agtlp.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the algorithmic game theory pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Exact linear programming in Fraction, by the two-phase simplex method with Bland's rule.

lp_max(c, A_ub, b_ub, A_eq=None, b_eq=None) maximizes c x subject to A_ub x <= b_ub,
A_eq x = b_eq and x >= 0. lp_min does the same for minimization. Free variables must be
split by the caller (x = x+ - x-). Every input number is converted to Fraction, so the
result is exact: there is no tolerance anywhere.

Both functions return (status, x, value, dual). status is "optimal", "infeasible" or
"unbounded". When status is not "optimal", x, value and dual are None. dual has one entry
per constraint, the A_ub rows first and then the A_eq rows. It is the vector of shadow
prices: the value is sum_i b_i dual_i (strong duality). For lp_max, dual_i >= 0 on the
A_ub rows and A^T dual >= c. For lp_min, dual_i <= 0 on the A_ub rows and A^T dual <= c.
The entries for the A_eq rows have no sign condition.

Bland's rule (the smallest improving column enters, and among the rows with the smallest
ratio the one with the smallest basic variable leaves) makes the method finite on every
input, degenerate inputs included. There is no game algorithm in this module.
"""

from fractions import Fraction


def _frac(v):
    return v if isinstance(v, Fraction) else Fraction(v)


def _pivot(T, obj, basis, r, j):
    p = T[r][j]
    row = [v / p for v in T[r]]
    T[r] = row
    for k in range(len(T)):
        f = T[k][j]
        if k != r and f != 0:
            T[k] = [a - f * b for a, b in zip(T[k], row)]
    f = obj[j]
    if f != 0:
        obj[:] = [a - f * b for a, b in zip(obj, row)]
    basis[r] = j


def _simplex(T, obj, basis, ncols):
    """Maximize. obj[j] is the reduced cost of column j and obj[-1] is minus the value."""
    while True:
        enter = next((j for j in range(ncols) if obj[j] > 0), None)
        if enter is None:
            return "optimal"
        best = None
        for r, row in enumerate(T):
            a = row[enter]
            if a > 0:
                key = (row[-1] / a, basis[r])
                if best is None or key < best[0]:
                    best = (key, r)
        if best is None:
            return "unbounded"
        _pivot(T, obj, basis, best[1], enter)


def _objective_row(cost, T, basis):
    obj = list(cost) + [Fraction(0)]
    for r, j in enumerate(basis):
        f = obj[j]
        if f != 0:
            obj = [a - f * b for a, b in zip(obj, T[r])]
    return obj


def _any_solution(M, rhs, nvars):
    """Return one solution y of M y = rhs (a consistent system), with the free variables 0."""
    rows = [list(M[k]) + [rhs[k]] for k in range(len(M))]
    pivots = []
    r = 0
    for col in range(nvars):
        p = next((k for k in range(r, len(rows)) if rows[k][col] != 0), None)
        if p is None:
            continue
        rows[r], rows[p] = rows[p], rows[r]
        pv = rows[r][col]
        rows[r] = [v / pv for v in rows[r]]
        for k in range(len(rows)):
            f = rows[k][col]
            if k != r and f != 0:
                rows[k] = [a - f * b for a, b in zip(rows[k], rows[r])]
        pivots.append(col)
        r += 1
        if r == len(rows):
            break
    y = [Fraction(0)] * nvars
    for k, col in enumerate(pivots):
        y[col] = rows[k][-1]
    return y


def _matrix(A, width, name):
    A = [[_frac(v) for v in row] for row in (A or [])]
    if any(len(row) != width for row in A):
        raise ValueError(name + " must have one column per variable")
    return A


def lp_max(c, A_ub, b_ub, A_eq=None, b_eq=None):
    """Maximize c x subject to A_ub x <= b_ub, A_eq x = b_eq and x >= 0, exactly."""
    c = [_frac(v) for v in c]
    n = len(c)
    A_ub = _matrix(A_ub, n, "A_ub")
    A_eq = _matrix(A_eq, n, "A_eq")
    b_ub = [_frac(v) for v in (b_ub or [])]
    b_eq = [_frac(v) for v in (b_eq or [])]
    if len(b_ub) != len(A_ub) or len(b_eq) != len(A_eq):
        raise ValueError("b_ub and b_eq must have one entry per row")
    m1, m2 = len(A_ub), len(A_eq)
    m = m1 + m2
    width = n + m1
    # Rows in the original orientation, with a slack column for each A_ub row.
    orig = [A_ub[i] + [Fraction(int(k == i)) for k in range(m1)] for i in range(m1)]
    orig += [A_eq[i] + [Fraction(0)] * m1 for i in range(m2)]
    rhs = b_ub + b_eq
    # A row gets an artificial variable if it is an equation or if its right side is negative.
    need = [i >= m1 or rhs[i] < 0 for i in range(m)]
    nart = sum(need)
    T, basis = [], []
    a = 0
    for i in range(m):
        sign = -1 if rhs[i] < 0 else 1
        row = [sign * v for v in orig[i]] + [Fraction(0)] * nart + [sign * rhs[i]]
        if need[i]:
            row[width + a] = Fraction(1)
            basis.append(width + a)
            a += 1
        else:
            basis.append(n + i)
        T.append(row)
    if nart:
        # Phase 1: maximize minus the sum of the artificial variables.
        obj = _objective_row([Fraction(0)] * width + [Fraction(-1)] * nart, T, basis)
        _simplex(T, obj, basis, width + nart)
        if obj[-1] != 0:
            return "infeasible", None, None, None
        keep = []
        for r in range(m):
            if basis[r] >= width:
                j = next((j for j in range(width) if T[r][j] != 0), None)
                if j is None:
                    continue  # the row is a combination of the other rows
                _pivot(T, [Fraction(0)] * (width + nart + 1), basis, r, j)
            keep.append(r)
        T = [T[r][:width] + [T[r][-1]] for r in keep]
        basis = [basis[r] for r in keep]
    # Phase 2: the original objective, without the artificial columns.
    cost = c + [Fraction(0)] * m1
    obj = _objective_row(cost, T, basis)
    if _simplex(T, obj, basis, width) == "unbounded":
        return "unbounded", None, None, None
    x = [Fraction(0)] * n
    for r, j in enumerate(basis):
        if j < n:
            x[j] = T[r][-1]
    value = sum((ci * xi for ci, xi in zip(c, x)), Fraction(0))
    # The dual solves y^T A_B = c_B, where A_B holds the basic columns of the original rows.
    M = [[orig[i][j] for i in range(m)] for j in basis]
    dual = _any_solution(M, [cost[j] for j in basis], m)
    return "optimal", x, value, dual


def lp_min(c, A_ub, b_ub, A_eq=None, b_eq=None):
    """Minimize c x subject to A_ub x <= b_ub, A_eq x = b_eq and x >= 0, exactly."""
    status, x, value, dual = lp_max([-_frac(v) for v in c], A_ub, b_ub, A_eq, b_eq)
    if status != "optimal":
        return status, None, None, None
    return status, x, -value, [-v for v in dual]
stackelberg_commitment_algorithm.py 48 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/stackelberg-commitment-algorithm/. The authors are listed in prov/3741KV.jsonl.
"""The optimal mixed strategy to commit to in a bimatrix game, by one LP per follower action.

The leader is the row player with payoff matrix A, the follower is the column player with
payoff matrix B, both m x n. The leader commits to a mixed strategy x; the follower sees x
and plays a best response, breaking ties in the leader's favor (the strong Stackelberg
convention). For each column j, an LP finds the best x among those to which j is a best
response; the answer is the best of these LPs.
"""

from fractions import Fraction

from agtlp import lp_max


def best_for_column(A, B, j):
    """Return (value, x) of max x . A[:, j] over the x in the simplex with j a best response to x.

    Return None if no mixed strategy makes j a best response.
    """
    m, n = len(A), len(A[0])
    c = [A[i][j] for i in range(m)]
    # sum_i x_i B[i][k] <= sum_i x_i B[i][j] for every other column k.
    A_ub = [[B[i][k] - B[i][j] for i in range(m)] for k in range(n) if k != j]  # @line L2
    status, x, value, _ = lp_max(c, A_ub, [0] * len(A_ub), [[1] * m], [1])
    if status != "optimal":  # @line L3
        return None
    return value, x


def optimal_commitment(A, B):
    """Return (value, x, j): the leader's optimal commitment x, its value, and the follower's column j."""
    best = None
    for j in range(len(A[0])):  # @line L1
        res = best_for_column(A, B, j)
        if res is not None and (best is None or res[0] > best[0]):  # @line L4
            best = (res[0], res[1], j)
    return best  # @line L5


def follower_response(A, B, x):
    """The follower's best response to x, with ties broken in the leader's favor."""
    m, n = len(A), len(A[0])
    pay = [sum(Fraction(x[i]) * B[i][k] for i in range(m)) for k in range(n)]
    top = max(pay)
    ties = [k for k in range(n) if pay[k] == top]
    return max(ties, key=lambda k: (sum(Fraction(x[i]) * A[i][k] for i in range(m)), -k))
test_stackelberg_commitment_algorithm.py 152 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/stackelberg-commitment-algorithm/. The authors are listed in prov/3741KV.jsonl.

import random
from fractions import Fraction
from itertools import combinations

from agtlp import lp_max
from stackelberg_commitment_algorithm import best_for_column, follower_response, optimal_commitment

F = Fraction


def solve_square(K, b):
    r = len(K)
    rows = [[F(v) for v in K[k]] + [F(b[k])] for k in range(r)]
    for col in range(r):
        p = next((k for k in range(col, r) if rows[k][col] != 0), None)
        if p is None:
            return None
        rows[col], rows[p] = rows[p], rows[col]
        rows[col] = [v / rows[col][col] for v in rows[col]]
        for k in range(r):
            f = rows[k][col]
            if k != col and f != 0:
                rows[k] = [a - f * c for a, c in zip(rows[k], rows[col])]
    return [rows[k][-1] for k in range(r)]


def leader_payoff(A, x, j):
    return sum(F(x[i]) * A[i][j] for i in range(len(A)))


def brute_force(A, B):
    """Best leader payoff over the vertices of all regions {x in simplex : j is a best response}."""
    m, n = len(A), len(A[0])
    best = None
    for j in range(n):
        # Constraints: x_i >= 0 and (B[:, j] - B[:, k]) . x >= 0; a vertex makes m - 1 of them tight.
        cons = [[int(t == i) for t in range(m)] for i in range(m)]
        cons += [[B[i][j] - B[i][k] for i in range(m)] for k in range(n) if k != j]
        for S in combinations(range(len(cons)), m - 1):
            x = solve_square([cons[s] for s in S] + [[1] * m], [0] * (m - 1) + [1])
            if x is None or any(sum(F(c[i]) * x[i] for i in range(m)) < 0 for c in cons):
                continue
            v = leader_payoff(A, x, j)
            if best is None or v > best:
                best = v
    return best


def support_enumeration(A, B):
    m, n = len(A), len(A[0])
    out = []
    for k in range(1, min(m, n) + 1):
        for I in combinations(range(m), k):
            for J in combinations(range(n), k):
                sy = solve_square([[A[i][j] for j in J] + [-1] for i in I] + [[1] * k + [0]], [0] * k + [1])
                sx = solve_square([[B[i][j] for i in I] + [-1] for j in J] + [[1] * k + [0]], [0] * k + [1])
                if sy is None or sx is None or min(sy[:k]) < 0 or min(sx[:k]) < 0:
                    continue
                x, y = [F(0)] * m, [F(0)] * n
                for i, p in zip(I, sx):
                    x[i] = p
                for j, p in zip(J, sy):
                    y[j] = p
                if all(sum(A[i][j] * y[j] for j in J) <= sy[k] for i in range(m)) and \
                        all(sum(x[i] * B[i][j] for i in I) <= sx[k] for j in range(n)):
                    out.append((x, y, sy[k]))
    return out


def random_game(rng, m, n, lo=-9, hi=9):
    return ([[rng.randint(lo, hi) for _ in range(n)] for _ in range(m)],
            [[rng.randint(lo, hi) for _ in range(n)] for _ in range(m)])


def check(A, B, value, x, j):
    m, n = len(A), len(A[0])
    assert all(v >= 0 for v in x) and sum(x) == 1
    pay = [sum(x[i] * B[i][k] for i in range(m)) for k in range(n)]
    assert pay[j] == max(pay)
    assert leader_payoff(A, x, j) == value
    assert leader_payoff(A, x, follower_response(A, B, x)) == value


def test_page_example():
    A = [[1, 3], [0, 2]]
    B = [[1, 0], [0, 1]]
    assert best_for_column(A, B, 0) == (1, [1, 0])
    assert best_for_column(A, B, 1) == (F(5, 2), [F(1, 2), F(1, 2)])
    value, x, j = optimal_commitment(A, B)
    assert (value, x, j) == (F(5, 2), [F(1, 2), F(1, 2)], 1)
    check(A, B, value, x, j)
    # The only Nash equilibrium gives the leader 1, and committing to a pure strategy gives 2.
    assert [e[2] for e in support_enumeration(A, B)] == [1]
    assert max(leader_payoff(A, [int(t == i) for t in range(2)],
                             follower_response(A, B, [int(t == i) for t in range(2)])) for i in range(2)) == 2


def test_infeasible_column():
    # Column 1 is strictly dominated for the follower, so its LP is infeasible.
    A = [[0, 9], [1, 9]]
    B = [[1, 0], [1, 0]]
    assert best_for_column(A, B, 1) is None
    assert optimal_commitment(A, B) == (1, [0, 1], 0)


def test_random_games_against_vertex_enumeration():
    rng = random.Random(5150)
    for _ in range(150):
        A, B = random_game(rng, rng.randint(1, 4), rng.randint(1, 4))
        value, x, j = optimal_commitment(A, B)
        check(A, B, value, x, j)
        assert value == brute_force(A, B)


def test_commitment_beats_every_nash_and_pure_commitment():
    rng = random.Random(77)
    for _ in range(100):
        m, n = rng.randint(1, 3), rng.randint(1, 3)
        A, B = random_game(rng, m, n)
        value, _, _ = optimal_commitment(A, B)
        eqs = support_enumeration(A, B)
        assert eqs
        for x, y, _ in eqs:
            assert value >= sum(x[i] * A[i][k] * y[k] for i in range(m) for k in range(n))
        for i in range(m):
            e = [int(t == i) for t in range(m)]
            assert value >= leader_payoff(A, e, follower_response(A, B, e))


def test_zero_sum_value_is_the_minimax_value():
    rng = random.Random(404)
    for _ in range(100):
        m, n = rng.randint(1, 4), rng.randint(1, 4)
        A = [[rng.randint(-9, 9) for _ in range(n)] for _ in range(m)]
        B = [[-v for v in row] for row in A]
        value, _, _ = optimal_commitment(A, B)
        # maximize v+ - v- subject to v+ - v- <= sum_i x_i A[i][k] for every k, sum x = 1.
        c = [1, -1] + [0] * m
        A_ub = [[1, -1] + [-A[i][k] for i in range(m)] for k in range(n)]
        status, _, minimax, _ = lp_max(c, A_ub, [0] * n, [[0, 0] + [1] * m], [1])
        assert status == "optimal" and value == minimax


def test_ties_are_broken_for_the_leader():
    # The follower is indifferent between the columns at every x; the leader gets the larger column.
    A = [[1, 4], [2, 0]]
    B = [[5, 5], [5, 5]]
    value, x, j = optimal_commitment(A, B)
    assert (value, x, j) == (4, [1, 0], 1)

History

Heinrich von Stackelberg studied leader-follower competition in markets in 1934, with pure strategies. Conitzer and Sandholm (2006) gave the multiple LPs algorithm for mixed commitments in two-player normal-form games and showed that the problem is NP-hard for Bayesian games with several follower types. Mixed integer programs for Bayesian followers and compact programs for resource allocation followed, and were used in deployed security systems; see security games.

References

  1. Vincent Conitzer and Tuomas Sandholm, Computing the optimal strategy to commit to, Proceedings of the 7th ACM Conference on Electronic Commerce (EC 2006), 82-90, the multiple LPs algorithm for two-player normal-form games and the NP-hardness for Bayesian games with several follower types
  2. Security and Game Theory, Stackelberg security games, strong Stackelberg equilibria and the algorithms used in deployed systems

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 proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
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)
WritingW2 basic
  • at least three sources
  • a scene preset for the example