Algorithm Search⌘K

Algorithmresearch

Approximate maximin share allocation

Also called Garg-Taki algorithm, 3/4 MMS algorithm.

Gives every agent at least a constant fraction, such as 3/4, of its maximin share in polynomial time by reductions and bag filling.

Time
O(n^2 T + n m log m + n^2 (n + m)) worst
Space
O(n m) extra
Where
T = the time of one maximin share computation; m = the number of goods; n = the number of agents
Properties
deterministicofflineiterative

An approximate maximin share allocation gives every agent at least a fixed fraction α\alpha of its maximin share (MMS). Exact MMS allocations can fail to exist (nonexistence of MMS allocations), so the goal is the largest α\alpha for which an α\alpha-MMS allocation always exists, and an algorithm that finds one. This page gives the algorithm of Garg and Taki (2021) in the simplified form of Akrami, Garg, Sharma and Taki (2023): it sorts the instance, gives away a few large goods by fixed rules, scales the values so that every share is 1, and then fills nn bags with goods until each agent accepts one. It gives every agent 3/43/4 of its share. The best published factor is 10/13≈0.76910/13 \approx 0.769 (SODA 2026), and no factor above 39/4039/40 is possible.

In plain words

Each person has a fair-share number: the value they could ensure by cutting the items into piles and taking the worst pile. We cannot always give everybody that much, so we aim for three quarters of it.

First, big items are handled. If one item, or a small fixed group of the largest items, already gives some person three quarters of their share, that person takes it and leaves. Taking big items away never hurts the others' shares.

After that, every item is small. Each remaining person scales their values so that their share is exactly 1. We prepare one bag per person, each with one large and one smaller item. Then we add items to a bag, one at a time, until some person says "this bag is worth three quarters to me" and leaves with it. The items never run out before everybody has a bag.

The problem

There are nn agents and mm indivisible goods, with additive values vij≥0v_{ij} \ge 0. For nn bundles, the maximin share of agent ii is MMSi=max⁡(P1,…,Pn)min⁡kvi(Pk)\mathrm{MMS}_i = \max_{(P_1, \dots, P_n)} \min_k v_i(P_k), the maximum over all partitions of the goods. The goal is an allocation AA with vi(Ai)≥34MMSiv_i(A_i) \ge \frac{3}{4} \mathrm{MMS}_i for every agent.

Three tools reduce the instance.

  • Ordering. An instance is ordered if one order of the goods sorts every agent's values in decreasing order. The ordered version of an instance gives position qq to every agent at the value of its qq-th largest good. An α\alpha-MMS allocation of the ordered version gives one of the original: go through the positions in increasing order, and let the owner of each position take its most valuable free good.
  • Reduction rules. In an ordered instance with kk agents and goods g1,g2,…g_1, g_2, \dots, let S1={g1}S_1 = \{g_1\}, S2={gk,gk+1}S_2 = \{g_k, g_{k+1}\}, S3={g2k−1,g2k,g2k+1}S_3 = \{g_{2k-1}, g_{2k}, g_{2k+1}\} and S4={g1,g2k+1}S_4 = \{g_1, g_{2k+1}\}. Rule RrR_r gives SrS_r to an agent ii with vi(Sr)≥34MMSiv_i(S_r) \ge \frac{3}{4} \mathrm{MMS}_i. Removing the agent and SrS_r does not lower the share of any other agent for k−1k - 1 bundles (Garg and Taki, Lemma 3.1); for R4R_4 this needs R1R_1 and R3R_3 not to apply.
  • Normalization. Agent ii takes an MMS partition PP and divides the value of each good in PjP_j by vi(Pj)v_i(P_j). Every share becomes 1, and each new value is at most the old value divided by MMSi\mathrm{MMS}_i.

