|
| 1 | +//! # SAT Solver Engine |
| 2 | +//! |
| 3 | +//! This module provides a core CDCL (Conflict-Driven Clause Learning) engine |
| 4 | +//! utilizing the Two-Watched Literal (2WL) scheme for efficient unit propagation. |
| 5 | +//! |
| 6 | +//! ## Core Logic |
| 7 | +//! The engine works by: |
| 8 | +//! 1. **Assignment**: Values are assigned to variables via `assert`. |
| 9 | +//! 2. **Propagation**: The engine uses watch lists to find unit clauses. |
| 10 | +//! 3. **Conflict Analysis**: If a contradiction is found, the engine performs |
| 11 | +//! 1-UIP (Unique Implication Point) analysis to learn a new clause. |
| 12 | +//! |
| 13 | +//! ## Example |
| 14 | +//! ```rust |
| 15 | +//! # use consensus::{Engine, pos, neg}; |
| 16 | +//! let mut engine = Engine::new(); |
| 17 | +//! let a = engine.add_var(); |
| 18 | +//! let b = engine.add_var(); |
| 19 | +//! engine.add_clause(vec![neg(a), pos(b)]); // (¬a ∨ b) |
| 20 | +//! engine.assert(pos(a)); // Forces b to be True |
| 21 | +//! ``` |
1 | 22 | use std::{ |
2 | 23 | cmp::Ordering, |
3 | 24 | collections::{HashMap, VecDeque}, |
@@ -128,6 +149,21 @@ impl Display for Clause { |
128 | 149 | } |
129 | 150 | } |
130 | 151 |
|
| 152 | +/// A CDCL-based SAT solver engine. |
| 153 | +/// |
| 154 | +/// The `Engine` manages variable assignments, watch lists for unit propagation, |
| 155 | +/// and performs conflict analysis to learn new clauses. |
| 156 | +/// |
| 157 | +/// # Examples |
| 158 | +/// ``` |
| 159 | +/// # use consensus::{Engine, pos, neg, LBool}; |
| 160 | +/// let mut engine = Engine::new(); |
| 161 | +/// let a = engine.add_var(); |
| 162 | +/// let b = engine.add_var(); |
| 163 | +/// engine.add_clause(vec![neg(a), pos(b)]); // (¬a ∨ b) |
| 164 | +/// engine.assert(pos(a)); // Forces b to be True |
| 165 | +/// assert_eq!(*engine.value(b), LBool::True, "b should be propagated by unit clause"); |
| 166 | +/// ``` |
131 | 167 | pub struct Engine { |
132 | 168 | assigns: Vec<LBool>, // Current assignments of variables |
133 | 169 | seen: Vec<bool>, // Used during conflict analysis to track seen variables |
|
0 commit comments