Snakes in the box in dimensions 13 to 16
Find longer snakes, induced paths in the hypercube, in dimensions 13 to 16: beat 2946, 5850, 11,673 and 23,318 edges.
| 1 | #!/usr/bin/env python3 |
| 2 | """The project's second judge (the check `improves`, which informs and does not gate a merge): for each dimension the |
| 3 | pushed route has a snake for, its longest snake against the longest the default branch holds (constructions/ and routes/ |
| 4 | of the check's own checkout, the approved version) and against the public record. A dimension improves when the route's |
| 5 | snake has at least one edge more; it is a new record when it has at least one edge more than the record. Passes when |
| 6 | some dimension improves. On the default branch itself it reports what it holds and passes.""" |
| 7 | import os |
| 8 | import pathlib |
| 9 | import sys |
| 10 | |
| 11 | from snake import INSTANCES, best_of, card, is_record, scan |
| 12 | |
| 13 | main_dir = pathlib.Path(sys.argv[2]) |
| 14 | held = best_of(scan([main_dir / "constructions", main_dir / "routes"])) |
| 15 | if os.environ.get("SS_ROUTE_DIR", "") == "routes": |
| 16 | new = [k for k in INSTANCES if k in held and is_record(k, held[k][0])] |
| 17 | holds = ", ".join(f"{k}: {held[k][0]}" for k in INSTANCES if k in held) or "no snake" |
| 18 | print(f"the default branch holds {holds}; " + (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 snake 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 | length, name = route[k] |
| 27 | h = held.get(k) |
| 28 | up = h is None or length > h[0] |
| 29 | better += [k] if up else [] |
| 30 | new += [k] if is_record(k, length) else [] |
| 31 | against = f"the default branch's {h[0]}, {length - h[0]:+d}" if h else "nothing on the default branch" |
| 32 | print(f"{k}: {length} edges ({name}) against {against}{': improves' if up else ''}; " |
| 33 | + (f"a new record, above {card(k)}" if is_record(k, length) else f"the record is {card(k)}")) |
| 34 | if not better: |
| 35 | print("no improvement on the default branch") |
| 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")) |