The algorithm

  1. APPROX-MMS(v) ▷ n agents, m goods, additive values v_ij ≥ 0
  2. 1w_i ← the values of agent i in decreasing order (the ordered instance)
  3. 2while some agent and some good remain do ▷ k agents left, goods g_1, g_2, ... by rank
  4. 3MMS_i ← the maximin share of agent i for k bundles of the remaining goods
  5. 4find the first rule r in R1, R2, R3, R4 and the first agent i with w_i(S_r) ≥ (3/4) MMS_i
  6. 5if found then give S_r to i and remove i and S_r
  7. 6else exit the loop
  8. 7for each agent i left: u_i(g) ← w_i(g)/w_i(P_j) for every g in P_j, P an MMS partition of i
  9. 8u_i ← the normalized values in decreasing order (ordered again); k ← the number of agents left
  10. 9bags B_t ← {position t, position 2k + 1 - t} for t = 1, ..., k
  11. 10while some agent left has no bag do
  12. 11if some agent i without a bag has u_i(B) ≥ 3/4 for a free bag B then give B to i
  13. 12else add the next unused position to the first free bag
  14. 13give unused positions to one agent; map positions back to goods by picking, first with u, then with w
  15. 14return the allocation

Lines L1 to L6 shrink the instance until no rule applies. Lines L7 and L8 normalize and sort it again; sorting is needed because normalization can break the order. The bag of line L9 pairs the tt-th largest position with the (2k+1−t)(2k + 1 - t)-th, so the bags start with similar values. When no rule applies, at least 2k2k goods remain, because an MMS partition with fewer goods would have a bundle of one good worth MMSi\mathrm{MMS}_i, and rule R1R_1 would apply (Akrami et al., Lemma 3). Line L12 adds the free goods in order of position. Line L13 undoes the two orderings with the picking step described above.

Example

Agent 1 values each of ten goods at 1, and agent 2 values them at 3,3,2,2,2,2,1,1,1,13, 3, 2, 2, 2, 2, 1, 1, 1, 1. Both lists are already sorted. The maximin shares for two bundles are 5 and 9, so the targets are 3.753.75 and 6.756.75.

  1. Rules. S1={g1}S_1 = \{g_1\} is worth 1 and 3, S2={g2,g3}S_2 = \{g_2, g_3\} is worth 2 and 5, S3={g3,g4,g5}S_3 = \{g_3, g_4, g_5\} is worth 3 and 6, and S4={g1,g5}S_4 = \{g_1, g_5\} is worth 2 and 5. All are below the targets, so both agents go to bag filling.
  2. Normalization. Agent 1 gets 1/51/5 per good. Agent 2 has an MMS partition into two bundles worth 9, so its values become 3/9,3/9,2/9,…,1/93/9, 3/9, 2/9, \dots, 1/9.
  3. Bags. B1={1,4}B_1 = \{1, 4\} and B2={2,3}B_2 = \{2, 3\}. Agent 1 values both at 2/52/5 and agent 2 values both at 5/95/9; nobody accepts.
  4. Filling. Position 5 joins B1B_1. Agent 2 now values B1B_1 at 7/9≥3/47/9 \ge 3/4 and takes it. Positions 6 and 7 join B2B_2, and agent 1 values it at 4/5≥3/44/5 \ge 3/4 and takes it. The unused positions 8 to 10 go to agent 1.
  5. Mapping back. Agent 2 gets goods g1,g4,g5g_1, g_4, g_5, worth 7, and agent 1 gets the other seven goods, worth 7.

Agent 2 gets 7≥6.757 \ge 6.75 but less than its share of 9; agent 1 gets 7≥57 \ge 5.

Correctness

The output is 3/43/4-MMS if each step keeps the guarantee and bag filling never runs out of goods. A rule gives agent ii value at least 34MMSi\frac{3}{4}\mathrm{MMS}_i in the current instance, and the shares of the other agents do not drop (the validity of the rules). Normalization and the second sorting turn a bag worth 3/43/4 under uiu_i into a bundle worth 34MMSi\frac{3}{4}\mathrm{MMS}_i under wiw_i. The picking step maps positions back to goods without loss, because at the qq-th position at most q−1q - 1 goods are gone, so the picker gets a good worth at least its qq-th largest value. That bag filling never runs out is the core of the analysis; Akrami et al. split the agents into those who value every initial bag at most 1 (Lemma 8) and the others (Lemma 14), and show that each assigned bag takes little value from the agents still waiting. The full proof of the transfers, with the cited lemmas, is in proofs/correctness.md.

Proof: The approximate MMS algorithm gives every agent three quarters of its maximin sharepartial

