pub struct Solver { /* private fields */ }Expand description
The CLS-based SAT/MaxSAT solver.
Implements Continuous Local Search, treating SAT as continuous optimization. Variables are relaxed from {0,1} to [0,1] and gradient descent with momentum is used to minimize the unsatisfied clause penalty.
§Algorithm
The solver minimizes the “unsatisfied-ness” of clauses:
- For each clause, compute the product of (1 - lit_value) for all literals
- This product is 0 when any literal is satisfied, approaching 1 when all fail
- Gradient descent moves variables to minimize this penalty
§Completeness
CLS is an incomplete solver - it can find satisfying assignments efficiently
but cannot prove unsatisfiability. For unsatisfiable instances, it will
return Unknown status with the best-effort assignment found.
§Example
use xlog_solve::{SolveInstance, Clause, Literal, Solver, SolverConfig};
// Create instance: (x0 OR x1) AND (NOT x0 OR x1)
let instance = SolveInstance::new(2, vec![
Clause::new(vec![Literal::positive(0), Literal::positive(1)]),
Clause::new(vec![Literal::negative(0), Literal::positive(1)]),
]);
// Solve with default config
let solver = Solver::new_cpu();
let result = solver.solve(instance.clone());
// Or with custom config
let config = SolverConfig::default().with_max_iterations(5000);
let solver = Solver::with_config_cpu(config);
let result = solver.solve(instance);Implementations§
Source§impl Solver
impl Solver
Sourcepub fn new_cpu() -> Self
pub fn new_cpu() -> Self
Creates a new CPU-based CLS solver with default configuration.
§Example
use xlog_solve::Solver;
let solver = Solver::new_cpu();Sourcepub fn with_config_cpu(config: SolverConfig) -> Self
pub fn with_config_cpu(config: SolverConfig) -> Self
Sourcepub fn config(&self) -> &SolverConfig
pub fn config(&self) -> &SolverConfig
Returns a reference to the solver configuration.
Sourcepub fn solve(&self, instance: SolveInstance) -> SolveResult
pub fn solve(&self, instance: SolveInstance) -> SolveResult
Solves the given SAT instance.
§Arguments
instance- The SAT/MaxSAT instance to solve
§Returns
A SolveResult containing:
Satstatus with satisfying assignment if foundUnknownstatus with best-effort assignment if not found
Note: CLS cannot prove unsatisfiability, so Unsat is never returned.
§Example
use xlog_solve::{SolveInstance, Clause, Literal, Solver, SolveStatus};
let instance = SolveInstance::new(1, vec![
Clause::new(vec![Literal::positive(0)]),
]);
let solver = Solver::new_cpu();
let result = solver.solve(instance);
assert!(matches!(result.status, SolveStatus::Sat));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Solver
impl RefUnwindSafe for Solver
impl Send for Solver
impl Sync for Solver
impl Unpin for Solver
impl UnsafeUnpin for Solver
impl UnwindSafe for Solver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more