Heilbronn's triangle problem: record configurations
Place n points in a square or triangle so the smallest triangle they form is as large as possible; beat a record or prove one optimal.
| 1 | #!/usr/bin/env python3 |
| 2 | """The project's second judge (the check `improves`, which informs and does not gate a merge): for each instance the |
| 3 | pushed route has a candidate for, its best value against the best the default branch holds (constructions/ and routes/ |
| 4 | of the check's own checkout, the approved version) and against the public record. An instance improves when it exceeds |
| 5 | the default branch's best by more than the minimum gain (a relative 1e-9); it is a new record when it exceeds the |
| 6 | public record by as much. Passes when some instance improves. On the default branch itself it reports what it holds and |
| 7 | passes.""" |
| 8 | import os |
| 9 | import pathlib |
| 10 | import sys |
| 11 | |
| 12 | from heilbronn import INSTANCES, MIN_GAIN, best_of, card, decimal, gain, is_record, scan |
| 13 | |
| 14 | main_dir = pathlib.Path(sys.argv[2]) |
| 15 | held = best_of(scan([main_dir / "constructions", main_dir / "routes"])) |
| 16 | if os.environ.get("SS_ROUTE_DIR", "") == "routes": |
| 17 | new = [k for k in INSTANCES if k in held and is_record(k, held[k][0])] |
| 18 | print(f"the default branch holds {len(held)} of {len(INSTANCES)} instances; " + (f"new records: {', '.join(new)}" if new else "no new record")) |
| 19 | sys.exit(0) |
| 20 | route = best_of(scan([pathlib.Path(sys.argv[1])])) |
| 21 | if not route: |
| 22 | print("no configuration in this route to compare") |
| 23 | sys.exit(1) |
| 24 | better, new = [], [] |
| 25 | for k in (k for k in INSTANCES if k in route): |
| 26 | v, name = route[k] |
| 27 | h = held.get(k) |
| 28 | up = h is None or v > h[0] * (1 + MIN_GAIN) |
| 29 | better += [k] if up else [] |
| 30 | new += [k] if is_record(k, v) else [] |
| 31 | against = f"the default branch's {decimal(h[0])}, {gain(v, h[0])}" if h else "nothing on the default branch" |
| 32 | print(f"{k}: {decimal(v)} ({name}) against {against}{': improves' if up else ''}; " |
| 33 | + (f"a new record, above {card(k)} by more than a relative 1e-9" if is_record(k, v) else f"the record is {card(k)}")) |
| 34 | if not better: |
| 35 | print("no improvement on the default branch by more than a relative 1e-9") |
| 36 | sys.exit(1) |
| 37 | print(f"improves on the default branch: {', '.join(better)}; " + (f"new records: {', '.join(new)}" if new else "no new record")) |