Setting. There are n≥1n \ge 1 agents and mm goods with additive values vig≥0v_{ig} \ge 0, and α=3/4\alpha = 3/4. We refer to the lines L1 to L14 of the page. For kk agents and a set of goods, MMSi\mathrm{MMS}_i is the maximin share of agent ii for kk bundles of that set. In an ordered instance the goods are positions 1,2,…1, 2, \dots, and position qq is worth the qq-th largest value of the agent. This proof proves the transfer steps in full: the mapping back from positions to goods, the validity of rule R1R_1, the count of goods before bag filling, and normalization. It cites Garg and Taki (Lemma 3.1), restated as Lemma 1 of Akrami, Garg, Sharma and Taki, for the validity of rules R2R_2 to R4R_4, and Lemmas 8 and 14 of Akrami et al. for the success of bag filling.

Lemma 1 (mapping back by picking). Let every agent ii have values xix_i on a set GG of goods, and let wi(q)w_i(q) be the qq-th largest value of xix_i. Let the positions 1,…,∣G∣1, \dots, |G| be split into sets QiQ_i. If the positions are taken in increasing order and the owner of each position picks its most valuable free good, then each agent ii gets goods with xix_i-value at least ∑q∈Qiwi(q)\sum_{q \in Q_i} w_i(q). Also, agent ii has the same maximin share under xix_i and under wiw_i.

Proof. When position qq comes, exactly q−1q - 1 goods are taken. The owner ii of qq has qq goods of xix_i-value at least wi(q)w_i(q), so one of them is free, and the good it picks is worth at least wi(q)w_i(q). Summing over QiQ_i gives the bound. The values wiw_i are the values xix_i in a different order, so the two instances have the same partitions up to renaming, and the same maximin share. □\square

Lemma 2 (rule R1R_1 is valid). Let k≥2k \ge 2 agents remain, let agent ii leave with one good gg, and let jj be another agent. Then the maximin share of jj for k−1k - 1 bundles of the remaining goods is at least its share for kk bundles before.

Proof. Take a partition of the goods into kk bundles, each worth at least MMSj\mathrm{MMS}_j to jj. Let BB be the bundle that contains gg. Remove BB and add B∖{g}B \setminus \{g\} to any other bundle. This gives k−1k - 1 bundles of the remaining goods, and no bundle lost value, so each is worth at least MMSj\mathrm{MMS}_j. □\square

Lemma 3 (rules R2R_2 to R4R_4; Garg and Taki, Lemma 3.1). If rule R2R_2 or R3R_3 gives its set to an agent, or rule R4R_4 does so when R1R_1 and R3R_3 do not apply, then no other agent's maximin share for the remaining agents and goods is less than before.

This is cited, not proved here.

Lemma 4 (enough goods for the bags). When the loop of line L2 exits in line L6 with kk agents left, at least 2k2k goods remain, and every agent left has MMSi>0\mathrm{MMS}_i > 0.

Proof. If some agent ii had MMSi=0\mathrm{MMS}_i = 0, then wi(S1)≥0=34MMSiw_i(S_1) \ge 0 = \frac{3}{4}\mathrm{MMS}_i, and line L4 would find rule R1R_1. So every agent left has MMSi>0\mathrm{MMS}_i > 0. Suppose fewer than 2k2k goods remain, and take an MMS partition of agent ii into kk bundles. By the pigeonhole principle, some bundle has at most one good. It is not empty, because each bundle is worth at least MMSi>0\mathrm{MMS}_i > 0. So it is one good worth at least MMSi\mathrm{MMS}_i, and the largest good g1g_1 is worth at least as much. Then wi(S1)≥MMSi≥34MMSiw_i(S_1) \ge \mathrm{MMS}_i \ge \frac{3}{4}\mathrm{MMS}_i, and line L4 would find rule R1R_1, which is a contradiction. □\square

Lemma 5 (normalization). Let kk agents be left after line L6, with MMSi>0\mathrm{MMS}_i > 0 by Lemma 4. Then the values uiu_i of line L7 satisfy wi(S)≥MMSi⋅ui(S)w_i(S) \ge \mathrm{MMS}_i \cdot u_i(S) for every set SS of the remaining goods, and the maximin share of uiu_i for kk bundles is 1.

