#!/usr/bin/env python3 """Route 132, instrument F: is there a valid inequality that cuts the fractional point x_{p,r} = 1/p? The LP relaxation of the covering model is feasible at every R because of that one point (return #1433), so LP-based reasoning could only be reopened by a family of inequalities that is valid for the model's integer points and VIOLATED at x_{p,r} = 1/p. This script answers the question in three independent ways. C1 (theorem, exact). Let c = sum_i lambda_i * a^(i) + sum_q mu_q * e^(q) be any real combination of the cover rows (lambda >= 0) and the exactly-one rows (mu of any sign), with B = sum_i lambda_i + sum_q mu_q its right-hand side. For prime q >= 3 each position is covered by exactly two residues, so summing over residues gives 2*sum_i lambda_i / q; for q = 2 it gives 1/2 * sum_i lambda_i; the exactly-one rows contribute mu_q exactly. Hence c . xf - B = (S(n) - 1) * sum_i lambda_i >= 0, so NO linear combination of the model's own rows separates xf -- not even one using the equality rows with negative multipliers. Any separating inequality must therefore use integrality, i.e. be a rounding (Chvatal-Gomory) cut. Verified exactly with fractions over many random combinations. C2 (search). Exhaustive enumeration of the natural rank-1 CG roundings of cover-row subsets: I a set of up to 4 positions; lambda_i = 1/d uniformly, d in {1,2,3,4}; optional mu_q in {-1,0,1} for q in the primes of a small tail set; cut: sum_j ceil(c_j) x_j >= ceil(B) (valid for x >= 0 integral); separating iff sum_j ceil(c_j)/p_j < ceil(B). Reported over a documented, finite space. C3 (state of the art). The root LP of the known-UNSAT instance, i.e. what HiGHS's own presolve and cut generation produce before any branching, and then how deep a random cube has to be fixed before the LP first becomes infeasible. If the root LP after cuts is still feasible, cutting planes as implemented do not refute this instance either. Usage: cut-search.py --n 9 --R 204 [--json OUT] """ import argparse import itertools import json import random import sys import time from fractions import Fraction as F import numpy as np import highspy as hp from ilp132 import A, encode, primes def cover_rows(n, R): """The cover rows as sets of column indices, plus the exactly-one row of each prime.""" ps, index, col, rows, stats = encode(n, R, "none", None) cover = [] for i in range(R): cover.append(sorted({index[p, (1 - i) % p] for p in ps} | {index[p, (-1 - i) % p] for p in ps})) one = [[index[p, r] for r in range(p)] for p in ps] return ps, index, cover, one def combo(covers, ones, lam, mu, prime_of): """Exact coefficient vector, B, and the value at xf for one combination.""" c = {} for i, li in lam.items(): for j in covers[i]: c[j] = c.get(j, F(0)) + F(li) for q, mq in mu.items(): for j in ones[q]: c[j] = c.get(j, F(0)) + F(mq) B = F(sum(lam.values())) + F(sum(mu.values())) val = sum(v / prime_of[j] for j, v in c.items()) return c, B, val def c1_theorem(n, R, trials=300, seed=0): ps, index, cover, one = cover_rows(n, R) prime_of = {} for p in ps: for r in range(p): prime_of[index[p, r]] = p S = sum((F(2, p) if p > 2 else F(1, 2)) for p in ps) rnd = random.Random(seed) worst, bad, checked = None, 0, 0 for _ in range(trials): k = rnd.randint(1, 4) I = rnd.sample(range(R), min(k, R)) lam = {i: F(rnd.choice([1, 2, 3]), rnd.choice([1, 2, 3])) for i in I} mu = {q: rnd.randint(-1, 1) for q in range(len(ps)) if rnd.random() < 0.5} c, B, val = combo(cover, one, lam, mu, prime_of) slack = val - B want = (S - 1) * sum(lam.values()) checked += 1 if slack != want: bad += 1 if slack < 0: bad += 1 worst = slack if worst is None else min(worst, slack) return {"claim": "c.xf - B == (S(n) - 1) * sum(lambda) >= 0 for every combination", "combinations_checked": checked, "counterexamples": bad, "min_slack_exact": str(worst), "S_n": str(S), "S_n_float": round(float(S), 6), "relative_slack_at_least": str(S - 1), "separating_inequality_found": bool(bad > 0 and worst is not None and worst < 0)} def cg_cut(c, B): """The rank-1 Chvatal-Gomory cut of the valid inequality sum_j c_j x_j >= B over x in [0,1]^n. Substituting x_j = 1 - s_j for the negative coefficients, rounding every (now nonnegative) coefficient up and the right side up (the left side is integral at integral points), then substituting back gives: coefficient ceil(c_j) if c_j >= 0, floor(c_j) if c_j < 0 right side ceil(B + sum_{c_j<0} |c_j|) - sum_{c_j<0} ceil(|c_j|) The naive "ceil everything, ceil the right side" is NOT valid with negative coefficients, so this function is used everywhere a cut is tested. """ def ce(f): return -((-f.numerator) // f.denominator) def fl(f): return f.numerator // f.denominator r = {j: (ce(v) if v >= 0 else fl(v)) for j, v in c.items()} neg = [v for v in c.values() if v < 0] R = ce(B + sum(-v for v in neg)) - sum(ce(-v) for v in neg) return r, R def c2b_cut_validity_selftest(n=4, R=None, trials=400, seed=7): """Brute force: does the derived cut hold at every integral feasible point of a small instance? n = 4 has 2*3*5*7 = 210 one-residue-per-prime assignments, so the integer feasible set of the model is enumerable and every derived cut can be checked against all of it. """ if R is None: R = A[n] ps, index, cover, one = cover_rows(n, R) prime_of = {} for p in ps: for r in range(p): prime_of[index[p, r]] = p feas = [] for combo_res in itertools.product(*[range(p) for p in ps]): x = np.zeros(sum(ps)) for p, r in zip(ps, combo_res): x[index[p, r]] = 1.0 if all(any(x[j] > 0.5 for j in cov) for cov in cover): feas.append(x) rnd = random.Random(seed) checked, invalid, min_slack = 0, 0, None for _ in range(trials): k = rnd.randint(1, 4) I = rnd.sample(range(R), min(k, R)) d = rnd.choice([1, 2, 3, 4]) lam = {i: F(1, d) for i in I} mu = {q: rnd.choice([-1, 0, 1]) for q in range(len(ps)) if rnd.random() < 0.4} c, B, val = combo(cover, one, lam, mu, prime_of) r, Rc = cg_cut(c, B) for x in feas: lhs = sum(float(r.get(j, 0)) * x[j] for j in range(len(x))) if lhs < Rc: invalid += 1 break checked += 1 return {"n": n, "R": R, "integer_feasible_points": len(feas), "cuts_check": checked, "cuts_invalid_on_an_integer_point": invalid, "formula_valid": invalid == 0, "note": "validation of cg_cut() itself, not a search for separating cuts"} def c1b_integer_multipliers(n, R, trials=300, seed=1): """C1 continued, the only place a cut could still gain: rounding. Take integer multipliers m >= 0 on the cover rows and integers mu on the exactly-one rows such that every coefficient c_j >= 0. Then the coefficients are integral, the left side is integral at integral points, and the rank-1 Chvatal-Gomory cut is sum_j c_j x_j >= ceil(B), B = sum m + sum mu, whose value at xf is exactly (S(n) - 1) * sum(m) + B by C1. So the cut separates xf only if (S(n) - 1) * sum(m) < ceil(B) - B < 1. If sum(m) >= 1 this needs S(n) - 1 < 1, i.e. S(n) < 2, which fails for every n >= 5 (S(9) = 2.498); and if sum(m) = 0 the cut is a pure combination of the exactly-one rows, whose value at xf is exactly B, so it is not violated either. Hence NO rank-1 CG cut with integer multipliers separates xf at any n >= 5 -- proved, and the random sample below checks the arithmetic. """ ps, index, cover, one = cover_rows(n, R) prime_of = {} for p in ps: for r in range(p): prime_of[index[p, r]] = p S = sum((F(2, p) if p > 2 else F(1, 2)) for p in ps) rnd = random.Random(seed) checked, skipped, min_slack, worst = 0, 0, None, None for _ in range(trials): k = rnd.randint(1, 4) I = rnd.sample(range(R), min(k, R)) m = {i: rnd.randint(1, 3) for i in I} mu = {q: rnd.randint(-2, 2) for q in range(len(ps)) if rnd.random() < 0.5} c, B, val = combo(cover, one, m, mu, prime_of) if any(v < 0 for v in c.values()): # rounding direction with negative coefficients is a skipped += 1 # separate case; the search handles those numerically continue assert all(v.denominator == 1 for v in c.values()) ceilB = -((-B.numerator) // B.denominator) slack = val - ceilB checked += 1 min_slack = slack if min_slack is None else min(min_slack, slack) worst = B if worst is None else min(worst, B) return {"claim": ("with integer multipliers, separation of xf needs (S(n)-1)*sum(m) < ceil(B)-B < 1, " "impossible once S(n) >= 2 (all n >= 5); sum(m) = 0 is never violated"), "S_n": str(S), "S_n_minus_2": str(S - 2), "n_ge_5_theorem_holds": S > 2, "combinations_checked": checked, "skipped_negative_coefficients": skipped, "min_slack_exact": str(min_slack), "min_slack_float": round(float(min_slack), 6), "separating_cut_found": bool(min_slack is not None and min_slack < 0)} def c2_cg_search(n, R, max_set=4, window=12, ds=(1, 2, 3, 4), mu_choices=(-1, 0, 1), mu_primes=2, limit=400000): ps, index, cover, one = cover_rows(n, R) prime_of = {} for p in ps: for r in range(p): prime_of[index[p, r]] = p positions = list(range(min(window, R))) tested, sep, examples = 0, 0, [] min_slack, min_at = None, None t0 = time.time() for size in range(1, max_set + 1): for I in itertools.combinations(positions, size): for d in ds: for mupat in itertools.product(mu_choices, repeat=min(mu_primes, len(ps))): if tested >= limit: break lam = {i: F(1, d) for i in I} mu = {q: mupat[q] for q in range(min(mu_primes, len(ps))) if mupat[q] != 0} c, B, val = combo(cover, one, lam, mu, prime_of) assert val - B >= 0, "C1 theorem violated" # every cut must be satisfied at xf coeff, ceilB = cg_cut(c, B) rounded = sum(F(v, prime_of[j]) for j, v in coeff.items() if v != 0) tested += 1 slack = rounded - ceilB if min_slack is None or slack < min_slack: min_slack, min_at = slack, {"positions": list(I), "d": d, "mu": {str(k): v for k, v in mu.items()}} if rounded < ceilB: sep += 1 if len(examples) < 3: examples.append({"positions": list(I), "d": d, "mu": {str(k): v for k, v in mu.items()}, "value": str(rounded), "rhs": str(ceilB)}) return {"space": ("|I| <= %d drawn from the first %d positions, uniform lambda = 1/d with d in %s, " "mu in %s on the smallest %d primes" % (max_set, window, list(ds), list(mu_choices), mu_primes)), "cuts_tested": tested, "separating_cuts": sep, "examples": examples, "closest_approach": {"slack_exact": str(min_slack), "slack_float": round(float(min_slack), 6), "at": min_at, "note": "a separating cut needs slack < 0; this is the minimum of " "value - ceil(B) over the whole space"}, "sec": round(time.time() - t0, 2), "found_separating_cut": bool(sep > 0)} def c3_root_lp_and_depth(n, R, depths=None, samples=100, seed=0): """Does HiGHS refute the instance without branching? Then how deep must a cube be fixed?""" ps, index, col, rows, stats = encode(n, R, "none", None) lb, ub, cost, integ, cols = col rlb, rub, starts, idxs, vals = rows if depths is None: depths = sorted({max(1, n - k) for k in range(1, 8)}) def build(max_nodes): h = hp.Highs() h.setOptionValue("output_flag", False) h.setOptionValue("mip_rel_gap", 0.0) h.setOptionValue("random_seed", 0) h.setOptionValue("threads", 1) h.setOptionValue("mip_max_nodes", max_nodes) h.addVars(len(lb), np.asarray(lb), np.asarray(ub)) h.changeColsCost(len(cols), cols, np.asarray(cost)) h.changeColsIntegrality(len(cols), cols, np.asarray(integ)) 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 h # (a) root only: no branching permitted. kInfeasible here would mean presolve + cut generation # alone refute the instance; anything else means the root relaxation stayed feasible. h0 = build(0) t0 = time.time() h0.run() n0 = getattr(h0.getInfo(), "mip_node_count", None) st0 = str(h0.getModelStatus()).split(".")[-1] root = {"max_nodes": 0, "status": st0, "nodes": n0, "sec": round(time.time() - t0, 3), "root_lp_refutes_instance": st0 == "kInfeasible", "option": "mip_max_nodes = 0, presolve and cut generation at their defaults (on)"} # (b) one node: if the root LP were infeasible, a single node suffices to report kInfeasible h1 = build(1) t1 = time.time() h1.run() root["one_node"] = {"status": str(h1.getModelStatus()).split(".")[-1], "nodes": getattr(h1.getInfo(), "mip_node_count", None), "sec": round(time.time() - t1, 3)} # (c) how deep must a random cube be fixed before the LP first becomes infeasible hlp = build(0) hlp.changeColsIntegrality(len(cols), cols, np.zeros(len(cols), dtype=np.uint8)) # continuous hlp.setOptionValue("mip_max_nodes", 1 << 30) rnd = random.Random(seed) curve = [] for d in depths: dd = min(d, len(ps)) inf = 0 for _ in range(samples): primes_fixed = rnd.sample(list(ps), dd) lo, hi = np.array(lb), np.array(ub) for p in primes_fixed: r = rnd.randrange(p) lo[index[p, r]] = hi[index[p, r]] = 1.0 hlp.changeColsBounds(len(cols), cols, lo, hi) hlp.run() inf += (str(hlp.getModelStatus()).split(".")[-1] == "kInfeasible") curve.append({"depth": dd, "samples": samples, "lp_infeasible": inf, "fraction": round(inf / samples, 4)}) print("depth=%d infeasible %d/%d" % (dd, inf, samples), file=sys.stderr, flush=True) return {"root_after_cuts": root, "depth_curve": curve, "design": ("per sample: a uniformly random set of `depth` primes, and for each a uniformly " "random residue, are fixed to 1; the remaining variables are continuous"), "note": ("depth is the number of primes whose residue is fixed; at depth = n the cube is a " "full assignment, for which the LP is infeasible by definition")} def main(): ap = argparse.ArgumentParser() ap.add_argument("--n", type=int, default=9) ap.add_argument("--R", type=int, default=None) ap.add_argument("--json", default=None) ap.add_argument("--quick", action="store_true") a = ap.parse_args() R = a.R if a.R is not None else A[a.n] + 1 rep = {"tool": "cut-search.py", "n": a.n, "R": R, "known": "R = a(n)+1 is UNSAT", "fractional_point": "x_{p,r} = 1/p"} rep["C1_no_combination_separates"] = c1_theorem(a.n, R, trials=60 if a.quick else 300) rep["C1b_integer_multiplier_cg"] = c1b_integer_multipliers(a.n, R, trials=60 if a.quick else 300) rep["C2_cg_roundings"] = c2_cg_search(a.n, R, mu_primes=3 if not a.quick else 2, limit=200000) if not a.quick: rep["C2b_cut_formula_selftest"] = c2b_cut_validity_selftest() rep["C3_root_lp_and_depth"] = c3_root_lp_and_depth( a.n, R, samples=30 if a.quick else 100) txt = json.dumps(rep, indent=1, sort_keys=True, ensure_ascii=False) if a.json: with open(a.json, "w", encoding="utf-8", newline="\n") as fh: fh.write(txt + "\n") print(txt) if __name__ == "__main__": main()