#!/usr/bin/env python3 """Job #4192, POST-HOC probe (labelled as such; not pre-registered): after the sparse search showed that every certified support uses nearly all of anchor 101's conditioned rows and only 18 of anchor 103's 51 phases, does a Farkas certificate exist with y restricted to ONE anchor's rows? Bounded search as #1848's solve1291.py (maximise f.z subject to A_S^T y_S + E^T z <= 0, f.z <= 1, y_S >= 0). Optimum 1 means a certificate exists; it is rounded, shifted by u1111.json and checked with check1291.py unchanged. Optimum 0 means that no certificate uses only those rows (an LP value, reported as measured). stdout JSON.""" import json, sys, time, warnings import numpy as np from scipy.optimize import linprog, OptimizeWarning from scipy.sparse import csr_matrix, hstack, vstack sys.path.insert(0, '.') from split1090 import build, load, MAPS import sparse4192 as S _, mapping = load('maps1086.json', MAPS) A, E, f, sng, blk, lab, cov, *_ = build(mapping) nA, nE = A.shape[0], E.shape[0] fv = np.asarray(f, dtype=float) U = json.loads(open('u1111.json', 'rb').read()) out = {} for h in (101, 103): keep = np.array([c[0] == h for c in cov]) top = hstack([A.T.tocsr(), E.T.tocsr()], format='csr') nzf = np.flatnonzero(fv != 0) norm = csr_matrix((fv[nzf], (np.zeros(len(nzf), dtype=int), nA + nzf)), shape=(1, nA + nE)) A_ub = vstack([top, norm], format='csr'); b_ub = np.concatenate([np.zeros(A.shape[1]), np.ones(1)]) c = np.zeros(nA + nE); c[nA:] = -fv bounds = [(0, None) if keep[r] else (0, 0) for r in range(nA)] + [(None, None)] * nE t = time.time() with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=OptimizeWarning) lp = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method='highs-ds', options={'time_limit': 1800.0, 'primal_feasibility_tolerance': 1e-9, 'dual_feasibility_tolerance': 1e-9}) rec = {'anchor_only': h, 'rows_allowed': int(keep.sum()), 'status': int(lp.status), 'message': str(lp.message)[:80], 'max_f_dot_z': None if lp.x is None else float(-lp.fun), 'wall_s': round(time.time() - t)} if lp.x is not None and -lp.fun > 0.5: cr, supp = S.certify('only%d' % h, A, E, f, lab, cov, lp.x[:nA], lp.x[nA:], U) rec['certification'] = {k: cr.get(k) for k in ('check1291_verdict', 'y_nonzero', 'z_nonzero', 'slots_total', 'delta', 'check1291_fail_lines', 'certificate_sha256')} out[str(h)] = rec print(json.dumps(rec), file=sys.stderr, flush=True) print(json.dumps(out, sort_keys=True, indent=1))