Proof. Line L7 uses an MMS partition PP of agent ii, so wi(Pj)≥MMSi>0w_i(P_j) \ge \mathrm{MMS}_i > 0 for every bundle. For g∈Pjg \in P_j, ui(g)=wi(g)/wi(Pj)≤wi(g)/MMSiu_i(g) = w_i(g)/w_i(P_j) \le w_i(g)/\mathrm{MMS}_i. Summing over SS gives the first claim. Each bundle PjP_j has ui(Pj)=1u_i(P_j) = 1, so the share of uiu_i is at least 1. The total uiu_i-value is kk, so no partition into kk bundles has all bundles above 1, and the share is exactly 1. □\square

Lemma 6 (bag filling succeeds; Akrami et al., Lemmas 8 and 14). In lines L9 to L12, on the ordered normalized instance of line L8, every agent gets a bag with uiu_i-value at least 3/43/4 before the free goods run out.

This is cited, not proved here. Lines L8 to L12 follow the instance toOrd(normalize(⋅))\mathrm{toOrd}(\mathrm{normalize}(\cdot)) of their Lemma 5 and the bags {t,2k+1−t}\{t, 2k + 1 - t\} of their Algorithm 3, and Lemmas 4 and 5 above give the conditions that their lemmas use.

Theorem. The allocation returned in line L14 gives every agent ii a bundle AiA_i with vi(Ai)≥34MMSiv_i(A_i) \ge \frac{3}{4}\mathrm{MMS}_i, where MMSi\mathrm{MMS}_i is the share for nn bundles of all goods, and every good goes to exactly one agent.

Proof. By Lemma 1, the instance ww of line L1 has the same shares as vv, and it is enough to give each agent a set of positions with wiw_i-value at least 34MMSi\frac{3}{4}\mathrm{MMS}_i; the last picking step of line L13 then gives goods with at least that viv_i-value.

By Lemmas 2 and 3 and induction on the number of rules applied, every agent still present has a share for the current agents and goods at least its share at the start. An agent that leaves in line L5 gets SrS_r with wi(Sr)≥34w_i(S_r) \ge \frac{3}{4} of its current share, so at least 34MMSi\frac{3}{4}\mathrm{MMS}_i.

If the loop of line L2 ends because no goods remain, the agents left have a current share of 0, so their starting share is 0 and the empty bundle is enough. If it ends because no agents remain, the free goods go to one agent and only add value.

Otherwise the loop exits in line L6, and Lemma 4 gives at least 2k2k goods, so the bags of line L9 exist. By Lemma 6, each agent ii left gets a bag of positions with uiu_i-value at least 3/43/4 in the order of line L8. Lemma 1, applied to uu, maps the bag to goods with uiu_i-value at least 3/43/4, and Lemma 5 gives them wiw_i-value at least 34\frac{3}{4} of the current share, which is at least 34MMSi\frac{3}{4}\mathrm{MMS}_i. The unused positions of line L13 go to one agent and only add value.

Each picking step gives each good to exactly one agent, so the result is an allocation of all goods. ■\blacksquare

Complexity

Line L1 sorts in O(nmlog⁡m)O(n m \log m) time. The loop of line L2 runs at most nn times, and each run computes up to nn maximin shares in line L3 and tests four rules in O(n)O(n) time. Line L7 computes one MMS partition per agent left. So the run needs O(n2)O(n^2) maximin share computations, which cost TT each, and O(nmlog⁡m+n2(n+m))O(n m \log m + n^2(n + m)) other steps for the rules, the sorting, the bags and the picking. Computing a maximin share is NP-hard, so with exact shares this is not polynomial; Garg and Taki give a strongly polynomial version for 3/43/4 that does not need exact shares (theorem). The implementation computes shares by branch and bound, which is fast for small instances.

Properties

  • 3/43/4-MMS for every agent, for additive valuations (theorem).
  • Close to 3/43/4 in the worst case. Akrami et al. (Theorem 2 and Example 1) give an instance with identical valuations on which the output of the algorithm is at most 3n4n−1\frac{3n}{4n - 1}-MMS. This tends to 3/43/4 as nn grows, so the analysis is nearly tight.
  • No fairness between agents. The output need not be EF1; the leftover goods of line L13 can go to anyone.
  • Deterministic with the fixed orders of the pseudocode.

Variants and improvements

The factor has risen over time (all theorems unless marked):

