#!/usr/bin/env python3 """Job #1090: verdict for the split-ordinary-singleton relaxation. Pipeline, all from #451's maps: 1. CONTROL (exact, no solver): rebuild #1086's OLD model (19 common singletons) and verify #451's own integer Farkas certificate against it. It must verify with RHS 288 - that is what licenses the model builder, since it reproduces a published infeasibility refutation. 2. NEW model (17 ordinary singleton vectors split into independently normalized per-star copies, anchors common, blocks and conditioned rows unchanged): one bounded HiGHS solve, plus a dual-simplex solve whose duals are repaired to integers and verified exactly. 3. Verdict: an exact verified certificate means infeasible; a feasible LP status with no certificate is reported as measured, not as a refutation. stdout is the artifact; progress and timings go to stderr. """ import argparse import json import sys import time import warnings from pathlib import Path import numpy as np from scipy.optimize import linprog, OptimizeWarning from scipy.sparse import csr_matrix, vstack, hstack HERE = Path(__file__).parent sys.path.insert(0, str(HERE)) from split1090 import build, verify, repair, load, MAPS, GLOBAL, LAYOUT # noqa: E402 from ray1090 import old_model # noqa: E402 T0 = time.process_time() def combined(A, E, y, z): Ai = csr_matrix((A.data.astype(np.int64), A.indices, A.indptr), shape=A.shape) Ei = csr_matrix((E.data.astype(np.int64), E.indices, E.indptr), shape=E.shape) return np.asarray(Ai.T.dot(np.asarray(y, dtype=np.int64)) + Ei.T.dot(np.asarray(z, dtype=np.int64)), dtype=np.int64) def quick_ok(A, E, labels, y, z): coef = combined(A, E, y, z) norm = sum(int(z[i]) for i, L in enumerate(labels) if L[0] in ('normalization', 'normalization_copy')) return bool(int(coef.max()) <= 0 and norm > 0), int(coef.max()), norm def solve(A, E, f, elastic, seconds, method): if elastic: rhs_ub = np.zeros(A.shape[0]) c = np.zeros(A.shape[1] + 1) c[-1] = 1.0 eqm = hstack([E, csr_matrix((E.shape[0], 1))], format='csr') ub = hstack([-A, csr_matrix(-np.ones((A.shape[0], 1)))], format='csr') bounds = (0, None) else: ub, rhs_ub, c, eqm, bounds = -A, np.zeros(A.shape[0]), np.zeros(A.shape[1]), E, (0, None) with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=OptimizeWarning) lp = linprog(c, A_ub=ub, b_ub=rhs_ub, A_eq=eqm, b_eq=f, bounds=bounds, method=method, options={'threads': 1, 'time_limit': float(seconds), 'primal_feasibility_tolerance': 1e-9, 'dual_feasibility_tolerance': 1e-9}) return lp def main(): ap = argparse.ArgumentParser() ap.add_argument('--seconds', type=float, default=25.0) ap.add_argument('--elastic-seconds', type=float, default=25.0) ap.add_argument('--method', default='highs-ds') args = ap.parse_args() _, mapping = load('maps1086.json', MAPS) _, glob = load('global1086.json', GLOBAL) _, layout = load('layout1086.json', LAYOUT) out = {'job': 1090, 'route_id': 8, 'revision': 8, 'source_maps_sha256': MAPS, 'source_certificate_sha256': GLOBAL, 'definition': ('ordinary singleton vectors split into independently normalized per-star' ' copies; anchors 101/103 keep one common vector each; the 36 owned joint' ' blocks, marginal equations and conditioned rows are #1086\'s'), 'sequence': ('previous rev7 step (#1086/#451): common singletons 101/103 + independent' ' anchor joints is infeasible; this step relaxes the 17 ordinary prime' ' singleton ties and keeps the two anchor singletons common')} # ---------------- control: exact verification of #451's certificate on the rebuilt OLD model A_o, E_o, f_o, sing_o, blk_o, lab_o, cov_o, size = old_model(mapping) cd = glob['certificate'] y_o, z_o = cd['inequality_multipliers'], cd['equality_multipliers'] assert len(y_o) == len(cov_o) and len(z_o) == len(lab_o) ok_o, mx_o, norm_o = quick_ok(A_o, E_o, lab_o, y_o, z_o) v_o = verify(A_o, E_o, f_o, lab_o, [int(v) for v in y_o], [int(v) for v in z_o]) if ok_o else None out['control'] = {'kind': 'rebuild #1086 model and verify its own certificate exactly', 'old_variables': int(A_o.shape[1]), 'old_equalities': int(E_o.shape[0]), 'old_conditioned_rows': int(A_o.shape[0]), 'old_layout_variables_match': int(A_o.shape[1]) == layout['variables'], 'old_layout_equalities_match': int(E_o.shape[0]) == layout['equalities'], 'max_combined_coefficient': mx_o, 'normalization_multiplier_sum': norm_o, 'certificate_verifies': bool(ok_o), 'python_integer_sweep': v_o} print(json.dumps({'stage': 'control', 'old_variables': int(A_o.shape[1]), 'max_coef': mx_o, 'rhs': norm_o, 'verifies': bool(ok_o), 'cpu_seconds': time.process_time() - T0}), file=sys.stderr, flush=True) # ---------------- new split model A_s, E_s, f_s, sng, blk_s, lab_s, cov_s, size2, ordq, H, Q, kind = build(mapping) st, ray = None, None lp = solve(A_s, E_s, f_s, False, args.seconds, args.method) st = int(lp.status) print(json.dumps({'stage': 'split feasibility', 'status': st, 'success': bool(lp.success), 'message': str(lp.message)[:120], 'cpu_seconds': time.process_time() - T0}), file=sys.stderr, flush=True) out['split_feasibility'] = {'method': args.method, 'status': st, 'success': bool(lp.success), 'message': str(lp.message)[:200], 'variables': int(A_s.shape[1]), 'equalities': int(E_s.shape[0]), 'conditioned_rows': int(A_s.shape[0]), 'ordinary_singletons_split': len(ordq), 'anchors_common': list(H)} cert = None if st == 0: out['verdict'] = 'feasible_split_ordinary_singletons' art = {'kind': 'feasibility_status_only', 'method': args.method, 'status': st, 'note': ('HiGHS returned optimal for the pure feasibility LP, so no Farkas' ' certificate exists; the witness is the solver point, which this return' ' does not certify exactly')} out['certificate'] = None out['witness_note'] = art else: lp2 = solve(A_s, E_s, f_s, True, args.elastic_seconds, args.method) audit = [] if lp2.x is not None: for T in (1e3, 1e6, 1e9): y = np.rint(np.maximum(-lp2.ineqlin.marginals, 0) * T).astype(np.int64) z = np.rint(lp2.eqlin.marginals * T).astype(np.int64) if int(np.max(np.abs(y))) >= 10 ** 15 or int(np.max(np.abs(z))) >= 10 ** 15: continue ok, mx, norm = quick_ok(A_s, E_s, lab_s, y, z) audit.append({'scale': T, 'raw_ok': ok, 'max_combined_coefficient': mx, 'normalization_multiplier_sum': norm}) if ok: v = verify(A_s, E_s, f_s, lab_s, [int(t) for t in y], [int(t) for t in z]) if v['ok']: cert = {'kind': 'integer_farkas_from_elastic_duals', 'scale': T, 'inequality_multipliers': [int(t) for t in y], 'equality_multipliers': [int(t) for t in z], 'positive_rhs': int(v['normalization_multiplier_sum']), 'verification': v} break y2, z2, rep, lrep = repair(y, z, mapping, lab_s, cov_s, size2, ordq, H, sng) ok2, mx2, norm2 = quick_ok(A_s, E_s, lab_s, y2, z2) audit.append({'scale': T, 'repaired_ok': ok2, 'max_combined_coefficient': mx2, 'normalization_multiplier_sum': norm2}) if ok2: v = verify(A_s, E_s, f_s, lab_s, [int(t) for t in y2], [int(t) for t in z2]) if v['ok']: cert = {'kind': 'integer_farkas_from_elastic_duals_repaired', 'scale': T, 'inequality_multipliers': [int(t) for t in y2], 'equality_multipliers': [int(t) for t in z2], 'positive_rhs': int(v['normalization_multiplier_sum']), 'verification': v, 'pair_repairs': rep, 'singleton_repairs': lrep} break out['certificate'] = cert out['elastic'] = {'status': int(lp2.status), 'success': bool(lp2.success), 'elastic_min': None if lp2.x is None else float(lp2.x[-1]), 'audit': audit} out['verdict'] = ('infeasible_split_ordinary_singletons' if cert else 'inconclusive_no_exact_certificate') text = json.dumps(out, sort_keys=True, indent=2) + '\n' (HERE / 'ds1090.json').write_text(text, encoding='utf-8', newline='\n') print(text, end='') print(json.dumps({'stage': 'complete', 'cpu_seconds': time.process_time() - T0}), file=sys.stderr) return 0 if __name__ == '__main__': raise SystemExit(main())