{
  "method": "Gap-ranked joint reinsertion of two or three connected pieces, including the inward cap, followed by block and whole-packing constrained polish",
  "seed": 23002,
  "derived_seeds": [
    3973929218,
    2463150038,
    1166987617,
    559687532,
    406388579,
    1244978724,
    1159641123,
    391948515,
    3558257477,
    2575735499,
    1696249067,
    281411952,
    1954938892
  ],
  "official_valid": true,
  "official_score": "2.94852695",
  "official_score_full": 2.948526950912552,
  "solution": [
    {
      "x": 0.545425,
      "y": 0.67215,
      "theta": -0.570778
    },
    {
      "x": 1.135484,
      "y": -1.23874,
      "theta": 2.227365
    },
    {
      "x": -0.584124,
      "y": -0.217653,
      "theta": -1.671787
    },
    {
      "x": 1.843118,
      "y": 0.631801,
      "theta": -0.722762
    },
    {
      "x": 0.278186,
      "y": 1.928675,
      "theta": 2.264578
    },
    {
      "x": -0.723715,
      "y": 1.809349,
      "theta": 3.126118
    },
    {
      "x": -1.624637,
      "y": 1.076193,
      "theta": -2.992325
    },
    {
      "x": -0.56981,
      "y": 0.785952,
      "theta": -1.682231
    },
    {
      "x": 0.032918,
      "y": 1.724683,
      "theta": -0.877015
    },
    {
      "x": 1.261991,
      "y": 1.484613,
      "theta": 0.453135
    },
    {
      "x": -1.944933,
      "y": -0.121111,
      "theta": -2.464295
    },
    {
      "x": -1.573106,
      "y": -1.149938,
      "theta": -1.641622
    },
    {
      "x": 1.049635,
      "y": -2.567295,
      "theta": 1.95895
    },
    {
      "x": -0.789401,
      "y": -1.781407,
      "theta": -0.792106
    },
    {
      "x": 1.811166,
      "y": -0.718041,
      "theta": -0.914204
    }
  ],
  "solution_json": "[\n  {\n    \"x\": 0.545425,\n    \"y\": 0.67215,\n    \"theta\": -0.570778\n  },\n  {\n    \"x\": 1.135484,\n    \"y\": -1.23874,\n    \"theta\": 2.227365\n  },\n  {\n    \"x\": -0.584124,\n    \"y\": -0.217653,\n    \"theta\": -1.671787\n  },\n  {\n    \"x\": 1.843118,\n    \"y\": 0.631801,\n    \"theta\": -0.722762\n  },\n  {\n    \"x\": 0.278186,\n    \"y\": 1.928675,\n    \"theta\": 2.264578\n  },\n  {\n    \"x\": -0.723715,\n    \"y\": 1.809349,\n    \"theta\": 3.126118\n  },\n  {\n    \"x\": -1.624637,\n    \"y\": 1.076193,\n    \"theta\": -2.992325\n  },\n  {\n    \"x\": -0.56981,\n    \"y\": 0.785952,\n    \"theta\": -1.682231\n  },\n  {\n    \"x\": 0.032918,\n    \"y\": 1.724683,\n    \"theta\": -0.877015\n  },\n  {\n    \"x\": 1.261991,\n    \"y\": 1.484613,\n    \"theta\": 0.453135\n  },\n  {\n    \"x\": -1.944933,\n    \"y\": -0.121111,\n    \"theta\": -2.464295\n  },\n  {\n    \"x\": -1.573106,\n    \"y\": -1.149938,\n    \"theta\": -1.641622\n  },\n  {\n    \"x\": 1.049635,\n    \"y\": -2.567295,\n    \"theta\": 1.95895\n  },\n  {\n    \"x\": -0.789401,\n    \"y\": -1.781407,\n    \"theta\": -0.792106\n  },\n  {\n    \"x\": 1.811166,\n    \"y\": -0.718041,\n    \"theta\": -0.914204\n  }\n]\n",
  "solution_sha256": "cefac3368caae7f9dea0c4cdc0e87d869f3a9bd76ba75292b1cd4b7fff7c8fb9",
  "mec": {
    "x": -0.0001819080616875258,
    "y": 0.00013448997007248039,
    "radius": 2.948526950912552
  },
  "max_pair_area": 9.997822348073144e-07,
  "inherited_baseline": {
    "official_valid": true,
    "official_score": "2.94852695",
    "official_score_full": 2.948526950912552,
    "solution": [
      {
        "x": 0.545425,
        "y": 0.67215,
        "theta": -0.570778
      },
      {
        "x": 1.135484,
        "y": -1.23874,
        "theta": 2.227365
      },
      {
        "x": -0.584124,
        "y": -0.217653,
        "theta": -1.671787
      },
      {
        "x": 1.843118,
        "y": 0.631801,
        "theta": -0.722762
      },
      {
        "x": 0.278186,
        "y": 1.928675,
        "theta": 2.264578
      },
      {
        "x": -0.723715,
        "y": 1.809349,
        "theta": 3.126118
      },
      {
        "x": -1.624637,
        "y": 1.076193,
        "theta": -2.992325
      },
      {
        "x": -0.56981,
        "y": 0.785952,
        "theta": -1.682231
      },
      {
        "x": 0.032918,
        "y": 1.724683,
        "theta": -0.877015
      },
      {
        "x": 1.261991,
        "y": 1.484613,
        "theta": 0.453135
      },
      {
        "x": -1.944933,
        "y": -0.121111,
        "theta": -2.464295
      },
      {
        "x": -1.573106,
        "y": -1.149938,
        "theta": -1.641622
      },
      {
        "x": 1.049635,
        "y": -2.567295,
        "theta": 1.95895
      },
      {
        "x": -0.789401,
        "y": -1.781407,
        "theta": -0.792106
      },
      {
        "x": 1.811166,
        "y": -0.718041,
        "theta": -0.914204
      }
    ],
    "mec": [
      -0.0001819080616875258,
      0.00013448997007248039,
      2.948526950912552
    ]
  },
  "best_new_solution": [
    {
      "x": 0.545425,
      "y": 0.67215,
      "theta": -0.570778
    },
    {
      "x": 1.135484,
      "y": -1.23874,
      "theta": 2.227365
    },
    {
      "x": -0.584124,
      "y": -0.217653,
      "theta": -1.671787
    },
    {
      "x": 1.843118,
      "y": 0.631801,
      "theta": -0.722762
    },
    {
      "x": 0.278186,
      "y": 1.928675,
      "theta": 2.264578
    },
    {
      "x": -0.723715,
      "y": 1.809349,
      "theta": 3.126118
    },
    {
      "x": -1.624637,
      "y": 1.076193,
      "theta": -2.992325
    },
    {
      "x": -0.56981,
      "y": 0.785952,
      "theta": -1.682231
    },
    {
      "x": 0.032918,
      "y": 1.724683,
      "theta": -0.877015
    },
    {
      "x": 1.261991,
      "y": 1.484613,
      "theta": 0.453135
    },
    {
      "x": -1.944933,
      "y": -0.121111,
      "theta": -2.464295
    },
    {
      "x": -1.573106,
      "y": -1.149938,
      "theta": -1.641622
    },
    {
      "x": 1.049635,
      "y": -2.567295,
      "theta": 1.95895
    },
    {
      "x": -0.789401,
      "y": -1.781407,
      "theta": -0.792106
    },
    {
      "x": 1.811166,
      "y": -0.718041,
      "theta": -0.914195
    }
  ],
  "best_fresh_solution": [
    {
      "x": 0.64086,
      "y": 0.22326,
      "theta": 2.821873
    },
    {
      "x": 1.4404,
      "y": 1.128999,
      "theta": -0.81406
    },
    {
      "x": -1.655989,
      "y": -0.42319,
      "theta": 0.10482
    },
    {
      "x": 1.082212,
      "y": 2.173892,
      "theta": -1.561224
    },
    {
      "x": -0.944695,
      "y": 1.447571,
      "theta": -0.943244
    },
    {
      "x": 1.763155,
      "y": -0.844727,
      "theta": 2.506801
    },
    {
      "x": -0.072695,
      "y": -1.645052,
      "theta": 1.385971
    },
    {
      "x": -2.46987,
      "y": 1.561686,
      "theta": -0.420208
    },
    {
      "x": 1.185187,
      "y": 2.19654,
      "theta": 1.556021
    },
    {
      "x": -1.131542,
      "y": -2.464377,
      "theta": 1.061457
    },
    {
      "x": 2.464078,
      "y": -0.728975,
      "theta": -1.154113
    },
    {
      "x": -0.810236,
      "y": 2.780462,
      "theta": -0.843579
    },
    {
      "x": 0.840865,
      "y": -2.826028,
      "theta": 1.716597
    },
    {
      "x": 2.689812,
      "y": 0.464617,
      "theta": 0.297363
    },
    {
      "x": -2.662334,
      "y": -0.42897,
      "theta": 0.227441
    }
  ],
  "best_new_score_full": 2.948526950912552,
  "best_fresh_score_full": 3.297901422227196,
  "best_new_score": "2.94852695",
  "best_fresh_score": "3.29790142",
  "best_block_reinsertion_score": "2.94853103",
  "strict_radius": null,
  "selected_start": "inherited baseline",
  "structure": {
    "full_disks": 0,
    "sliding_seams": [
      [
        1,
        14
      ],
      [
        4,
        8
      ]
    ],
    "flats": "Opposed diameters are displaced along the seam by roughly 0.853 and 0.319 units. Piece 12 has the farthest disk center and faces inward, with a diameter endpoint on the enclosing circle. Other flats vary with their contacts.",
    "rim_pieces": [
      3,
      4,
      5,
      6,
      9,
      10,
      11,
      12,
      13,
      14
    ],
    "interior_pieces": [
      0,
      1,
      2,
      7,
      8
    ],
    "symmetry": "No evident rotational or reflection symmetry.",
    "effect": "Sliding along the diameters lets outer pieces and interior pieces share space without requiring coincident disk centers."
  },
  "scorer_check": {
    "random": {
      "pairs": 2520,
      "disagreements": 0,
      "max_abs_area_difference": 2.0353515983728698e-07,
      "layouts": 24,
      "max_abs_radius_difference": 2.5873525544284348e-11
    },
    "tight": {
      "pairs": 120,
      "disagreements": 0,
      "max_abs_area_difference": 1.8055509468284023e-09
    },
    "baseline": {
      "pairs": 105,
      "disagreements": 6,
      "max_abs_area_difference": 1.782502247599566e-09
    },
    "seed": 406388579,
    "baseline_mec": [
      -0.0001819080617291321,
      0.00013448996991973104,
      2.9485269509127
    ],
    "final_max_exact_pair_area": 1.0013726927313171e-06,
    "area_method": "Green’s theorem over analytically clipped unit arcs and diameter segments.",
    "mec_method": "Convex radius minimization with analytically maximized distance on each semicircle.",
    "case_design": "The seeded check used 24 layouts uniform on [-3,3] squared and angles uniform on [-pi,pi]. It also used 40 arc–arc, 40 arc–flat, and 40 flat–flat cases targeted near the 1e-6 cutoff, with random translations and rotations. Every layout and pair was rounded before comparison.",
    "sample_official_score": "3.500000",
    "official_repo_tests_passed": 31,
    "final_validate_and_score_from_clean_checkout": true
  },
  "runs": [
    {
      "seed": 1159641123,
      "start_kind": "fresh-grid",
      "minutes": 6.610162529007842,
      "attempts": 145,
      "valid_count": 1,
      "best_radius": 3.636761026898483,
      "score_kind": "official",
      "errors": {
        "exact area prefilter": 144
      }
    },
    {
      "seed": 1166987617,
      "start_kind": "fresh",
      "minutes": 7.09048981089145,
      "attempts": 200,
      "valid_count": 7,
      "best_radius": 566.7136697935942,
      "score_kind": "official",
      "errors": {
        "exact area prefilter": 193
      }
    },
    {
      "seed": 1244978724,
      "start_kind": "rounding-aware local polish",
      "minutes": 7.0468328439320125,
      "attempts": 118,
      "valid_count": 16,
      "best_radius": 2.9485282316935333,
      "score_kind": "official",
      "errors": {
        "Semicircles 4 and 8 overlap": 102,
        "Semicircles 1 and 14 overlap": 22,
        "Semicircles 0 and 3 overlap": 1
      }
    },
    {
      "seed": 1696249067,
      "start_kind": "seam-aware lattice polish",
      "minutes": 6.641048055685435,
      "attempts": 30,
      "valid_count": 18,
      "best_radius": 2.948528245462032,
      "score_kind": "official",
      "errors": {
        "no lattice incumbent": 12
      }
    },
    {
      "seed": 1954938892,
      "start_kind": "fresh-grid",
      "minutes": 3.6740994059480725,
      "attempts": 184,
      "valid_count": 1,
      "best_radius": 3.297901422227196,
      "score_kind": "official",
      "errors": {
        "exact area prefilter": 183
      }
    },
    {
      "seed": 2463150038,
      "start_kind": "fresh",
      "minutes": 7.099591403470064,
      "attempts": 207,
      "valid_count": 1,
      "best_radius": 209.81365849202885,
      "score_kind": "official",
      "errors": {
        "exact area prefilter": 206
      }
    },
    {
      "seed": 2575735499,
      "start_kind": "seam-aware lattice polish",
      "minutes": 6.233968033843364,
      "attempts": 73,
      "valid_count": 0,
      "best_radius": null,
      "score_kind": "official",
      "errors": {
        "Semicircles 4 and 8 overlap": 73,
        "Semicircles 1 and 2 overlap": 1,
        "Semicircles 12 and 14 overlap": 8,
        "Semicircles 5 and 8 overlap": 5,
        "Semicircles 11 and 13 overlap": 6,
        "Semicircles 2 and 13 overlap": 3,
        "Semicircles 0 and 9 overlap": 1,
        "Semicircles 2 and 7 overlap": 1,
        "Semicircles 7 and 8 overlap": 3,
        "Semicircles 4 and 9 overlap": 1,
        "Semicircles 0 and 2 overlap": 1,
        "Semicircles 8 and 9 overlap": 1,
        "Semicircles 4 and 5 overlap": 1
      }
    },
    {
      "seed": 281411952,
      "start_kind": "seam-aware lattice polish",
      "minutes": 6.556538155814633,
      "attempts": 50,
      "valid_count": 22,
      "best_radius": 2.948526950912552,
      "score_kind": "official",
      "errors": {
        "no lattice incumbent": 28
      }
    },
    {
      "seed": 3558257477,
      "start_kind": "seam-aware lattice polish",
      "minutes": 6.187160881298284,
      "attempts": 76,
      "valid_count": 32,
      "best_radius": 2.948528245462032,
      "score_kind": "official",
      "errors": {
        "no lattice incumbent": 44
      }
    },
    {
      "seed": 391948515,
      "start_kind": "seam-aware lattice polish",
      "minutes": 6.757333162240684,
      "attempts": 111,
      "valid_count": 111,
      "best_radius": 2.948527408919511,
      "score_kind": "official",
      "errors": {}
    },
    {
      "seed": 3973929218,
      "start_kind": "baseline",
      "minutes": 7.107159075963621,
      "attempts": 162,
      "valid_count": 6,
      "best_radius": 2.948531029481951,
      "score_kind": "official",
      "errors": {
        "exact area prefilter": 150,
        "official rejection": 6
      }
    },
    {
      "seed": 559687532,
      "start_kind": "baseline reinsertion lattice polish",
      "minutes": 7.096563647485649,
      "attempts": 120,
      "valid_count": 0,
      "best_radius": null,
      "score_kind": "official",
      "errors": {
        "official rejection": 120
      }
    }
  ],
  "prior_round_reported_scores": [
    {
      "strategy": "cma-es",
      "reported_radius": 3.02081451,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "3.02081451",
      "local_errors": [],
      "sha256": "9b93e2ed4de5a95fd82268d4d16fbbcdd424365f3b491f82e9593ec4a630715e"
    },
    {
      "strategy": "diff-evolution",
      "reported_radius": 3.04084534,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "3.04084534",
      "local_errors": [],
      "sha256": "5e21fa1cc1c5d03397d3a7174fab39a9b309ff256372c9a3f7bde116491cc0e3"
    },
    {
      "strategy": "flats-on-rim",
      "reported_radius": 3.00113305,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "3.00113305",
      "local_errors": [],
      "sha256": "3c4e8ebc6358be8f9d5282d044a86f261a9aa266d934a45d1055244dce89d5d9"
    },
    {
      "strategy": "flats-to-centre",
      "reported_radius": 2.9632139,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "2.96321390",
      "local_errors": [],
      "sha256": "48136c0ce3de775847e9552c7769cd159326d5fe66bae6e220314061514f1af1"
    },
    {
      "strategy": "no-pairs",
      "reported_radius": "3.03051443",
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "3.03051443",
      "local_errors": [],
      "sha256": "2faa94063d84c1d90ed0c9d02d971eab5bae4a5500494b4330c1a9bbae812f19"
    },
    {
      "strategy": "pairs-1-4",
      "reported_radius": 2.97438934,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "2.97438934",
      "local_errors": [],
      "sha256": "a9e45b112408be2bd2c257bf0b325caa662e5d914703ad640079ef73b446b83b"
    },
    {
      "strategy": "pairs-5-5",
      "reported_radius": 2.95475629,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "2.95475629",
      "local_errors": [],
      "sha256": "e5a5fe2cd0aa58f0b6d60d12a66e3a2976b628f1bdfcb42757ae89188f58ec61"
    },
    {
      "strategy": "pairs-6-3",
      "reported_radius": 2.97726863,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "2.97726863",
      "local_errors": [],
      "sha256": "9fab734175cef0454e15d89586a396de552e9a6ec288e71755fce4b183c7f0cb"
    },
    {
      "strategy": "pairs-7-1",
      "reported_radius": "3.06352356",
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "3.06352356",
      "local_errors": [],
      "sha256": "d59f73e64c56ed584e964006e98ee46c03edc85995d04b5517e6af14194277e1"
    },
    {
      "strategy": "rings-159-267",
      "reported_radius": "2.99381251",
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "2.99381251",
      "local_errors": [],
      "sha256": "c0fd3edd0bbe4ff31859c5ae1e8b72ac69412fa2f0d76005ff746c2991eb8876"
    },
    {
      "strategy": "rings-312-411",
      "reported_radius": 2.98539036,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "2.98539036",
      "local_errors": [],
      "sha256": "708b6b93a9c8c13123d15f70c8185ebcf6008bfc84058ad55aa4665b307df04a"
    },
    {
      "strategy": "symmetric",
      "reported_radius": 2.97035856,
      "reported_valid": true,
      "local_valid": true,
      "local_radius": "2.97035856",
      "local_errors": [],
      "sha256": "7201832288052d238d03202edfdf759c63d18bb9789948c682530bca71086a81"
    }
  ],
  "repo_commit": "78a78626f098cd236f3a09bb2cb242f72951599d",
  "source_urls": [
    "https://www.paradigm.xyz/puzzles/packing/about",
    "https://github.com/benedictbrady/shape-packing-challenge",
    "https://raw.githubusercontent.com/benedictbrady/shape-packing-challenge/78a78626f098cd236f3a09bb2cb242f72951599d/README.md",
    "https://raw.githubusercontent.com/benedictbrady/shape-packing-challenge/78a78626f098cd236f3a09bb2cb242f72951599d/src/semicircle_packing/geometry.py",
    "https://raw.githubusercontent.com/benedictbrady/shape-packing-challenge/78a78626f098cd236f3a09bb2cb242f72951599d/src/semicircle_packing/config.py",
    "https://raw.githubusercontent.com/benedictbrady/shape-packing-challenge/78a78626f098cd236f3a09bb2cb242f72951599d/run.py"
  ],
  "exploratory_commands": [
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python lattice-old.py run-3973929218.json 559687532 425 run-559687532.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python lattice-narrow.py fallback.json 1244978724 420 run-1244978724.json"
  ],
  "notes": [
    "All scores in runs are official scores after six-decimal rounding. max_pair_area is the largest official 4096-point polygon intersection. Indices are zero-based.",
    "Run durations are wall-clock limits. The search environment used SciPy 1.18.1, NumPy 2.5.5 and Shapely 2.2.0. The supplied sources consolidate checkpointing and evaluate the same analytic containment support directly.",
    "Fresh ring jitters initially allowed infeasible SLSQP moves with large excursions. The fresh-grid retry used bounded steps and a randomized separated hexagonal start.",
    "The exploratory lattice variants used a direct linearization of area. The exploratory commands are logged with their script names. The supplied lattice.py replaces both prototypes and uses interval constraints for the two nearly antiparallel flat seams.",
    "The final solution was rerun in a separate clean checkout at the pinned commit. An independent agent rerun was unavailable for this item.",
    "Extract solution_json verbatim to obtain solution.json and plot_svg to obtain the plot. The item format delivers both inside this JSON.",
    "The inherited packing ties the published score at five decimals. The best new coordinates tie it at eight decimals and the best joint reinsertion is larger. Near-parallel seams and arc contacts leave little slack after quantization."
  ],
  "plot_svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 620 660\" width=\"620\" height=\"660\">\n<title>Semicircle packing with official radius 2.94852695</title>\n<rect width=\"620\" height=\"660\" fill=\"#f8fafc\"/>\n<g transform=\"translate(310 305) scale(96 -96)\" stroke-width=\".014\">\n<circle cx=\"-0.0001819080616875258\" cy=\"0.00013448997007248039\" r=\"2.948526950912552\" fill=\"white\" stroke=\"#0f172a\"/>\n<path d=\"M 0.0051381157 -0.1693308867 A 1 1 0 0 1 1.0857118843 1.5136308867 Z\" fill=\"#75c9c8\" stroke=\"#24354b\"/>\n<path d=\"M 1.9275753810 -0.6283374736 A 1 1 0 0 1 0.3433926190 -1.8491425264 Z\" fill=\"#f3ad81\" stroke=\"#24354b\"/>\n<path d=\"M -1.5790287747 -0.1168339085 A 1 1 0 0 1 0.4107807747 -0.3184720915 Z\" fill=\"#9cb5e7\" stroke=\"#24354b\"/>\n<path d=\"M 1.1816593583 -0.1181806434 A 1 1 0 0 1 2.5045766417 1.3817826434 Z\" fill=\"#ddaddf\" stroke=\"#24354b\"/>\n<path d=\"M 1.0470193303 2.5681242241 A 1 1 0 0 1 -0.4906473303 1.2892257759 Z\" fill=\"#e5cd76\" stroke=\"#24354b\"/>\n<path d=\"M -0.7082409640 2.8092292699 A 1 1 0 0 1 -0.7391890360 0.8094687301 Z\" fill=\"#75c9c8\" stroke=\"#24354b\"/>\n<path d=\"M -1.7733509695 2.0650732533 A 1 1 0 0 1 -1.4759230305 0.0873127467 Z\" fill=\"#f3ad81\" stroke=\"#24354b\"/>\n<path d=\"M -1.5636075791 0.8971561896 A 1 1 0 0 1 0.4239875791 0.6747478104 Z\" fill=\"#9cb5e7\" stroke=\"#24354b\"/>\n<path d=\"M -0.7359155518 1.0852340422 A 1 1 0 0 1 0.8017515518 2.3641319578 Z\" fill=\"#ddaddf\" stroke=\"#24354b\"/>\n<path d=\"M 1.6997772937 0.5855339373 A 1 1 0 0 1 0.8242047063 2.3836920627 Z\" fill=\"#e5cd76\" stroke=\"#24354b\"/>\n<path d=\"M -2.5716224598 0.6581580941 A 1 1 0 0 1 -1.3182435402 -0.9003800941 Z\" fill=\"#75c9c8\" stroke=\"#24354b\"/>\n<path d=\"M -2.5705989103 -1.0791715255 A 1 1 0 0 1 -0.5756130897 -1.2207044745 Z\" fill=\"#f3ad81\" stroke=\"#24354b\"/>\n<path d=\"M 1.9752444350 -2.1888149163 A 1 1 0 0 1 0.1240255650 -2.9457750837 Z\" fill=\"#9cb5e7\" stroke=\"#24354b\"/>\n<path d=\"M -1.5012349943 -2.4837547519 A 1 1 0 0 1 -0.0775670057 -1.0790592481 Z\" fill=\"#ddaddf\" stroke=\"#24354b\"/>\n<path d=\"M 1.0190890575 -1.3284622620 A 1 1 0 0 1 2.6032429425 -0.1076197380 Z\" fill=\"#e5cd76\" stroke=\"#24354b\"/>\n</g><g font-family=\"sans-serif\" font-size=\"16\" fill=\"#0f172a\" text-anchor=\"middle\">\n<text x=\"397.90\" y=\"268.30\">0</text>\n<text x=\"393.22\" y=\"395.46\">1</text>\n<text x=\"249.67\" y=\"372.92\">2</text>\n<text x=\"518.62\" y=\"277.29\">3</text>\n<text x=\"309.70\" y=\"92.37\">4</text>\n<text x=\"198.29\" y=\"135.65\">5</text>\n<text x=\"112.26\" y=\"212.97\">6</text>\n<text x=\"250.60\" y=\"276.53\">7</text>\n<text x=\"340.17\" y=\"176.91\">8</text>\n<text x=\"469.13\" y=\"148.99\">9</text>\n<text x=\"90.37\" y=\"348.10\">10</text>\n<text x=\"155.99\" y=\"462.53\">11</text>\n<text x=\"394.78\" y=\"517.36\">12</text>\n<text x=\"263.88\" y=\"511.08\">13</text>\n<text x=\"509.66\" y=\"412.39\">14</text>\n<text x=\"310\" y=\"632\">Official enclosing radius 2.94852695</text></g></svg>",
  "search_source": {
    "area.cpp": "#include <algorithm>\n#include <cmath>\nusing namespace std;\nconst double pi=acos(-1.);\nstruct V {\n    double x,y;\n    V operator+(V b) const {return {x+b.x,y+b.y};}\n    V operator-(V b) const {return {x-b.x,y-b.y};}\n    V operator*(double s) const {return {x*s,y*s};}\n    double dot(V b) const {return x*b.x+y*b.y;}\n    double cross(V b) const {return x*b.y-y*b.x;}\n};\nV unit(double t){return {cos(t),sin(t)};}\nV perp(V v){return {-v.y,v.x};}\ndouble area(V d,V a,V b){\n    double ds=d.dot(d);\n    if(ds>=4) return 0;\n    V c[]={ {0,0},d }, n[]={a,b};\n    double ans=0;\n    for(int i=0;i<2;i++){\n        int j=1-i;\n        V diff=c[i]-c[j];\n        if(i==0 || ds>1e-30){\n            double t[10]={0,2*pi};\n            int count=2;\n            auto cut=[&](V normal,double h){\n                double mag=hypot(normal.x,normal.y);\n                if(abs(h)>=mag) return;\n                double ang=atan2(normal.y,normal.x), width=acos(h/mag);\n                t[count++]=fmod(ang-width+2*pi,2*pi);\n                t[count++]=fmod(ang+width+2*pi,2*pi);\n            };\n            cut(n[i],0);\n            cut(n[j],-diff.dot(n[j]));\n            cut(diff,-ds*.5);\n            sort(t,t+count);\n            for(int k=1;k<count;k++){\n                V u=unit((t[k]+t[k-1])*.5);\n                if(u.dot(n[i])>=0 && (u+diff).dot(n[j])>=0 && ds+2*u.dot(diff)<=1e-14)\n                    ans+=t[k]-t[k-1]+c[i].cross(unit(t[k])-unit(t[k-1]));\n            }\n        }\n        V v=perp(n[i])*(-1);\n        double projection=diff.dot(v), h=diff.dot(n[i]);\n        if(abs(h)>=1) continue;\n        double width=sqrt(1-h*h);\n        double lo=max(-1.,-projection-width), hi=min(1.,-projection+width);\n        double slope=v.dot(n[j]), off=diff.dot(n[j]);\n        if(abs(slope)<1e-15){\n            if(off<-1e-15 || (abs(off)<1e-15 && i==1 && n[i].dot(n[j])>0)) continue;\n        } else if(slope>0) lo=max(lo,-off/slope);\n        else hi=min(hi,-off/slope);\n        if(hi>lo) ans+=c[i].cross(v)*(hi-lo);\n    }\n    return max(0.,ans*.5);\n}\nextern \"C\" void overlap(int n,const double* p,int k,const int* pairs,double* out){\n    V normals[15];\n    for(int i=0;i<n;i++) normals[i]=unit(p[3*i+2]);\n    for(int m=0;m<k;m++){\n        int i=pairs[2*m],j=pairs[2*m+1];\n        out[m]=area({p[3*j]-p[3*i],p[3*j+1]-p[3*i+1]},normals[i],normals[j]);\n    }\n}\n",
    "search.py": "import ctypes as ct\nimport itertools\nimport json\nimport sys\nimport time\nfrom pathlib import Path\nimport numpy as np\nfrom scipy.optimize import minimize\nfrom semicircle_packing.geometry import Semicircle\nfrom semicircle_packing.scoring import validate_and_score\nROOT = Path(__file__).resolve().parent\nLIB = ct.CDLL(str(ROOT / 'area.so'))\nLIB.overlap.argtypes = [ct.c_int, ct.c_void_p, ct.c_int, ct.c_void_p, ct.c_void_p]\nPAIRS = np.array(list(itertools.combinations(range(15), 2)), dtype=np.int32)\nALL = np.arange(15)\nTOL = 1e-6\ndef areas(points, pairs=PAIRS):\n    points = np.ascontiguousarray(points, dtype=float)\n    pairs = np.ascontiguousarray(pairs, dtype=np.int32)\n    out = np.empty(len(pairs))\n    LIB.overlap(len(points), points.ctypes.data, len(pairs), pairs.ctypes.data, out.ctypes.data)\n    return out\ndef distances(points, center):\n    x,y = (points[:,:2]-center).T\n    c,s = np.cos(points[:,2]),np.sin(points[:,2])\n    radius = np.hypot(x,y)\n    support = np.where(x*c+y*s>=0, radius, np.abs(y*c-x*s))\n    return np.sqrt(radius**2+1+2*support)\ndef mec(points):\n    center = points[:, :2].mean(axis=0)\n    sol = minimize(lambda z: z[2], np.r_[center, max(distances(points, center))],\n                   constraints=[{'type': 'ineq', 'fun': lambda z: z[2] - distances(points, z[:2])}],\n                   method='SLSQP', options={'ftol': 1e-13, 'maxiter': 100})\n    return np.r_[sol.x[:2], max(distances(points, sol.x[:2]))]\ndef rounded(points):\n    p = points.copy()\n    p[:, 2] = (p[:, 2]+np.pi) % (2*np.pi) - np.pi\n    return np.array([[round(float(x),6) for x in row] for row in p])\ndef official(points):\n    return validate_and_score([Semicircle(*row) for row in rounded(points)])\ndef polish(points, moving=ALL, center=None, budget=TOL*.95, iterations=120):\n    if center is None:\n        center = mec(points)[:2]\n    subset = PAIRS[np.any(np.isin(PAIRS, moving), axis=1)]\n    working = points.copy()\n    budget = np.broadcast_to(budget, (len(subset),))\n    allowances = np.power(budget, 2/3)\n    def constraints(z):\n        working[moving] = z[:-3].reshape(-1,3)\n        a = areas(working, subset)\n        clearance = (allowances - np.power(a, 2/3))*10\n        return np.r_[z[-1]-distances(working,z[-3:-1]), clearance]\n    z = np.r_[working[moving].ravel(),center,max(distances(working,center))]\n    limits = np.tile([1.2,1.2,2.5],len(moving))\n    limits = np.r_[limits,.8,.8,max(1.,z[-1])]\n    fit = minimize(lambda x: x[-1], z, method='SLSQP', bounds=list(zip(z-limits,z+limits)) if 'grid' in sys.argv[1] else None, constraints=[\n        {'type':'ineq','fun':constraints}], options={'ftol':3e-11,'maxiter':iterations})\n    working[moving] = fit.x[:-3].reshape(-1,3)\n    return working, fit.x[-3:-1]\ndef neighbors(points, center, rng, attempt):\n    physical = points[:, :2] + (4/(3*np.pi))*np.column_stack(\n        (np.cos(points[:,2]),np.sin(points[:,2])))\n    d = np.linalg.norm(physical[:,None]-physical[None,:],axis=2)\n    cap = int(np.argmax(np.linalg.norm(points[:,:2]-center,axis=1)))\n    block = [cap if attempt % 3 != 2 else int(rng.integers(15))]\n    count = 2 + attempt % 2\n    while len(block)<count:\n        nearby = np.argsort(np.min(d[block],axis=0))\n        pool = [i for i in nearby if i not in block][:4]\n        block.append(int(rng.choice(pool,p=[.46,.28,.17,.09])))\n    return np.array(block)\ndef joint_candidates(points, block, center, rng, attempt):\n    others = np.setdiff1d(ALL, block)\n    subset = PAIRS[np.any(np.isin(PAIRS,block),axis=1)]\n    radii = distances(points,center)\n    r = max(radii)\n    occupied = points[block].copy()\n    candidates = []\n    for k in range(96):\n        trial = points.copy()\n        trial[block] = occupied\n        if k and k%3==0:\n            outer = np.argmax(radii[block])\n            inner = np.argmin(radii[block])\n            trial[block[[inner,outer]],:2] = occupied[[outer,inner],:2]\n            trial[block[[inner,outer]],2] += np.pi\n        if k and k%3==1:\n            i = rng.choice(block)\n            j,l = rng.choice(others,2,replace=False)\n            trial[i,:2] = (points[j,:2]+points[l,:2])/2\n            trial[i,2] = rng.uniform(-np.pi,np.pi)\n        if k:\n            scale = [.005,.025,.11,.28][(k//3+attempt)%4]\n            trial[block] += rng.normal(size=(len(block),3))*scale\n        a = areas(trial,subset)\n        excess = np.maximum(0,distances(trial[block],center)-r)\n        rank = float(np.sum(np.maximum(0,a-TOL)**(2/3)) + np.sum(excess))\n        candidates.append((rank,k,trial))\n    ordered = sorted(candidates,key=lambda item:item[:2])\n    return ordered[0][2], next(item[2] for item in ordered if item[1]%3==0 and item[1]!=0)\ndef count_error(stats, error):\n    errors = stats['errors']\n    errors[error] = errors.get(error,0)+1\ndef run_stats(seed, kind):\n    return dict(seed=seed,start_kind=kind,minutes=0,attempts=0,valid_count=0,\n                best_radius=None,score_kind='official',errors={},solution=None)\ndef checkpoint(stats, start, output):\n    stats['minutes'] = (time.monotonic()-start)/60\n    path = Path(output)\n    temp = path.with_suffix('.tmp')\n    temp.write_text(json.dumps(stats))\n    temp.replace(path)\ndef run(kind, seed, seconds, output):\n    rng = np.random.default_rng(seed)\n    if kind=='baseline':\n        points = np.array(json.loads((ROOT/'base.json').read_text()))\n        reference = official(points).score\n    elif kind=='fresh-grid':\n        grid=np.array([(2.12*(i+.5*(j%2)),1.84*j) for j in range(-2,3)\n                       for i in range(-2,3)])\n        xy=grid[np.argsort(np.linalg.norm(grid,axis=1))[:15]]\n        xy+=rng.uniform(-.025,.025,xy.shape)\n        a=rng.uniform(-np.pi,np.pi)\n        xy=xy@np.array([[np.cos(a),np.sin(a)],[-np.sin(a),np.cos(a)]])\n        points=np.c_[xy,np.arctan2(-xy[:,1],-xy[:,0])+rng.uniform(-2.3,2.3,15)]\n        reference=np.inf\n    else:\n        theta = np.r_[rng.uniform(-np.pi,np.pi,4),\n                      np.arange(11)*2*np.pi/11+rng.uniform(-.19,.19,11)]\n        rho = np.r_[rng.uniform(.2,1.2,4),rng.uniform(1.6,2.6,11)]\n        points = np.column_stack((rho*np.cos(theta),rho*np.sin(theta),\n                                  rng.uniform(-np.pi,np.pi,15)))\n        reference = np.inf\n    center = mec(points)[:2]\n    clock = time.monotonic()\n    due = clock + 55\n    stats = run_stats(seed, kind)\n    checkpoint(stats, clock, output)\n    attempt = 0\n    while time.monotonic()-clock < seconds:\n        block = neighbors(points,center,rng,attempt)\n        insertions = joint_candidates(points,block,center,rng,attempt)\n        trial = insertions[attempt%2]\n        if kind=='baseline':\n            budget = np.full(len(PAIRS),TOL*[.96,.98,1.0,1.025,1.04][attempt%5])\n            p,q = PAIRS.T\n            flats = np.cos(points[p,2]-points[q,2]) < -.99999\n            budget[flats] = TOL*[.40,.75,.95,1.0,1.0][attempt%5]\n        else:\n            budget = TOL*.65\n        trial, middle = polish(trial,block,center,iterations=40,budget=TOL*.85)\n        trial, middle = polish(trial,center=middle,budget=budget,iterations=100)\n        stats['attempts'] += 1\n        candidate = rounded(trial)\n        if max(areas(candidate)) > 1.35e-6:\n            count_error(stats,'exact area prefilter')\n        else:\n            score = official(candidate)\n            if score.valid:\n                stats['valid_count'] += 1\n                if stats['best_radius'] is None or score.score < stats['best_radius']:\n                    stats.update(best_radius=score.score,solution=candidate.tolist())\n                    checkpoint(stats, clock, output)\n                if score.score < reference:\n                    reference = score.score\n                    points, center = candidate,np.array(score.mec[:2])\n            else:\n                count_error(stats,'official rejection')\n        if kind!='baseline' and not stats['valid_count']:\n            if np.isfinite(trial).all() and max(areas(trial)) < max(areas(points)):\n                points,center=trial,middle\n        attempt += 1\n        if time.monotonic()>=due:\n            checkpoint(stats, clock, output)\n            due=time.monotonic()+55\n    checkpoint(stats, clock, output)\nif __name__=='__main__':\n    kind, seed, seconds, output = sys.argv[1:]\n    run(kind,int(seed),float(seconds),output)\n",
    "lattice.py": "import json\nimport sys\nimport time\nfrom pathlib import Path\nimport numpy as np\nfrom scipy.optimize import Bounds, LinearConstraint, milp\nfrom semicircle_packing.geometry import Semicircle, semicircle_polygon\nfrom search import PAIRS, areas, checkpoint, count_error, distances, mec, official, rounded, run_stats\ninp, seed, seconds, output = sys.argv[1:]\nseed=int(seed)\nrng=np.random.default_rng(seed)\np=np.array(json.loads(Path(inp).read_text())['solution'])\nbest=official(p).score\nstart=time.monotonic()\nstats=run_stats(seed,'seam-aware lattice polish')\ncheckpoint(stats,start,output)\nwhile time.monotonic()-start<float(seconds):\n    c=mec(p)\n    pairs=PAIRS[areas(p)>1e-7]\n    i,j=pairs.T\n    seam=np.cos(p[i,2]-p[j,2])<-.99999\n    ends={}\n    for i,j in pairs[seam]:\n        v=np.array([-np.sin(p[i,2]),np.cos(p[i,2])])\n        shift=(p[j,:2]-p[i,:2])@v\n        lo,hi=max(-1,shift-1),min(1,shift+1)\n        grid=np.linspace(lo,hi,65)\n        ends[i,j]=(np.r_[lo+0*grid,grid],np.r_[grid,hi+0*grid])\n    pairs=pairs[~seam]\n    z0=np.r_[p.ravel(),c[:2],c[2]]\n    def g(z):\n        a=z[:45].reshape(15,3)\n        n=np.c_[np.cos(a[:,2]),np.sin(a[:,2])]\n        seams=[]\n        for (i,j),(l,r) in ends.items():\n            v=np.array([-n[i,1],n[i,0]])\n            seams.extend((r-l)*((a[i,:2]-a[j,:2])@n[j]+(r+l)*.5*(v@n[j])))\n        radial=distances(a,z[45:47])\n        if seed==281411952:\n            v=n[:,::-1]*[-1,1]\n            d=a[:,:2]-z[45:47]\n            radial=np.r_[radial,np.linalg.norm(d+v,axis=1),np.linalg.norm(d-v,axis=1)]\n        return np.r_[np.r_[areas(a,pairs),seams]*1000,radial-z[47]]\n    y0=g(z0)\n    h=1e-6\n    jac=np.column_stack([(g(z0+d)-g(z0-d))/(2*h) for d in np.eye(48)*h])\n    polys=[semicircle_polygon(Semicircle(*row)) for row in p]\n    delta=areas(p,pairs)-[polys[i].intersection(polys[j]).area for i,j in pairs]\n    margin=rng.uniform(.01,.4)*1e-9\n    limit=(np.r_[(1e-6+delta-margin)*1000,\n                 np.full(130*len(ends),.9995e-3),np.zeros(45 if seed==281411952 else 15)]-y0)/h\n    scale=np.maximum(1e-5,np.linalg.norm(jac,axis=1))\n    width=int(rng.choice([2,4,6,9,14,20]))\n    low,high=np.full(48,-width),np.full(48,width)\n    if seed != 391948515:\n        n=2 if seed in (1696249067,281411952) else 3\n        low[:n]=high[:n]=0\n        low[-1],high[-1]=-width,0\n    fit=milp(np.r_[rng.normal(0,.00003,47),1.],integrality=np.r_[np.ones(45),np.zeros(3)],\n             bounds=Bounds(low,high),constraints=LinearConstraint(jac/scale[:,None],\n             -np.inf,limit/scale),options={'time_limit':{391948515:2.5,1696249067:22.,281411952:12.}.get(seed,5.),'mip_rel_gap':.005})\n    stats['attempts']+=1\n    if fit.x is not None:\n        candidate=rounded(p+np.rint(fit.x[:45]).reshape(15,3)*h)\n        result=official(candidate)\n        if result.valid:\n            stats['valid_count']+=1\n            if stats['best_radius'] is None or result.score<stats['best_radius']:\n                stats.update(best_radius=result.score,solution=candidate.tolist())\n            if result.score<best:\n                best,p=result.score,candidate\n        else:\n            for error in result.errors:\n                count_error(stats,error)\n    else:\n        count_error(stats,'no lattice incumbent')\n    checkpoint(stats,start,output)\n"
  },
  "commands": [
    "git clone https://github.com/benedictbrady/shape-packing-challenge official",
    "git -C official checkout --detach 78a78626f098cd236f3a09bb2cb242f72951599d",
    "(cd official && uv sync && uv run python run.py && uv pip install scipy==1.18.1)",
    "Extract search_source entries to the current directory. Convert inherited_baseline.solution to base.json as [x,y,theta] rows and write those rows under the solution key in fallback.json.",
    "g++ -O3 -shared -fPIC area.cpp -o area.so",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python search.py baseline 3973929218 425 run-3973929218.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python search.py fresh 2463150038 425 run-2463150038.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python search.py fresh 1166987617 425 run-1166987617.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python search.py fresh-grid 1159641123 395 run-1159641123.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python search.py fresh-grid 1954938892 220 run-1954938892.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python lattice.py fallback.json 391948515 405 run-391948515.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python lattice.py fallback.json 3558257477 370 run-3558257477.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python lattice.py run-3973929218.json 2575735499 370 run-2575735499.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python lattice.py fallback.json 1696249067 390 run-1696249067.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470s official/.venv/bin/python lattice.py fallback.json 281411952 390 run-281411952.json",
    "(cd official && uv run python run.py ../solution.json --save-plot ../packing.svg)"
  ]
}
