#!/usr/bin/env python3 """The project's second judge (the check `improves`, which informs and does not gate a merge): for each instance the pushed route has a candidate for, its best value against the best the default branch holds (constructions/ and routes/ of the check's own checkout, the approved version) and against the public record. An instance improves when it exceeds the default branch's best by more than the minimum gain (a relative 1e-9); it is a new record when it exceeds the public record by as much. Passes when some instance improves. On the default branch itself it reports what it holds and passes.""" import os import pathlib import sys from heilbronn import INSTANCES, MIN_GAIN, best_of, card, decimal, gain, is_record, scan main_dir = pathlib.Path(sys.argv[2]) held = best_of(scan([main_dir / "constructions", main_dir / "routes"])) if os.environ.get("SS_ROUTE_DIR", "") == "routes": new = [k for k in INSTANCES if k in held and is_record(k, held[k][0])] print(f"the default branch holds {len(held)} of {len(INSTANCES)} instances; " + (f"new records: {', '.join(new)}" if new else "no new record")) sys.exit(0) route = best_of(scan([pathlib.Path(sys.argv[1])])) if not route: print("no configuration in this route to compare") sys.exit(1) better, new = [], [] for k in (k for k in INSTANCES if k in route): v, name = route[k] h = held.get(k) up = h is None or v > h[0] * (1 + MIN_GAIN) better += [k] if up else [] new += [k] if is_record(k, v) else [] against = f"the default branch's {decimal(h[0])}, {gain(v, h[0])}" if h else "nothing on the default branch" print(f"{k}: {decimal(v)} ({name}) against {against}{': improves' if up else ''}; " + (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)}")) if not better: print("no improvement on the default branch by more than a relative 1e-9") sys.exit(1) print(f"improves on the default branch: {', '.join(better)}; " + (f"new records: {', '.join(new)}" if new else "no new record"))