factor source
2/32/3 Kurokawa, Procaccia and Wang (JACM 2018)
3/43/4 Ghodsi et al. (EC 2018)
3/4+1/(12n)3/4 + 1/(12n) Garg and Taki (AI 2021)
3/4+min⁡(1/36,3/(16n−4))3/4 + \min(1/36, 3/(16n - 4)) Akrami, Garg, Sharma and Taki (IJCAI 2023), by adding dummy goods to rule R4R_4
3/4+3/38363/4 + 3/3836 Akrami and Garg (SODA 2024)
10/1310/13 Heidari et al. (SODA 2026, arXiv:2510.10423)
7/97/9 Huang and Zhou (arXiv:2511.13056), preprint

Upper bounds: Feige, Sapir and Tauber (2021) give an instance with three agents and nine goods where no allocation is better than 39/4039/40-MMS, and instances with 1−1/n41 - 1/n^4 for n≥4n \ge 4 (theorems). A preprint by Ezra and Garbuz (arXiv:2609.15085, September 2026) gives 20/2120/21 with four agents and eleven goods.

When to use it

Use it when a provable share for every agent matters more than comparisons between agents, for example when agents state values for many goods and each must be sure of a minimum. For small instances, an exact search may find a full MMS allocation; the algorithm is the fallback with a guarantee.

Pitfalls

  • Skipping the second sort. Line L8 must sort the normalized values again. Normalization by the MMS partition can make a later good worth more than an earlier one, and the bag analysis needs an ordered instance.
  • Applying rule R4R_4 too early. Line L4 must try R1R_1 and R3R_3 before R4R_4. Rule R4R_4 is valid only when R1R_1 and R3R_3 do not apply; otherwise the shares of the other agents can drop.
  • Using the original shares after a reduction. Line L3 must recompute each share for the remaining agents and goods, with kk bundles. The old shares are lower bounds only.
  • Filling with a factor above 3/43/4. With α>3/4\alpha > 3/4 in lines L4 and L11, rule R4R_4 is no longer valid as stated, and Akrami et al. add a dummy good to repair it.
  • Mapping positions straight to goods. Line L13 must let owners pick in the order of the positions; giving each agent the goods at its positions in the original numbering loses the guarantee.

Implementations

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.

approximate_mms_allocation.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/approximate-mms-allocation/. The authors are listed in prov/1VB5JR.jsonl.

from fractions import Fraction
from math import gcd as _gcd
from typing import Optional, Sequence

ALPHA = Fraction(3, 4)


def mms_partition(row: Sequence[Fraction], goods: Sequence[int], n: int) -> tuple[Fraction, list[list[int]]]:
    """Maximin share of an additive valuation over the given goods, for n bundles.

    Returns (MMS, partition), where the partition has n bundles and its
    worst bundle has value MMS. Branch and bound: the goods go out in
    decreasing order of value, bundles with equal loads count once, and a
    branch stops when the water level of the remaining value cannot beat
    the best partition found so far. Exponential time in the worst case
    (the problem is NP-hard); fine for m up to about 20 small values.
    """
    items = sorted(goods, key=lambda g: (-row[g], g))
    if n <= 0:
        raise ValueError("n must be positive")
    # Scale to integers, so that the search compares small ints.
    scale = 1
    for g in items:
        scale = scale * Fraction(row[g]).denominator // _gcd(scale, Fraction(row[g]).denominator)
    val = {g: int(Fraction(row[g]) * scale) for g in items}
    suffix = [0] * (len(items) + 1)
    for k in range(len(items) - 1, -1, -1):
        suffix[k] = suffix[k + 1] + val[items[k]]
    upper = suffix[0] // n
    loads = [0] * n
    parts: list[list[int]] = [[] for _ in range(n)]
    best: list = [-1, None]

    def water(rem: int) -> int:
        # The largest integer the smallest load can reach if the rest were divisible.
        low = sorted(loads)
        acc = 0
        for k in range(n):
            acc += low[k]
            level = (acc + rem) // (k + 1)
            if k + 1 == n or level <= low[k + 1]:
                return level
        return (acc + rem) // n

    def dfs(k: int) -> None:
        if best[0] == upper:
            return
        if k == len(items):
            low = min(loads)
            if low > best[0]:
                best[0] = low
                best[1] = [list(b) for b in parts]
            return
        if water(suffix[k]) <= best[0]:
            return
        g = items[k]
        tried = set()
        for b in sorted(range(n), key=lambda b: (loads[b], b)):
            if loads[b] in tried:
                continue
            tried.add(loads[b])
            loads[b] += val[g]
            parts[b].append(g)
            dfs(k + 1)
            parts[b].pop()
            loads[b] -= val[g]

    dfs(0)
    return Fraction(best[0], scale), best[1]


