#!/usr/bin/env python3 """Route 4, job 959: CNF (built with #357's own encoder, Sinz AMO + ALO) for the prefix n of support a, solved by CaDiCaL (python-sat) with a DRUP proof. Writes sat959--.cnf and, on UNSAT, sat959--.drup; prints status. python sat959.py 9409 48 """ import importlib.util, os, sys HERE = os.path.dirname(os.path.abspath(__file__)) def load(name, fn): s = importlib.util.spec_from_file_location(name, os.path.join(HERE, fn)); m = importlib.util.module_from_spec(s); s.loader.exec_module(m); return m b357 = load('b357', 'r357-build-exact-cover758.py') rw = load('rw', 'r370-route4-weighted.py') from pysat.formula import CNF from pysat.solvers import Solver a, n = int(sys.argv[1]), int(sys.argv[2]) D = rw.slots_from(a, n, rw.old_primes(97)) text, dom = b357.encode(D, b357.Q) base = f'sat959-{a}-{n}' open(base + '.cnf', 'w').write(text) f = CNF(from_string=text) with Solver(name='cadical195', bootstrap_with=f.clauses, with_proof=True) as s: r = s.solve() if r: m = set(x for x in s.get_model() if x > 0) ph = {q: [b for b, v in enumerate(dom[str(q)]) if v in m] for q in b357.Q} print(f'a={a} n={n} L={D[-1]-a+1}: SAT phases', ph) else: pr = s.get_proof() open(base + '.drup', 'w').write('\n'.join(pr) + '\n') print(f'a={a} n={n} L={D[-1]-a+1}: UNSAT, proof lines {len(pr)}; vars/clauses {text.splitlines()[0]}')