moonbit-sat

    Cross-backend CDCL SAT solver with DRAT-checkable UNSAT proofs, incremental assumptions and weighted MaxSAT optimisation.

    sat
    cdcl
    maxsat
    drat
    solver
    reasoning
    Download zip
    Version
    0.7.6
    License
    Apache-2.0
    Last updated
    15 minutes ago
    Downloads
    96

    #moonbit-sat

    纯 MoonBit 实现的 CDCL SAT 求解器 + 可独立校验的 UNSAT 证明 + 加权 MaxSAT 优化, 四个后端(wasm / wasm-gc / js / native)行为一致。

    moonbit-sat 面向的是「判定—证明—优化」这条完整链路,而不是一份孤立的求解实现:

    能力说明
    CDCL 求解两文字监听、1-UIP 学习子句、VSIDS 活动度、Luby 序列重启、子句库归约、相位保存
    增量求解solve(assumptions) 可反复调用,带 assumption 的 UNSAT 不污染后续求解状态
    UNSAT coresolve_core(assumptions) 在 UNSAT 时返回一个本身不可满足的假设子集,可用来解释冲突,也给 MaxSAT 提供下界
    冲突预算solve_with_budget 在给定冲突数后返回 Unknown,回退到 0 层,可继续求解
    UNSAT 证明每个学习子句与最终空子句写入 DRAT 风格日志,可交给第三方检查器复算
    独立检查器项目自带 check_drat / verify_proof(RUP)与 check_drat_rat / verify_proof_rat(RUP + RAT),不信任求解器
    加权 MaxSATWCNF 解析 + 松弛变量 + Sinz 顺序计数编码 + 二分求最优成本
    MaxSAT 最优性下界侧 maxsat_bound_proof 导出「代价 k 不可达」的 DRAT 证明;上界侧 maxsat_solution 给出代价恰为 opt 的赋值,maxsat_model_cost 按 WCNF 原文复算;maxsat-verify 两端一起验
    预处理Formula::simplify 去掉子句内重复文字、删除重言子句,并统计被删条数
    四后端求解与校验不手写 FFI、不依赖外部求解器,preferred_target = "wasm" 下与 native 同结果;命令行的 @path 读盘用官方 moonbitlang/x/fs

    全部证据(判定 / 证明 / 校验 / core / 加权 / 最优性两端 / 压力)的复现步骤与预期输出见 docs/reproduce.md。

    #安装

    moon add 2227057182/moonbit-sat

    或从源码构建:

    git clone https://github.com/2227057182/moonbit-sat.git cd moonbit-sat moon check --deny-warn && moon test

    #最小可运行工程

    新建目录,按这个顺序做(先 moon add 再写 import,可以避开索引未更新时的解析报错):

    mkdir sat-demo && cd sat-demo printf 'name = "tmp/sat-demo"\nversion = "0.1.0"\n' > moon.mod moon update moon add 2227057182/moonbit-sat

    moon.pkg:

    import {
    "2227057182/moonbit-sat" @moonbit_sat
    }
    pkgtype(kind: "executable")

    main.mbt(maxsat_model 不抛异常,普通 fn main 直接可用):

    fn main {
    // (x1 ∨ x2) ∧ ¬x1 ∧ ¬x2:两条软子句必有一条被违约,最优成本是 1
    let w = @moonbit_sat.parse_wcnf("p wcnf 2 3 10\n10 1 2 0\n1 -1 0\n1 -2 0\n")
    match @moonbit_sat.maxsat_model(w, 512) {
    Some((model, cost)) => {
    println("cost=\{cost}") // cost=1
    println("verified=\{@moonbit_sat.verify_maxsat_solution(w, model, cost)}") // verified=true
    }
    None => println("hard clauses unsatisfiable")
    }
    }

    moon run . # cost=1 / verified=true

    moon update 靠 git 拉索引,报 program not found: git 时先装 git 或把 git 加进 PATH。

    #快速开始

    // (a ∨ b) ∧ ¬a ⇒ a=false, b=true
    let f = @moonbit_sat.parse_dimacs("p cnf 2 2\n1 2 0\n-1 0\n")
    let s = @moonbit_sat.Solver::new(f)
    let proof = s.enable_proof()
    if s.solve([]) {
    println(s.model()) // [false, true]
    } else {
    // 证明:学习子句 + 空子句,DRAT 文本
    println(proof.text())
    }
    println(s.stats_string()) // decisions=… propagations=… conflicts=… learnts=…

    #增量求解与假设

    let f = @moonbit_sat.parse_dimacs("p cnf 2 1\n1 2 0\n")
    let s = @moonbit_sat.Solver::new(f)
    assert_true(s.solve([]))
    assert_false(s.solve([@moonbit_sat.lit_new(0, true), @moonbit_sat.lit_new(1, true)]))
    assert_true(s.solve([@moonbit_sat.lit_new(0, true)])) // 上一次 UNSAT 不影响这一次

    #独立校验证明

    let f = @moonbit_sat.parse_dimacs(cnf_text)
    let s = @moonbit_sat.Solver::new(f)
    let p = s.enable_proof()
    assert_false(s.solve([]))
    assert_true(@moonbit_sat.verify_proof(f, p.text()))

    verify_proof 不接触求解器状态:它按 ASCII DRAT 文本重放,每条新增子句都要在「原公式 + 已验证子句」上通过 RUP 复算,最后必须出现空子句;二进制 DRAT 要先转文本(cadical --binary=false)。

    verify_proof_rat 用完整规则:RUP 不成立时再试 RAT——取候选子句第一个文字为 pivot,池中每条含其否定的子句与候选子句求归结,归结式仍须是 RUP,池中没有含否定 pivot 的子句时直接成立。这条路径用于校验外部工具产出的证明;本项目求解器本身只产 RUP。

    #加权 MaxSAT

    p wcnf 2 3 10 10 1 2 0 # 硬子句:a ∨ b 1 -1 0 # 软子句:¬a,权 1 1 -2 0 # 软子句:¬b,权 1

    let w = @moonbit_sat.parse_wcnf(wcnf_text)
    let opt = @moonbit_sat.maxsat_solve(w, 512) // 总软权重上限 512
    println(opt) // 1

    总软权重超过 512 时 maxsat_solve 会拒绝;maxsat_oll 没有这个上限:它按 unsat core 驱动下界,再用每个模型违反的软子句收紧上界,两界相接才收尾。

    let opt = @moonbit_sat.maxsat_oll(w) // 无总权重上限
    let best = @moonbit_sat.maxsat_oll_solution(w) // (赋值, 代价)?
    let bounded = @moonbit_sat.maxsat_oll_result(w, 50) // 带轮预算,不收敛时带回界

    maxsat_oll_result 在预算内收敛返回 Solved,硬子句不可满足返回 Infeasible,预算用尽返回 Budgeted(下界, 上界)——rounds <= 0 表示不限。20×20 加权网格(总软权重 40000)给 20 轮,不到 10 ms 就返回 lower= 2000 upper= 40000,不再无限跑下去。

    #CLI

    moon run cmd/main -- solve "p cnf 3 2;1 2 0;-1 0" # SAT + 模型 + 统计 moon run cmd/main -- proof "p cnf 6 9;1 2 0;..." # UNSAT + DRAT 证明 moon run cmd/main -- verify "p cnf 2 3;1 0;2 0;-1 -2 0" "-1 0;0" # 独立校验(RUP) moon run cmd/main -- verify-rat "p cnf 2 3;1 0;2 0;-1 -2 0" "-1 0;0" # 同一证明,RUP + RAT 规则 moon run cmd/main -- maxsat "p wcnf 2 3 10;10 1 2 0;1 -1 0;1 -2 0" moon run cmd/main -- maxsat-cnf "p wcnf 2 3 10;10 1 2 0;1 -1 0;1 -2 0" 0 # 打印「代价 ≤0」编码后的 CNF,交给外部检查器 moon run cmd/main -- verify-maxsat "p wcnf 2 3 10;10 1 2 0;1 -1 0;1 -2 0" 0 "$(cat proof)" # 重建编码后校验 moon run cmd/main -- maxsat-verify "p wcnf 2 3 10;10 1 2 0;1 -1 0;1 -2 0" # 上界赋值 + 下界证明一起验 moon run cmd/main -- maxsat-solution "p wcnf 2 3 10;10 1 2 0;1 -1 0;1 -2 0" # 最优赋值 + 复算代价 moon run cmd/main -- maxsat-oll "p wcnf 2 3 10;10 1 2 0;1 -1 0;1 -2 0" # 核心引导,总软权重无上限 moon run cmd/main -- maxsat-oll-budget "p wcnf 2 3 10;10 1 2 0;1 -1 0;1 -2 0" 50 # 同上,加轮预算:不收敛时打印上下界 moon run cmd/main -- verify-solution "p wcnf 2 3 10;10 1 2 0;1 -1 0;1 -2 0" 1 "v 1 -2 0" # 只核对导出的赋值 moon run cmd/main -- proof @examples/pigeonhole-3-2.cnf > p32.drat # 从文件读公式,证明写进文件 moon run cmd/main -- verify @examples/pigeonhole-3-2.cnf @p32.drat # 再从文件验回来,24 MB 的证明只能这样传

    参数里的 ; 会被当作换行,公式可以直接内联传参;也可以用 @路径 从文件读(0.7.6 起),24 MB 的证明只有这条路径能进。

    #生态里为什么还需要它

    MoonBit 生态已有两个 SAT 相关包,能力边界与本项目并不重叠:

    AdUhTkJm/sat-solveryf666888/moonsatkitmoonbit-sat
    核心算法CDCLDPLLCDCL(两监听 + 1-UIP + VSIDS + 重启 + 归约)
    后端仅 native四后端四后端
    UNSAT 证明无无DRAT 风格日志 + 自带独立检查器(RUP 与 RUP+RAT 两种模式)
    加权优化无无加权 partial MaxSAT(Sinz 编码 + 二分;核心引导无权重上限)
    增量假设不明确有(solve_with_assumptions)有,且 assumption 冲突不污染状态
    UNSAT core无无有(solve_core,返回的 core 可单独回代复验)

    clbbbb/lrat-check 只有检查器、没有求解器;本项目两者同仓、可相互印证。

    社区里做「判定 + 可验证证明 + 加权优化」的完整工具链此前是空白,这正是本项目的立足点,而不是「零依赖」或「统一 API」这类可替代的包装理由。

    #正确性证据

    moon test 共 82 个测试,其中 14 类是硬证据:

    1. 与暴力枚举对拍:80 轮随机 3–5 变量公式,CDCL 的 SAT/UNSAT 结论与真值表枚举逐一比对,SAT 时还验证模型确实满足每条子句。
    2. 证明自校验:对随机 UNSAT 实例生成 DRAT 证明,再用 verify_proof 逐条 RUP 复算;同时有反例测试,确认非 RUP 步骤与缺失空子句都会被拒绝。
    3. MaxSAT 与暴力最优值对拍:40 轮随机 WCNF,二分求得的最优成本与枚举所有赋值的最小成本一致。
    4. 边界与退化输入:空公式、空子句、重复文字、重言子句、变量越界、证明删除行、连续假设调用、MaxSAT 硬冲突与无软子句实例,各有独立测试;simplify 与原公式的结论还在 30 轮随机公式上逐一对拍。
    5. 重启与预算:Luby 序列前 16 项逐项固定,防止差一错误;0 预算在必然产生冲突的实例上返回 Unknown,随后同一求解器继续求解仍得到正确结论,确认中断后的状态可复用。
    6. 最小化不削弱子句:递归最小化删掉的字面必须让子句仍满足 RUP,5 鸽 4 洞实例的证明经独立检查器判定 VERIFIED;另有测试确认 minimised > 0,避免最小化静默失效。
    7. RAT 分支有正反两面:在 (x1∨x2)∧(¬x1∨x2) 上加 (x1),strict 必须拒绝、full 必须接受;在 (¬x1∨x2)∧(¬x1∨x3) 上加 (x1),两种模式都必须拒绝,确认 RAT 不是「一律放行」。
    8. MaxSAT 下界证明可复算:不可达下界能出证且校验通过、可达下界不出证、删掉空子句后被拒、同一证明挪到另一个 k 被拒、硬子句本身不可满足时证明仍可校验;另有 4 个真实实例在 native 上跑 maxsat-verify 全部 OPTIMALITY-VERIFIED。
    9. MaxSAT 上界可达:最优赋值确实付出所声称的代价、声称代价偏大或偏小都被拒、破坏硬子句的赋值被拒、零代价实例仍给出可校验赋值、硬子句本身不可满足时返回 None;并在顶点覆盖实例上确认「上界 + 下界」两端同时成立才判最优。
    10. 证明文本容错:注释行(c / s / o 开头)被跳过而不是当成子句,把命令行打印的 s 与 c … 统计原样回喂给 verify 仍得到 s VERIFIED;只含注释的文本得到 s PROOF-REJECTED,不是崩溃。0.6.4 之前这里会 abort,三个测试守着。
    11. 外部检查器交叉验证:鸽巢 3–9 洞与三个加权实例的最优性下界共 10 个案例,交给 drat-trim 与 lrat-check(与本项目无共享代码的两个 C 检查器)复算,全部 s VERIFIED / c VERIFIED,且全部是 0 RAT 引理的纯 DRUP 证明。BIG=1 bash tools/crosscheck.sh 再追加鸽巢 10/9(295345 行,drat-trim 约 17s)与 20×20 网格下界(8622 行),12 个案例同样全绿。见 docs/crosscheck.md。
    12. 核心引导不受总软权重限制:加权 Petersen(每条 100,总 1000)在 maxsat 上直接抛出上限错误,maxsat-oll 给出 o 600,同一实例把权重降到 1 走编码路径也得 6;另有「同一条软子句被两个 core 命中不重复收费」「单个昂贵 core 计费到 1001」「硬子句不可满足返回 None」等结构化用例,以及 4×5 网格(总 2000)→ o 1000。
    13. 核心引导有预算出口,且不只对图形态有效:20×20 加权网格给 20 轮预算,不到 10 ms 就返回 lower= 2000 upper= 40000(不设预算会一直跑),预算超过自然长度时与无预算结果一致、rounds <= 0 表示不限;另有一个三条三元超边的加权超图实例(软子句与图的边无关)与编码路径对拍,o 200 且模型成本按 WCNF 复算一致。
    14. 外部求解器产的证明同样能读:CaDiCaL 3.1.0(源码编译)对鸽巢 6 鸽 5 洞写出的 235 行 DRAT(156 条添加、79 条删除)原样内联进测试,verify_proof 与 verify_proof_rat 都判 VERIFIED,drat-trim 结论一致;去掉末尾空子句后同一份证明被拒绝——验收是有条件的,不是把文件读进来就点头。

    moon check --deny-warn # 0 warnings moon test # 90 passed

    #基准

    moon run cmd/main -- bench

    在固定的随机 3-SAT 阶梯上跑一遍,实例由内置线性同余发生器生成、种子写死,任何人可复现。输出决策、传播、冲突和最小化删掉的字面数:

    变量子句结论决策传播冲突删除字面
    2086SAT135973
    30129UNSAT991102
    40172SAT242091511
    50215SAT9910087644
    60258SAT10814698365

    这是搜索量数据,不是墙钟耗时;也没有与 MiniSat、CaDiCaL 做过对比。本项目不声称性能领先,只声称链路完整且结论可被独立复算。

    #证明校验耗时

    bench-verify <k> 在同一进程里构造 k 鸽 k-1 洞实例、求解、取证明、校验并打印行数——几千行的证明不可能作为命令行参数内联(单个参数 128KB 上限),但可以 verify @cnf @proof 从文件读:0.7.6 在 native 上验过鸽巢 k=10 的 24.7 MB 证明,整条命令 89 s 得到 s VERIFIED。

    moon run cmd/main -- bench-verify 9

    native release 下实测,证明行数在改造前后完全相同:

    k变量证明行数全量扫描两文字监听扁平池(0.6.7)
    7426700.04s0.02s0.02s
    85639420.66s0.16s0.14s
    9724027332.56s6.00s5.30s
    1090295345—435s366s

    检查器原先对每条新增子句都从头扫一遍整个池,行数 ×10 时耗时 ×50。改成两文字监听后,传播只沿被置假文字对应的监听列表走,k=9 提速 5.4 倍,结论仍是 VERIFIED。0.6.7 把子句池摊平成一维数组,端到端 k=9 从 6.00s 降到 5.30s、k=10 从 435s 降到 366s(其中求解约 239s,纯校验部分 196s → 127s)。同一条证明交给 drat-trim 只要约 17 s、lrat-check 约 0.7 s。0.7.4 同机复跑:端到端 277.5 s,其中求解 207.7 s、解析不到 1 s、纯校验约 70 s;上面的 239 s / 127 s 是旧机器记录,两者不能混用,慢的是检查器的传播调度,不是证明本身,见 docs/benchmarks.md 的「规模上限」。

    #范围边界

    • 求解器只输出 RUP 步骤(CDCL 学习子句天然满足),不构造 RAT 步骤;检查器另有 RUP + RAT 模式(verify-rat),用于校验外部工具产出的证明。外部检查器复算这 10 个案例时统计到 0 RAT 引理,与这条边界一致。
    • maxsat_solve 用权重展开 + Sinz 编码,总软权重有上限(由调用方给出,示例 512),超出会明确报错而非静默降级;maxsat_oll 走核心引导,不建基数编码,所以没有这个上限。代价是均匀权重下每轮只推进一层,因此总软权重 ≤ 512 时它也自动改走编码路径(结果一致),超过 512 才真正跑 core 循环。不设轮预算时不收敛的实例会一直跑,maxsat_oll_result 用轮预算换一个有界出口:可能只拿回上下界,而不是最优值。
    • MaxSAT 最优性的上界只是「该赋值代价恰为 opt」,单独看不能排除更低的代价;与 opt-1 不可达的证明合起来才闭合最优性,所以 maxsat-verify 两端都要过。
    • MaxSAT 最优性证明是对扩展后的 CNF(含 select 变量与 Sinz 计数变量)给出的,校验方必须用库内同一个 maxsat_encoding 重建公式。所以准确的说法是「可复算」而不是「不看编码也能独立验」;编码器是公开源码,不存在黑箱。这一点在 docs/proof.md 里单独说明。
    • 最优性证明只覆盖「k 不可达」,不导出「k 可达」的模型。
    • 预处理只做到子句内去重与重言消除(Formula::simplify),不含变量消除与子句自吸收;不含并行组合。这些是后续迭代项。

    #文档与示例

    #开发

    moon check --deny-warn moon test moon run cmd/main -- solve "p cnf 2 1;1 2 0"

    #License

    Apache-2.0

    Lit

    type Lit = Int

    Literal encoding used throughout the solver.

    A literal is stored as 2 * variable + sign, where sign is 0 for a positive literal and 1 for a negated one. The variable keeps a dense 0-based index, which lets the solver use plain integer arrays for all per-variable state.

    Clause

    pub struct Clause {
    lits : Array[Int]
    learnt : Bool
    activity : Double
    lbd : Int
    watch0 : Int
    watch1 : Int
    dead : Bool
    }

    A single clause. lits is a flat literal array; the two watched positions are stored inside the clause so propagation never allocates.

    Clause::add_activity

    fn Clause::add_activity(self : Clause, v : Double) -> Unit

    Clause::mark_dead

    fn Clause::mark_dead(self : Clause) -> Unit

    Clause::move_watch

    fn Clause::move_watch(self : Clause, which : Int, pos : Int) -> Unit

    Move one of the two watched positions. which is 0 or 1.

    Clause::new

    fn Clause::new(lits : Array[Int], learnt : Bool) -> Clause

    Clause::set_lbd

    fn Clause::set_lbd(self : Clause, v : Int) -> Unit

    Clause::set_learnt

    fn Clause::set_learnt(self : Clause, v : Bool) -> Unit

    Clause::size

    fn Clause::size(self : Clause) -> Int

    Clause::watch_at

    fn Clause::watch_at(self : Clause, which : Int) -> Int

    DratStep

    pub struct DratStep {
    is_delete : Bool
    lits : Array[Int]
    }

    One step of a DRAT-style proof log.

    Formula

    pub struct Formula {
    num_vars : Int
    clauses : Array[Clause]
    }

    A CNF formula. Variables are 0-based internally; DIMACS input and output use the usual 1-based numbering.

    Formula::add

    fn Formula::add(self : Formula, lits : Array[Int]) -> Bool

    Append a clause. Returns false when the clause is empty, i.e. the formula is trivially unsatisfiable.

    Formula::new

    fn Formula::new(num_vars : Int) -> Formula

    Formula::num_clauses

    fn Formula::num_clauses(self : Formula) -> Int

    Formula::num_tautologies

    fn Formula::num_tautologies(self : Formula) -> Int

    Number of tautological clauses currently in the formula. Reading this is cheap and lets a caller warn about redundant input without rewriting it.

    Formula::simplify

    fn Formula::simplify(self : Formula) -> Int

    Normalise the formula before handing it to Solver::new: repeated literals inside a clause are collapsed and tautological clauses are removed. The solver caches clause shape in its watch lists, so this must run on the Formula, not on a live solver. Returns the number of clauses dropped.

    OllOutcome

    pub enum OllOutcome {
    Solved(Array[Bool], Int)
    Infeasible
    Budgeted(Int, Int)
    }

    Result of a core-guided run.

    • Solved(model, cost): an optimal model and its cost.
    • Infeasible: the hard clauses alone are unsatisfiable.
    • Budgeted(lower, upper): the round budget ran out before the bounds met. lower only grows through cores; upper starts at the total soft weight and drops only when a model is found, so upper - lower is what is left to close.

    Proof

    pub struct Proof {
    lines : Array[String]
    }

    DRAT-style proof recorder. Every learnt clause is logged in the order the solver derives it; deletions are logged when the clause database is reduced. A final 0 line is appended when the solver proves UNSAT.

    Proof::add

    fn Proof::add(self : Proof, lits : Array[Int]) -> Unit

    Proof::delete

    fn Proof::delete(self : Proof, lits : Array[Int]) -> Unit

    Proof::empty

    fn Proof::empty(self : Proof) -> Unit

    Proof::new

    fn Proof::new() -> Proof

    Proof::text

    fn Proof::text(self : Proof) -> String

    DIMACS-style text of the whole proof.

    SolveOutcome

    pub enum SolveOutcome {
    Satisfiable
    Unsatisfiable
    Unknown
    }

    Outcome of a search. Unknown only appears when a conflict budget stopped the search before it could decide.

    Solver

    pub struct Solver {
    num_vars : Int
    clauses : Array[Clause]
    watches : Array[Array[Int]]
    assigns : Array[Int]
    levels : Array[Int]
    reasons : Array[Int]
    trail : Array[Int]
    trail_lim : Array[Int]
    qhead : Int
    activity : Array[Double]
    var_inc : Double
    heap : Array[Int]
    heap_pos : Array[Int]
    phase : Array[Bool]
    ok : Bool
    decisions : Int
    propagations : Int
    conflicts : Int
    minimised : Int
    restarts : Int
    learnts : Array[Int]
    max_learnts : Int
    conflicts_until_restart : Int
    proof : Proof?
    last_core : Array[Int]
    }

    CDCL SAT solver with two-watched-literal propagation, 1-UIP conflict analysis, VSIDS branching, phase saving, restarts and an optional DRAT proof log.

    Solver::add_clause

    fn Solver::add_clause(self : Solver, lits : Array[Int]) -> Bool

    Incrementally add a clause on top of the current state. The solver backtracks to level 0 first, so learnt clauses and activities are kept.

    Solver::decision_level

    fn Solver::decision_level(self : Solver) -> Int

    Solver::enable_proof

    fn Solver::enable_proof(self : Solver) -> Proof

    Solver::model

    fn Solver::model(self : Solver) -> Array[Bool]

    Current model as a per-variable boolean array.

    Solver::new

    fn Solver::new(formula : Formula) -> Solver

    Solver::new_var

    fn Solver::new_var(self : Solver) -> Int

    Allocate a fresh variable. Used by encodings (cardinality constraints, MaxSAT relaxations) that build on top of the solver.

    Solver::solve

    fn Solver::solve(self : Solver, assumptions : Array[Int]) -> Bool

    Main CDCL search. assumptions are temporary decisions on top of level 0.

    Solver::solve_core

    fn Solver::solve_core(self : Solver, assumptions : Array[Int]) -> (Bool, Array[Int])

    Solve under assumptions and, when the verdict is UNSAT, hand back a subset of the assumptions that is itself unsatisfiable. The subset is not guaranteed minimal: it is what the final conflict's reason graph justifies, which is enough to use as an unsat core for MaxSAT bounds and for explaining why a query failed. The core is empty when the verdict does not depend on any assumption, i.e. the hard clauses alone are unsatisfiable.

    Solver::solve_with_budget

    fn Solver::solve_with_budget(self : Solver, assumptions : Array[Int], max_conflicts : Int) -> SolveOutcome

    Search that gives up after max_conflicts conflicts and reports Unknown. The learnt clauses and statistics survive, so the caller can resume with a larger budget or with solve.

    Solver::stats_string

    fn Solver::stats_string(self : Solver) -> String

    Statistics rendered as a single line, useful for benchmarks and CI output.

    Solver::value_lit

    fn Solver::value_lit(self : Solver, l : Int) -> Int

    Wcnf

    pub struct Wcnf {
    num_vars : Int
    top : Int
    hard : Array[Array[Int]]
    soft : Array[Array[Int]]
    weights : Array[Int]
    header_ok : Bool
    }

    Weighted partial MaxSAT instance (WCNF).

    check_drat

    fn check_drat(formula : Formula, steps : Array[DratStep]) -> Bool

    Verify a DRAT proof against the original formula, accepting RUP only. Every added clause must be a RUP consequence of the current pool, and the proof must end with the empty clause. Clause deletions are honoured by marking the matched clause dead. This is the mode the CDCL core produces and the mode the competition-facing claims rest on.

    check_drat_rat

    fn check_drat_rat(formula : Formula, steps : Array[DratStep]) -> Bool

    Verify a DRAT proof with the full rule set: an added clause is accepted when it is either RUP or RAT on its first literal. This is what external tools emit when they introduce definitions that are not implied by the formula.

    lit_is_neg

    fn lit_is_neg(l : Int) -> Bool

    Whether the literal is negated.

    lit_neg

    fn lit_neg(l : Int) -> Int

    Complement of a literal. lit_neg(lit_neg(l)) == l.

    lit_new

    fn lit_new(v : Int, neg : Bool) -> Int

    Build a literal from a variable and a sign flag.

    lit_var

    fn lit_var(l : Int) -> Int

    Variable index of a literal.

    maxsat_bound_proof

    fn maxsat_bound_proof(w : Wcnf, k : Int) -> String?

    A DRAT proof that no assignment keeps the soft cost within k, or None when such an assignment exists. The proof is stated over the extended CNF from maxsat_encoding, so it can be replayed without trusting the solver run that produced it.

    maxsat_core_bound

    fn maxsat_core_bound(w : Wcnf) -> Int

    A lower bound on the optimal cost taken from one unsat core: the soft clauses in the core cannot all hold at once, so at least the cheapest of them is violated. Returns 0 when every soft clause can be satisfied simultaneously, and -1 when the hard clauses alone are unsatisfiable.

    maxsat_encoding

    fn maxsat_encoding(w : Wcnf, k : Int) -> Formula

    Build the cardinality-extended CNF that decides whether the soft-clause cost can stay within k: an enumeration of partial MaxSAT as a single SAT instance. The construction is deterministic, which is what makes an exported lower-bound proof checkable against a freshly rebuilt encoding.

    maxsat_model

    fn maxsat_model(w : Wcnf, weight_cap : Int) -> (Array[Bool], Int)?

    Same as maxsat_solution, but never raises: an exceeded weight cap is reported as None instead of an error, so a first call needs no try.

    maxsat_model_cost

    fn maxsat_model_cost(w : Wcnf, model : Array[Bool]) -> Int

    Cost of an assignment: the sum of weights of violated soft clauses, or -1 when some hard clause fails. The cost is recomputed from the assignment, never taken from the search loop that produced it.

    maxsat_oll

    fn maxsat_oll(w : Wcnf) -> Int

    Optimal weighted MaxSAT cost by core-guided search, or -1 when the hard clauses alone are unsatisfiable. No cap on the total soft weight: this path never builds a cardinality encoding.

    maxsat_oll_result

    fn maxsat_oll_result(w : Wcnf, max_rounds : Int) -> OllOutcome

    Core-guided run with a round budget, so a large instance cannot spin forever. max_rounds <= 0 means no budget. A round is one core query plus its bookkeeping; the count is deterministic for a given input, not a wall-clock deadline.

    maxsat_oll_solution

    fn maxsat_oll_solution(w : Wcnf) -> (Array[Bool], Int)?

    Optimal assignment and its cost by core-guided search. None when the hard clauses alone are unsatisfiable.

    maxsat_solution

    fn maxsat_solution(w : Wcnf, weight_cap : Int) -> (Array[Bool], Int)? raise

    An assignment reaching the optimum and the cost it actually pays. None when the hard clauses alone are unsatisfiable.

    maxsat_solve

    fn maxsat_solve(w : Wcnf, weight_cap : Int) -> Int raise

    Optimal weighted MaxSAT cost, or -1 when the hard clauses alone are unsatisfiable. Weight totalling is capped so the cardinality encoding stays small; the cap is reported rather than silently ignored.

    parse_dimacs

    fn parse_dimacs(text : String) -> Formula raise

    Parse DIMACS CNF text.

    parse_drat

    fn parse_drat(text : String) -> Array[DratStep]

    Parse the textual proof produced by Proof into steps.

    parse_wcnf

    fn parse_wcnf(text : String) -> Wcnf

    Parse the DIMACS WCNF dialect: p wcnf V C TOP, then one clause per line prefixed by its weight. Clauses whose weight reaches TOP are hard.

    to_dimacs

    fn to_dimacs(formula : Formula) -> String

    Render the formula as DIMACS text (1-based variable numbers).

    verify_maxsat_bound

    fn verify_maxsat_bound(w : Wcnf, k : Int, proof_text : String) -> Bool

    Check a lower-bound proof: rebuild the encoding for the same k and replay the DRAT steps against it. A true answer means the proof really does establish that cost k is unreachable.

    verify_maxsat_solution

    fn verify_maxsat_solution(w : Wcnf, model : Array[Bool], claimed_cost : Int) -> Bool

    Check an optimal assignment the same way a third party would: the model must satisfy every hard clause, and the recomputed soft cost must equal the claimed optimum. This is the upper half of an optimality claim.

    verify_proof

    fn verify_proof(formula : Formula, proof_text : String) -> Bool

    Convenience wrapper: verify the textual proof for a formula, RUP only.

    verify_proof_rat

    fn verify_proof_rat(formula : Formula, proof_text : String) -> Bool

    Convenience wrapper: verify the textual proof with the RUP + RAT rule set.

    wcnf_error

    fn wcnf_error(w : Wcnf) -> String?

    Why this instance cannot be optimised, or None when it is well formed. A WCNF file without p wcnf <vars> <clauses> <top> (with a positive top) cannot say which clauses are hard, and a negative weight has no meaning in the cost model; both used to be accepted silently and then either mis-read the instance or drive the encoder into an invalid range.