def pick_back(owner_of_position: Sequence[int], goods: Sequence[int], vals: dict) -> dict:
    """Undo an ordering: position q is the q-th largest value of every agent.

    Positions are handled in increasing order; the owner of position q
    picks its most valuable good among those not taken yet (ties to the
    smallest good). vals[i][g] is the value of agent i for good g. Returns
    a dict from agents to lists of goods.
    """
    free = sorted(goods)
    out: dict = {}
    for i in owner_of_position:
        g = max(free, key=lambda g: (vals[i][g], -g))
        free.remove(g)
        out.setdefault(i, []).append(g)
    return out


def approx_mms(values: Sequence[Sequence], stats: Optional[dict] = None) -> list[list[int]]:
    """A 3/4-MMS allocation: the Garg-Taki algorithm in the form of Akrami, Garg, Sharma and Taki.

    values[i][g] is the nonnegative additive value of agent i for good g.
    Returns bundles A with v_i(A_i) >= (3/4) MMS_i for every agent i. If
    stats is a dict, it gets the rules applied ("rules", a list of pairs
    (agent, rule number)) and the agents left for bag filling ("bagfill").

    Cost: the reductions and bag filling take O(n m log m + n^2 (n + m))
    steps, plus O(n^2) exact MMS computations, which take exponential time
    in the worst case. Garg and Taki also give a strongly polynomial
    version that does not need exact MMS values; this file does not.
    """
    v = [[Fraction(x) for x in row] for row in values]
    n = len(v)
    if n == 0:
        raise ValueError("at least one agent is needed")
    m = len(v[0])
    if any(len(row) != m for row in v) or any(x < 0 for row in v for x in row):
        raise ValueError("every agent needs a nonnegative value for every good")
    w = [sorted(row, reverse=True) for row in v]  # @line L1
    agents = list(range(n))
    ranks = list(range(m))
    owner_of_rank = [-1] * m
    rules: list[tuple[int, int]] = []
    while agents and ranks:  # @line L2
        k = len(agents)
        mms = {i: mms_partition(w[i], ranks, k)[0] for i in agents}  # @line L3
        size = len(ranks)
        sets = [
            [ranks[0]],
            ranks[k - 1:k + 1] if size >= k + 1 else [],
            ranks[2 * k - 2:2 * k + 1] if size >= 2 * k + 1 else [],
            [ranks[0], ranks[2 * k]] if size >= 2 * k + 1 else [],
        ]
        found = None
        for rule, s in enumerate(sets):  # @line L4
            if not s:
                continue
            for i in agents:
                if sum(w[i][r] for r in s) >= ALPHA * mms[i]:
                    found = (i, rule)
                    break
            if found:
                break
        if found is None:  # @line L6
            break
        i, rule = found
        for r in sets[rule]:  # @line L5
            owner_of_rank[r] = i
        agents.remove(i)
        ranks = [r for r in ranks if r not in sets[rule]]
        rules.append((i, rule + 1))
    if stats is not None:
        stats["rules"] = rules
        stats["bagfill"] = list(agents) if ranks else []
    if agents and ranks:
        k = len(agents)
        u = {}
        for i in agents:  # @line L7
            _, part = mms_partition(w[i], ranks, k)
            u[i] = {}
            for bundle in part:
                total = sum(w[i][r] for r in bundle)
                for r in bundle:
                    u[i][r] = w[i][r] / total
        order = {i: sorted((u[i][r] for r in ranks), reverse=True) for i in agents}  # @line L8
        size = len(ranks)
        if size < 2 * k:
            raise AssertionError("an R1-irreducible instance has at least 2n goods")
        bags = [[t, 2 * k - 1 - t] for t in range(k)]  # @line L9
        free_goods = list(range(2 * k, size))
        free_bags = list(range(k))
        waiting = list(agents)
        bag_of: dict = {}
        while waiting:  # @line L10
            hit = None
            for i in waiting:
                for b in free_bags:
                    if sum(order[i][q] for q in bags[b]) >= ALPHA:
                        hit = (i, b)
                        break
                if hit:
                    break
            if hit:  # @line L11
                bag_of[hit[0]] = hit[1]
                waiting.remove(hit[0])
                free_bags.remove(hit[1])
            elif free_goods:  # @line L12
                bags[free_bags[0]].append(free_goods.pop(0))
            else:
                raise AssertionError("bag filling ran out of goods")
        owner_of_position = [-1] * size
        for i, b in bag_of.items():  # @line L13
            for q in bags[b]:
                owner_of_position[q] = i
        for q in free_goods:
            owner_of_position[q] = agents[0]
        got = pick_back(owner_of_position, ranks, u)
        for i, rs in got.items():
            for r in rs:
                owner_of_rank[r] = i
    for r in range(m):
        if owner_of_rank[r] < 0:
            owner_of_rank[r] = 0
    final = pick_back(owner_of_rank, range(m), {i: v[i] for i in range(n)})
    return [sorted(final.get(i, [])) for i in range(n)]  # @line L14
