Skip to content

Commit e78b038

Browse files
Enhance documentation for SAT Solver Engine and provide usage examples
1 parent f531cc4 commit e78b038

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
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+
//! ```
122
use std::{
223
cmp::Ordering,
324
collections::{HashMap, VecDeque},
@@ -128,6 +149,21 @@ impl Display for Clause {
128149
}
129150
}
130151

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+
/// ```
131167
pub struct Engine {
132168
assigns: Vec<LBool>, // Current assignments of variables
133169
seen: Vec<bool>, // Used during conflict analysis to track seen variables

0 commit comments

Comments
 (0)