#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Route 21 / job #1324: gather the per-cell records of run_maxmin_N.py into one artifact and a table. python3 summarize_grid.py out/*.json > route21_N_grid_results.json (stdout = the artifact) The table goes to stderr. Independent re-check per cell: the returned w is re-scored on a fresh Instance (all 47 phases) and the reported max-min margin must equal that oracle minimum exactly. """ import json, sys, os from fractions import Fraction as F sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from route21_model import Instance, LEAVING, ENTERING, Q_OLD cells = {} for f in sorted(sys.argv[1:]): d = json.load(open(f)) if not d.get("exact"): cells[f"{d['window_start']}_N{d['N']}"] = {k: d[k] for k in d if k != "slots"}; continue inst = Instance(d["window_start"], n=d["N"]) w = [F(v) for v in d["w"]] assert sum(w) == 1 and all(v >= 0 for v in w) m_or, arg, prof = inst.oracle(w) d["recheck_oracle_min"] = str(m_or) d["recheck_matches"] = (m_or == F(d["max_min_margin"])) and arg["phase"] == d["argmin_phase"] d["recheck_L"] = inst.span + 1 cells[f"{d['window_start']}_N{d['N']}"] = {k: d[k] for k in d if k not in ("profile",)} print(f"{d['window_start']:>8} N={d['N']:<3} L={d['span_L']:<5} sum_occ={d['sum_occ']:<3} " f"maxmin={d['max_min_margin']:>22} ({d['max_min_margin_float']:+.6f}) delta={d['delta_at_optimum']:>18} " f"argmin={d['argmin_phase']:<3} sat={str(d['argmin_saturates_C47']):<5} " f"eq(delta-C'89-D)={str(d['equals_delta_minus_Cp89_minus_D']):<5} C'89={d['Cprime_89_at_argmin']:>14} " f"D={d['D_other_owners_loss_at_argmin']:>12} C47={d['C_47']:>12} pos={d['positive_phases']}/47 " f"cert={d['certificate_all_conditions']} recheck={d['recheck_matches']} {d['wall_s']}s", file=sys.stderr) print(json.dumps(cells, indent=1, sort_keys=True))