test_approximate_mms_allocation.py 131 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/approximate-mms-allocation/. The authors are listed in prov/1VB5JR.jsonl.

import random
from fractions import Fraction

import pytest

from approximate_mms_allocation import approx_mms, mms_partition

F = Fraction


def mms_brute(row, n):
    """MMS by brute force over partitions: max over a first bundle S of min(v(S), MMS of the rest with n - 1)."""
    m = len(row)
    val = [0] * (1 << m)
    for s in range(1, 1 << m):
        low = s & -s
        val[s] = val[s ^ low] + row[low.bit_length() - 1]
    memo = {}

    def best(s, k):
        if k == 1:
            return val[s]
        if (s, k) not in memo:
            r = -1
            sub = s
            while True:
                r = max(r, min(val[sub], best(s ^ sub, k - 1)))
                if sub == 0:
                    break
                sub = (sub - 1) & s
            memo[(s, k)] = r
        return memo[(s, k)]

    return best((1 << m) - 1, n)


def check(values, bundles, exact=True):
    n, m = len(values), len(values[0])
    assert sorted(g for b in bundles for g in b) == list(range(m))
    for i in range(n):
        target = mms_brute(values[i], n) if exact else mms_partition([F(x) for x in values[i]], range(m), n)[0]
        assert 4 * sum(values[i][g] for g in bundles[i]) >= 3 * target


def test_worked_example():
    values = [[1] * 10, [3, 3, 2, 2, 2, 2, 1, 1, 1, 1]]
    assert mms_brute(values[0], 2) == 5
    assert mms_brute(values[1], 2) == 9
    stats = {}
    bundles = approx_mms(values, stats)
    assert stats["rules"] == []
    assert stats["bagfill"] == [0, 1]
    assert bundles == [[1, 2, 5, 6, 7, 8, 9], [0, 3, 4]]
    assert [sum(values[i][g] for g in bundles[i]) for i in range(2)] == [7, 7]
    check(values, bundles)


def test_mms_partition_against_brute_force():
    rng = random.Random(41)
    for _ in range(300):
        n, m = rng.randint(1, 4), rng.randint(0, 8)
        row = [rng.randint(0, 12) for _ in range(m)]
        value, part = mms_partition([F(x) for x in row], range(m), n)
        assert value == mms_brute(row, n)
        assert len(part) == n
        assert sorted(g for b in part for g in b) == list(range(m))
        assert min(sum(row[g] for g in b) for b in part) == value


def test_random_instances():
    rng = random.Random(42)
    rules_seen = set()
    for _ in range(250):
        n, m = rng.randint(1, 4), rng.randint(0, 8)
        lo = rng.choice([0, 1, 5, 10])
        hi = lo + rng.choice([3, 10, 30])
        values = [[rng.randint(lo, hi) for _ in range(m)] for _ in range(n)]
        stats = {}
        bundles = approx_mms(values, stats)
        rules_seen.update(rule for _, rule in stats["rules"])
        check(values, bundles)
    assert {1, 2, 3} <= rules_seen


def test_rule_four():
    # Agent 0: MMS 17, so 3/4 MMS = 51/4. g1 = 9, g2 + g3 = 11 and g3 + g4 + g5 = 12 are below it,
    # and g1 + g5 = 13 is not, so only R4 applies.
    values = [[9, 7, 4, 4, 4, 4, 1, 1], [6, 3, 2, 2, 2, 2, 2, 1]]
    assert mms_brute(values[0], 2) == 17
    stats = {}
    bundles = approx_mms(values, stats)
    assert stats["rules"] == [(0, 4)]
    check(values, bundles)


