#!/usr/bin/env python3 """Job 2847 triage probe for route 144: deterministic cube-and-conquer with pure-LP closure. Model = ilp132.encode (served, sha256 e87e8bbb...) with integrality dropped (pure LP). A cube fixes the residues of a prefix of an ORDER of primes (column bounds). DFS in a fixed lexicographic order: solve the cube LP; infeasible -> close cube + subtree; else deepen. At full depth the leaf is checked combinatorially (LP with all fixed = exact check). Modes: sample --order large|small --depth d --k K : K uniformly random cubes at that depth, count LP-infeasible dfs --order large|small --cap S : full deterministic DFS, counts per depth, verdict Output: one JSON line on stdout. """ import argparse, json, random, sys, time import numpy as np import highspy as hp from ilp132 import encode, A def build(n, R, seed): ps, index, col, rows, _ = encode(n, R, "none") lb, ub, cost, integ, cols = col rlb, rub, starts, idxs, vals = rows h = hp.Highs() h.setOptionValue("output_flag", False) h.setOptionValue("random_seed", int(seed)) h.setOptionValue("threads", 1) h.setOptionValue("presolve", "off") h.addVars(len(lb), np.asarray(lb), np.asarray(ub)) h.addRows(len(rlb), np.asarray(rlb), np.asarray(rub), len(idxs), np.asarray(starts, dtype=np.int32), np.asarray(idxs, dtype=np.int32), np.asarray(vals)) return ps, index, h def lp_infeasible(h, ps, index, fixed): """fixed: dict p -> residue. Returns True if the cube LP is infeasible.""" cidx, lo, hi = [], [], [] for p in ps: for r in range(p): cidx.append(index[p, r]) if p in fixed: v = 1.0 if r == fixed[p] else 0.0 lo.append(v); hi.append(v) else: lo.append(0.0); hi.append(1.0) h.changeColsBounds(len(cidx), np.asarray(cidx, dtype=np.int32), np.asarray(lo), np.asarray(hi)) h.run() st = str(h.getModelStatus()).split(".")[-1] return st in ("kInfeasible", "kUnboundedOrInfeasible") def main(): ap = argparse.ArgumentParser() ap.add_argument("mode"); ap.add_argument("--n", type=int, required=True) ap.add_argument("--R", type=int); ap.add_argument("--order", default="small") ap.add_argument("--depth", type=int, default=1); ap.add_argument("--k", type=int, default=100) ap.add_argument("--cap", type=float, default=600); ap.add_argument("--seed", type=int, default=0) a = ap.parse_args() R = a.R or A[a.n] + 1 ps, index, h = build(a.n, R, a.seed) order = sorted(ps, reverse=(a.order == "large")) S_free = lambda free: sum((0.5 if q == 2 else 2.0 / q) for q in free) out = dict(mode=a.mode, n=a.n, R=R, order=a.order, seed=a.seed, solver="HiGHS " + h.version()) t0 = time.time() if a.mode == "sample": rng = random.Random(12345) pre = order[:a.depth] inf = 0 for _ in range(a.k): fixed = {p: rng.randrange(p) for p in pre} inf += lp_infeasible(h, ps, index, fixed) out.update(depth=a.depth, fixed_primes=pre, k=a.k, lp_infeasible=inf, S_free=round(S_free(order[a.depth:]), 6)) else: created = [0] * (len(order) + 1); closed = [0] * (len(order) + 1) sat = None; timed_out = False stack = [{}] while stack: if time.time() - t0 > a.cap: timed_out = True; break fixed = stack.pop() d = len(fixed) created[d] += 1 if lp_infeasible(h, ps, index, fixed): closed[d] += 1; continue if d == len(order): sat = {str(p): fixed[p] for p in ps}; break p = order[d] for r in reversed(range(p)): # pop gives lexicographic order g = dict(fixed); g[p] = r; stack.append(g) lps = sum(created) out.update(verdict=("timeout" if timed_out else ("SAT" if sat else "UNSAT")), sat=sat, lp_solves=lps, created=created, closed=closed, S_free_by_depth=[round(S_free(order[d:]), 4) for d in range(len(order) + 1)]) dt = time.time() - t0 out.update(sec=round(dt, 3)) print(json.dumps(out), flush=True) if __name__ == "__main__": main()