"""c93-validate.py -- does the corrected search find solutions it should, and does its tree depend on the window it is searching? Two controls, because a search that never says "solved" is worthless as a negative: POSITIVE CONTROL. Perturb the recorded state by one move (prime 2: residue 0 -> 1) and target a window that the RECORDED state covers outright, [227, 2254) (the recorded best run 2027). The perturbation removes coverage only where prime 2 was the sole coverer, so a solution exists and it is exactly the undo move (k=0, v=0). A correct DFS must find it, at depth 1. TREE-DEPENDENCE CONTROL. K = 3 on the 1-hole window [227, 2028) and on the 9-hole bar window [17, 2489). The bar window's root has nine uncovered offsets instead of one, so its tree must be at least as large; identical node counts would mean the search is not actually branching on the window it was given. """ import importlib.util import json import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) def load(name, fn): spec = importlib.util.spec_from_file_location(name, os.path.join(HERE, fn)) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod def main(): M = load("repair90c", "repair90c.py") res = json.load(open(os.path.join(HERE, "state-n25.json"), encoding="utf-8"))["residues"] out = {} # --- control 0: a window the recorded state covers outright cov0 = M.Cov(res, 227, 2027) r0 = M.solve_dfs(cov0, K=1, node_cap=1000, secs=10) out["covered_window_R2027"] = {"holes": cov0.holes0, "solved": r0["solved"], "moves": r0["moves"], "nodes": r0["nodes"]} # --- control 1: perturb one prime, recover it pert = list(res) pert[0] = 1 # prime 2: 0 -> 1 cov1 = M.Cov(pert, 227, 2027) r1 = M.solve_dfs(cov1, K=1, node_cap=200000, secs=60) out["perturbed_p2_needs_undo"] = { "holes": cov1.holes0, "solved": r1["solved"], "moves": r1["moves"], "expected_move": [[0, 0]], "ok": r1["solved"] and sorted(r1["moves"]) == [[0, 0]], "nodes": r1["nodes"]} # --- control 1b: same perturbation, K = 0 can never succeed (negative control) r1b = M.solve_dfs(cov1, K=0, node_cap=200000, secs=60) out["perturbed_K0"] = {"solved": r1b["solved"], "exhausted": r1b["exhausted"]} # --- control 2: tree size must depend on the window trees = {} for (start, R, K) in [(227, 2028, 3), (17, 2489, 3)]: cov = M.Cov(res, start, R) r = M.solve_dfs(cov, K=K, node_cap=60000000, secs=300) trees["start%d_R%d" % (start, R)] = {"holes": cov.holes0, "solved": r["solved"], "exhausted": r["exhausted"], "nodes": r["nodes"], "secs": r["secs"]} out["tree_size"] = trees print(json.dumps(out, indent=1)) with open(os.path.join(HERE, "c93-validate.json"), "w", encoding="utf-8", newline="\n") as fh: fh.write(json.dumps(out, indent=1) + "\n") return 0 if __name__ == "__main__": sys.exit(main())