#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Route 21 / job #1306 runner: max-min one-step margin on the declared windows. python3 run_maxmin.py [window_start ...] default: 1160000 1240000 1280000 1000000 Writes route21_maxmin_results.json next to this file and prints a compact summary plus the sha256 of each window's record. Deterministic, stdlib only, no network, no input files. """ import hashlib import json import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) from route21_maxmin_margin import solve_window # noqa: E402 from route21_model import Instance # noqa: E402 DEFAULT_WINDOWS = [1160000, 1240000, 1280000, 1000000] OUT = os.path.join(HERE, "route21_maxmin_results.json") def occupancy(ws): """sum_q occ_q: the scan's ranking statistic (max class-pair occupancy over the old owners).""" inst = Instance(ws) occ = {} for q, pairs in inst.pairs_old.items(): occ[q] = max(len(p) for p in pairs.values()) return sum(occ.values()), occ, inst.span + 1 def main(): windows = [int(a) for a in sys.argv[1:]] or DEFAULT_WINDOWS out = {} for ws in windows: s, occ, L = occupancy(ws) print(f"window {ws}: L={L} sum_occ={s} occ={occ}", flush=True) rec = solve_window(ws, verbose=True) rec["sum_occ"] = s rec["occ"] = {str(k): v for k, v in occ.items()} key = {k: v for k, v in rec.items() if k != "profile"} out[str(ws)] = rec mm = rec.get("max_min_margin", rec.get("upper_bound_relaxation")) print(f" -> max-min margin {mm} (exact={rec['exact']}), delta {rec.get('delta')}, " f"positive phases {rec.get('positive_phases')}, argmin phase {rec.get('argmin_phase')}, " f"rows {rec['cuts']}, {rec['wall_s']}s, certificate " f"{rec.get('restricted_lp_certificate', {}).get('all_conditions')}", flush=True) print(" record sha256:", hashlib.sha256(json.dumps(key, sort_keys=True, default=str).encode()).hexdigest(), flush=True) with open(OUT, "w", encoding="utf-8") as f: json.dump(out, f, indent=1, sort_keys=True, default=str) h = hashlib.sha256(open(OUT, "rb").read()).hexdigest() print("wrote", OUT) print("sha256(route21_maxmin_results.json):", h) if __name__ == "__main__": main()