def test_bag_filling_instances():
    rng = random.Random(43)
    reached = 0
    for _ in range(80):
        n = rng.choice([2, 3])
        m = rng.randint(2 * n + 1, 9)
        values = [[rng.randint(10, 14) for _ in range(m)] for _ in range(n)]
        stats = {}
        bundles = approx_mms(values, stats)
        reached += bool(stats["bagfill"])
        check(values, bundles)
    assert reached >= 10


def test_three_agents_in_bag_filling():
    values = [
        [7, 9, 6, 6, 6, 8, 6, 7, 6, 6, 9, 9, 6],
        [7, 6, 9, 6, 6, 7, 6, 9, 6, 7, 6, 7, 8],
        [9, 7, 6, 8, 7, 6, 7, 8, 6, 6, 6, 7, 9],
    ]
    stats = {}
    bundles = approx_mms(values, stats)
    assert stats["bagfill"] == [0, 1, 2]
    check(values, bundles, exact=False)


def test_rational_values_and_bad_input():
    values = [[F(1, 2), F(1, 3), F(1, 6), F(2, 3)], [F(1, 4), F(1, 4), F(1, 4), F(1, 4)]]
    check(values, approx_mms(values))
    with pytest.raises(ValueError):
        approx_mms([])
    with pytest.raises(ValueError):
        approx_mms([[1, -1]])

History

Kurokawa, Procaccia and Wang showed that MMS allocations need not exist and that 2/32/3-MMS allocations do, and Ghodsi et al. reached 3/43/4. Garg and Taki (2021) gave the simple algorithm of this page with the factor 3/4+1/(12n)3/4 + 1/(12n), and Akrami, Garg, Sharma and Taki (2023) simplified its analysis to the bag-filling lemmas used here.

References

  1. Jugal Garg and Setareh Taki, An improved approximation algorithm for maximin shares, Artificial Intelligence 300 (2021), 103547, Lemma 3.1 (valid reductions), the 3/4 + 1/(12n) existence result, and the strongly polynomial 3/4 algorithm
  2. Hannaneh Akrami, Jugal Garg, Eklavya Sharma and Setareh Taki, Simplification and improvement of MMS approximation, IJCAI 2023 (arXiv:2303.16788), Definitions 1 to 5, Lemmas 1 to 5 (ordering, reductions and normalization), Algorithm 3 (bag filling), Lemmas 6 to 14, Theorem 1 (3/4 + min(1/36, 3/(16n - 4))) and Theorem 2 (tight example)
  3. David Kurokawa, Ariel D. Procaccia and Junxing Wang, Fair enough: guaranteeing approximate maximin shares, Journal of the ACM 65(2) (2018), article 8, the existence of 2/3-MMS allocations
  4. Mohammad Ghodsi, Mohammad Taghi Hajiaghayi, Masoud Seddighin, Saeed Seddighin and Hadi Yami, Fair allocation of indivisible goods: improvements and generalizations, Proceedings of the 19th ACM Conference on Economics and Computation (EC 2018), the existence of 3/4-MMS allocations
  5. Hannaneh Akrami and Jugal Garg, Breaking the 3/4 barrier for approximate maximin share, Proceedings of the 35th ACM-SIAM Symposium on Discrete Algorithms (SODA 2024), the existence of (3/4 + 3/3836)-MMS allocations
  6. Heidari et al., arXiv:2510.10423 (2025), SODA 2026, the existence of 10/13-MMS allocations
  7. Uriel Feige, Ariel Sapir and Laliv Tauber, A tight negative example for MMS fair allocations, WINE 2021 (arXiv:2104.04977), the upper bounds 39/40 for three agents and 1 - 1/n^4 for n at least 4
  8. Huang and Zhou, arXiv:2511.13056 (2025), preprint, the claimed existence of 7/9-MMS allocations
  9. Ezra and Garbuz, arXiv:2609.15085 (September 2026), preprint, the claimed instance with four agents and eleven goods with no allocation better than 20/21-MMS

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 correctness
  • 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
  • History with a source
  • a scene preset for the example