#!/usr/bin/env python3 """Route 4, job 959: integer frontier per support by MILP bisection on n. n_cov = largest n with a phase vector found AND rechecked in integer arithmetic (exact: a cover exists); n_cov + 1 is MILP-infeasible (solver status only). Covering is monotone in n, so bisection is valid. Input: 'a n*' pairs from the census (weighted frontier). stdout is the artifact; no randomness. python ifront959.py census959w.out 40 """ import importlib.util, os, sys HERE = os.path.dirname(os.path.abspath(__file__)) s = importlib.util.spec_from_file_location('cv', os.path.join(HERE, 'cover959.py')); cv = importlib.util.module_from_spec(s); s.loader.exec_module(cv) sys.stdout.reconfigure(newline='\n') rows = [] for line in open(sys.argv[1]): p = line.split() if len(p) > 2 and p[0].isdigit() and p[1].isdigit(): rows.append((int(p[0]), int(p[1]))) rows = rows[:int(sys.argv[2])] print('a n* L* n_cov L_cov n_cov+1 status gap_slots gap_L') def cov(a, n, D): st, msg, ph = cv.solve(D[:n]) if ph is None: return False, st ok = all(any((x + ph[q]) % q == 0 or (x + ph[q] + 2) % q == 0 for q in cv.QS) for x in D[:n]) assert ok, 'MILP phase vector failed recheck' return True, st gaps = [] for a, ns in rows: D = cv.rw.slots_from(a, ns, cv.OLD) lo, hi = 1, ns # lo coverable (1 slot trivially), hi: n* (weighted-certified non-coverable) status = {} while hi - lo > 1: m = (lo + hi) // 2 c, st = cov(a, m, D) status[m] = st if c: lo = m else: hi = m Ls, Lc = D[ns - 1] - a + 1, D[lo - 1] - a + 1 nxt = 'weighted-cert' if hi == ns else f'milp-status-{status[hi]}' gaps.append(ns - hi) print(flush=True) if False else None; print(f'{a:<8d} {ns:<3d} {Ls:<5d} {lo:<6d} {Lc:<6d} {nxt:<17s} {ns - hi:<10d} {Ls - (D[hi - 1] - a + 1)}', flush=True) print(f'supports {len(gaps)}; gap (n* - first MILP-infeasible n) min {min(gaps)} median {sorted(gaps)[len(gaps)//2]} max {max(gaps)}')