{"abstract":"Neighbouring lines one class apart are penalised as visually incompatible.","category":"Typography line breaking","checks":8,"contract":"Input [word widths, [space, stretch, shrink] per gap, line width, line penalty]. A line i..j has gaps=j-i-1. The last line has zero badness when not overfull. Other lines use ratio shortfall/(stretch*gaps) or /(shrink*gaps); zero stretch with slack or compression past shrink is infeasible; badness=min(10000, floor(100|r|^3+1/2)) and must be <=1000. Fitness 0 tight (r<-1/2), 1 decent (r<=1/2), 2 loose (r<=1), 3 very loose; last line decent. Demerits (lp+b)^2 plus 3000 when adjacent fitness classes differ by more than 1, starting from decent. Return [min total demerits, break list] (ties: first found) or [\"infeasible\"].","contract_signature":"x","evaluation_group":"w2-typography-line-breaking-total-fit-demerits","failed_approach":"Checking only the upward direction misses tight-after-loose jumps.","family":"w2-typography-line-breaking-total-fit-demerits-adjacent-fitness-penalty","id":"FA-79886","implementations":{"attempt":{"sha256":"8c80ff31375d4ce972da4a6a3d6e0db4a474db6ee6079c31b6401293972e3b1b","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport math\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    words, glue, width, lp = x\n    sp, st, sh = glue\n    n = len(words)\n    def rate(i, j):\n        gaps = j - i - 1\n        nat = sum(words[i:j]) + sp * gaps\n        short = width - nat\n        if j == n and short >= 0:\n            return 0, 1\n        if short > 0:\n            if st * gaps == 0:\n                return None\n            r = Fraction(short, st * gaps)\n        elif short < 0:\n            if -short > sh * gaps:\n                return None\n            r = Fraction(short, sh * gaps)\n        else:\n            r = Fraction(0)\n        b = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))\n        if b > 1000:\n            return None\n        fit = 0 if r < Fraction(-1, 2) else 1 if r <= Fraction(1, 2) else 2 if r <= 1 else 3\n        return b, fit\n    best = {(0, 1): (0, [])}\n    for j in range(1, n + 1):\n        for i in range(j):\n            rated = rate(i, j)\n            if rated is None:\n                continue\n            b, fit = rated\n            for (pos, pfit), (dem, brk) in sorted(best.items()):\n                if pos != i:\n                    continue\n                d = dem + (lp + b) ** 2\n                if fit - pfit > 1:\n                    d += 3000\n                key = (j, fit)\n                if key not in best or d < best[key][0]:\n                    best[key] = (d, brk + [j])\n    finals = [v for (pos, f), v in best.items() if pos == n]\n    if not finals:\n        return ['infeasible']\n    d, brk = min(finals)\n    return [d, brk]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('regression: adjacent fitness penalty', [[3, 6, 2, 2, 3, 1, 6], [3, 2, 1], 14, 1], [10211, [2, 5, 7]]), ('partial-repair probe', [[6, 6, 7, 3, 4, 4], [1, 1, 2], 15, 1], [647611, [2, 5, 6]]), ('partial-repair probe', [[1, 3, 7], [3, 2, 2], 11, 1], [647602, [2, 3]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('control layout', [[4, 5, 6], [1, 1, 1], 10, 10], [200, [2, 3]]), ('control layout', [[4, 5, 6, 3, 3, 6, 2, 5], [3, 3, 0], 24, 50], [8969, [3, 7, 8]])], [('regression: adjacent fitness penalty', [[1, 7, 7, 2, 4, 1, 3, 4], [1, 1, 2], 13, 50], [27500, [3, 7, 8]]), ('regression: adjacent fitness penalty', [[4, 2, 3, 4], [2, 1, 0], 15, 10], [12200, [3, 4]]), ('partial-repair probe', [[7, 5, 2, 3, 3], [3, 1, 0], 17, 10], [662200, [2, 5]]), ('regression: adjacent fitness penalty', [[4, 7, 6, 7, 2, 7, 6, 4], [1, 1, 1], 22, 10], [139304, [3, 7, 8]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('control layout', [[3, 3, 5], [3, 1, 2], 21, 10], [100, [3]]), ('control layout', [[5, 5, 3, 6], [1, 1, 1], 22, 1], [1, [4]])], [('regression: adjacent fitness penalty', [[3, 6, 2, 2, 3, 1, 6], [3, 2, 1], 14, 1], [10211, [2, 5, 7]]), ('regression: adjacent fitness penalty', [[4, 2, 7, 3, 4], [2, 1, 1], 15, 50], [25000, [3, 5]]), ('partial-repair probe', [[5, 1, 6, 4, 7, 7, 1, 4], [1, 1, 1], 14, 1], [647603, [3, 5, 8]]), ('regression: adjacent fitness penalty', [[5, 7, 4, 7, 6, 4, 4, 1], [2, 1, 1], 24, 10], [674300, [3, 7, 8]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('control layout', [[1, 2, 5], [3, 3, 2], 13, 1], [9, [3]]), ('control layout', [[2, 3, 2, 2, 2, 4, 2, 7], [3, 3, 1], 9, 10], ['infeasible'])], [('regression: adjacent fitness penalty', [[2, 7, 2, 3, 3, 4], [3, 2, 0], 21, 50], [25000, [3, 6]]), ('regression: adjacent fitness penalty', [[7, 4, 3, 3, 6, 3, 7], [1, 1, 1], 13, 10], [12729, [2, 5, 7]]), ('partial-repair probe', [[2, 1, 4, 6, 1, 5], [3, 1, 1], 16, 50], [179044, [3, 6]]), ('partial-repair probe', [[5, 1, 5, 4], [2, 2, 1], 12, 1], [647602, [2, 4]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('control layout', [[4, 5, 4, 4], [1, 3, 2], 23, 1], [1, [4]]), ('control layout', [[7, 2, 2, 5, 7, 5], [3, 1, 0], 24, 10], ['infeasible'])], [('regression: adjacent fitness penalty', [[4, 4, 5, 4, 5], [1, 1, 1], 11, 10], [671300, [2, 4, 5]]), ('regression: adjacent fitness penalty', [[4, 2, 3, 4], [2, 1, 0], 15, 10], [12200, [3, 4]]), ('partial-repair probe', [[4, 1, 2, 3, 1, 7, 5, 1], [3, 2, 2], 11, 1], [235844, [2, 4, 6, 8]]), ('partial-repair probe', [[7, 6, 6, 6, 5, 5, 2, 4], [2, 2, 0], 15, 1], [121119, [2, 4, 6, 8]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('control layout', [[7, 4, 6, 5, 6, 4], [2, 2, 2], 23, 50], [6469, [3, 6]]), ('control layout', [[6, 1, 2], [2, 2, 2], 14, 10], [100, [3]])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"1e83117599a4a24457674495465ffa67cd3467df1f508c9c715b8a599561647c","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport math\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    words, glue, width, lp = x\n    sp, st, sh = glue\n    n = len(words)\n    def rate(i, j):\n        gaps = j - i - 1\n        nat = sum(words[i:j]) + sp * gaps\n        short = width - nat\n        if j == n and short >= 0:\n            return 0, 1\n        if short > 0:\n            if st * gaps == 0:\n                return None\n            r = Fraction(short, st * gaps)\n        elif short < 0:\n            if -short > sh * gaps:\n                return None\n            r = Fraction(short, sh * gaps)\n        else:\n            r = Fraction(0)\n        b = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))\n        if b > 1000:\n            return None\n        fit = 0 if r < Fraction(-1, 2) else 1 if r <= Fraction(1, 2) else 2 if r <= 1 else 3\n        return b, fit\n    best = {(0, 1): (0, [])}\n    for j in range(1, n + 1):\n        for i in range(j):\n            rated = rate(i, j)\n            if rated is None:\n                continue\n            b, fit = rated\n            for (pos, pfit), (dem, brk) in sorted(best.items()):\n                if pos != i:\n                    continue\n                d = dem + (lp + b) ** 2\n                if abs(fit - pfit) >= 1:\n                    d += 3000\n                key = (j, fit)\n                if key not in best or d < best[key][0]:\n                    best[key] = (d, brk + [j])\n    finals = [v for (pos, f), v in best.items() if pos == n]\n    if not finals:\n        return ['infeasible']\n    d, brk = min(finals)\n    return [d, brk]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('regression: adjacent fitness penalty', [[3, 6, 2, 2, 3, 1, 6], [3, 2, 1], 14, 1], [10211, [2, 5, 7]]), ('partial-repair probe', [[6, 6, 7, 3, 4, 4], [1, 1, 2], 15, 1], [647611, [2, 5, 6]]), ('partial-repair probe', [[1, 3, 7], [3, 2, 2], 11, 1], [647602, [2, 3]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('control layout', [[4, 5, 6], [1, 1, 1], 10, 10], [200, [2, 3]]), ('control layout', [[4, 5, 6, 3, 3, 6, 2, 5], [3, 3, 0], 24, 50], [8969, [3, 7, 8]])], [('regression: adjacent fitness penalty', [[1, 7, 7, 2, 4, 1, 3, 4], [1, 1, 2], 13, 50], [27500, [3, 7, 8]]), ('regression: adjacent fitness penalty', [[4, 2, 3, 4], [2, 1, 0], 15, 10], [12200, [3, 4]]), ('partial-repair probe', [[7, 5, 2, 3, 3], [3, 1, 0], 17, 10], [662200, [2, 5]]), ('regression: adjacent fitness penalty', [[4, 7, 6, 7, 2, 7, 6, 4], [1, 1, 1], 22, 10], [139304, [3, 7, 8]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('control layout', [[3, 3, 5], [3, 1, 2], 21, 10], [100, [3]]), ('control layout', [[5, 5, 3, 6], [1, 1, 1], 22, 1], [1, [4]])], [('regression: adjacent fitness penalty', [[3, 6, 2, 2, 3, 1, 6], [3, 2, 1], 14, 1], [10211, [2, 5, 7]]), ('regression: adjacent fitness penalty', [[4, 2, 7, 3, 4], [2, 1, 1], 15, 50], [25000, [3, 5]]), ('partial-repair probe', [[5, 1, 6, 4, 7, 7, 1, 4], [1, 1, 1], 14, 1], [647603, [3, 5, 8]]), ('regression: adjacent fitness penalty', [[5, 7, 4, 7, 6, 4, 4, 1], [2, 1, 1], 24, 10], [674300, [3, 7, 8]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('control layout', [[1, 2, 5], [3, 3, 2], 13, 1], [9, [3]]), ('control layout', [[2, 3, 2, 2, 2, 4, 2, 7], [3, 3, 1], 9, 10], ['infeasible'])], [('regression: adjacent fitness penalty', [[2, 7, 2, 3, 3, 4], [3, 2, 0], 21, 50], [25000, [3, 6]]), ('regression: adjacent fitness penalty', [[7, 4, 3, 3, 6, 3, 7], [1, 1, 1], 13, 10], [12729, [2, 5, 7]]), ('partial-repair probe', [[2, 1, 4, 6, 1, 5], [3, 1, 1], 16, 50], [179044, [3, 6]]), ('partial-repair probe', [[5, 1, 5, 4], [2, 2, 1], 12, 1], [647602, [2, 4]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('control layout', [[4, 5, 4, 4], [1, 3, 2], 23, 1], [1, [4]]), ('control layout', [[7, 2, 2, 5, 7, 5], [3, 1, 0], 24, 10], ['infeasible'])], [('regression: adjacent fitness penalty', [[4, 4, 5, 4, 5], [1, 1, 1], 11, 10], [671300, [2, 4, 5]]), ('regression: adjacent fitness penalty', [[4, 2, 3, 4], [2, 1, 0], 15, 10], [12200, [3, 4]]), ('partial-repair probe', [[4, 1, 2, 3, 1, 7, 5, 1], [3, 2, 2], 11, 1], [235844, [2, 4, 6, 8]]), ('partial-repair probe', [[7, 6, 6, 6, 5, 5, 2, 4], [2, 2, 0], 15, 1], [121119, [2, 4, 6, 8]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('control layout', [[7, 4, 6, 5, 6, 4], [2, 2, 2], 23, 50], [6469, [3, 6]]), ('control layout', [[6, 1, 2], [2, 2, 2], 14, 10], [100, [3]])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"A deterministic toy typesetting model with integer widths and a stipulated rule set; it does not claim conformance to any engine. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-typography-line-breaking-total-fit-demerits-adjacent-fitness-penalty","generated_at":"2026-09-29T14:49:48.852596+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Line breaking decides where paragraphs wrap on screen and in print; a wrong decision point shifts every following line.","root_cause":"The adjacent-demerit test uses >= 1 so any class change costs 3000.","sha256":"46d39c326eb3b00695b5a4adc1aea3e923a17fbf71825defe0f7e2d555beafce","title":"Total-fit paragraph demerits: adjacent fitness penalty · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verified":true,"visibility":"public","verification":{"attempt":{"elapsed_ms":46.205,"exit_code":1,"observations":[{"actual":[12200,[3,4]],"check":"two-line paragraph with loose first line","expected":[12200,[3,4]],"passed":true},{"actual":[10211,[2,5,7]],"check":"regression: adjacent fitness penalty","expected":[10211,[2,5,7]],"passed":true},{"actual":[644611,[2,5,6]],"check":"partial-repair probe","expected":[647611,[2,5,6]],"passed":false},{"actual":[644602,[2,3]],"check":"partial-repair probe","expected":[647602,[2,3]],"passed":false},{"actual":["infeasible"],"check":"last line overfull","expected":["infeasible"],"passed":true},{"actual":[20403,[3,6,7]],"check":"tight then loose lines","expected":[20403,[3,6,7]],"passed":true},{"actual":[200,[2,3]],"check":"control layout","expected":[200,[2,3]],"passed":true},{"actual":[8969,[3,7,8]],"check":"control layout","expected":[8969,[3,7,8]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"two-line paragraph with loose first line\", \"actual\": [12200, [3, 4]], \"expected\": [12200, [3, 4]], \"passed\": true}, {\"check\": \"regression: adjacent fitness penalty\", \"actual\": [10211, [2, 5, 7]], \"expected\": [10211, [2, 5, 7]], \"passed\": true}, {\"check\": \"partial-repair probe\", \"actual\": [644611, [2, 5, 6]], \"expected\": [647611, [2, 5, 6]], \"passed\": false}, {\"check\": \"partial-repair probe\", \"actual\": [644602, [2, 3]], \"expected\": [647602, [2, 3]], \"passed\": false}, {\"check\": \"last line overfull\", \"actual\": [\"infeasible\"], \"expected\": [\"infeasible\"], \"passed\": true}, {\"check\": \"tight then loose lines\", \"actual\": [20403, [3, 6, 7]], \"expected\": [20403, [3, 6, 7]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [200, [2, 3]], \"expected\": [200, [2, 3]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [8969, [3, 7, 8]], \"expected\": [8969, [3, 7, 8]], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":44.742,"exit_code":1,"observations":[{"actual":[18200,[3,4]],"check":"two-line paragraph with loose first line","expected":[12200,[3,4]],"passed":false},{"actual":[16211,[2,5,7]],"check":"regression: adjacent fitness penalty","expected":[10211,[2,5,7]],"passed":false},{"actual":[647611,[2,5,6]],"check":"partial-repair probe","expected":[647611,[2,5,6]],"passed":true},{"actual":[647602,[2,3]],"check":"partial-repair probe","expected":[647602,[2,3]],"passed":true},{"actual":["infeasible"],"check":"last line overfull","expected":["infeasible"],"passed":true},{"actual":[26403,[3,6,7]],"check":"tight then loose lines","expected":[20403,[3,6,7]],"passed":false},{"actual":[200,[2,3]],"check":"control layout","expected":[200,[2,3]],"passed":true},{"actual":[8969,[3,7,8]],"check":"control layout","expected":[8969,[3,7,8]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"two-line paragraph with loose first line\", \"actual\": [18200, [3, 4]], \"expected\": [12200, [3, 4]], \"passed\": false}, {\"check\": \"regression: adjacent fitness penalty\", \"actual\": [16211, [2, 5, 7]], \"expected\": [10211, [2, 5, 7]], \"passed\": false}, {\"check\": \"partial-repair probe\", \"actual\": [647611, [2, 5, 6]], \"expected\": [647611, [2, 5, 6]], \"passed\": true}, {\"check\": \"partial-repair probe\", \"actual\": [647602, [2, 3]], \"expected\": [647602, [2, 3]], \"passed\": true}, {\"check\": \"last line overfull\", \"actual\": [\"infeasible\"], \"expected\": [\"infeasible\"], \"passed\": true}, {\"check\": \"tight then loose lines\", \"actual\": [26403, [3, 6, 7]], \"expected\": [20403, [3, 6, 7]], \"passed\": false}, {\"check\": \"control layout\", \"actual\": [200, [2, 3]], \"expected\": [200, [2, 3]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [8969, [3, 7, 8]], \"expected\": [8969, [3, 7, 8]], \"passed\": true}], \"passed\": false}\n"}},"member_only":{"stages":["fixed"],"fields":["implementations.fixed","verification.fixed","harness","repair"],"note":"The verified repair, its recorded checks, the repair description, and the scoring harness are available to members."}}