pub trait SolverExecutor {
// Required methods
fn get_solver_path(&self) -> PathBuf;
fn execute(
&self,
dimacs: &str,
timeout: Option<Duration>,
) -> Result<SATResult, SATSolverError>;
fn get_args(&self, input_file: &Path) -> Vec<String>;
fn parse_output(
&self,
stdout: &str,
stderr: &str,
) -> Result<SATResult, SATSolverError>;
}Expand description
Trait for SAT solver execution.
This trait provides a unified interface for executing different SAT solvers. Each solver implementation handles its specific command-line interface and output format.
§Implementors
cadical::CaDiCaLExecutor(requirescadicalfeature)minisat::MiniSatExecutor(requiresminisatfeature)- [
glucose::GlucoseExecutor] (requiresglucosefeature) - [
lingeling::LingelingExecutor] (requireslingelingfeature) - [
kissat::KissatExecutor] (requireskissatfeature)
§Example
use sat_solvers::solvers::SolverExecutor;
use std::time::Duration;
fn solve_with_any_executor(executor: &impl SolverExecutor, dimacs: &str) {
let result = executor.execute(dimacs, Some(Duration::from_secs(30)));
match result {
Ok(r) => println!("Result: {}", r),
Err(e) => eprintln!("Error: {}", e),
}
}Required Methods§
Sourcefn get_solver_path(&self) -> PathBuf
fn get_solver_path(&self) -> PathBuf
Returns the path to the solver binary.
The path is typically determined at build time and embedded in the binary. It can often be overridden via environment variables.
Sourcefn execute(
&self,
dimacs: &str,
timeout: Option<Duration>,
) -> Result<SATResult, SATSolverError>
fn execute( &self, dimacs: &str, timeout: Option<Duration>, ) -> Result<SATResult, SATSolverError>
Executes the SAT solver with the given DIMACS input.
This is the main entry point for solving SAT problems. The input should be a valid DIMACS CNF formula.
§Arguments
dimacs- The SAT problem in DIMACS CNF formattimeout- Optional timeout duration. IfNone, no timeout is applied.
§Returns
Returns a SATResult indicating whether the problem is satisfiable,
unsatisfiable, or unknown (e.g., due to timeout).
§Errors
Returns SATSolverError if:
- The solver process fails to start (
SATSolverError::Io) - The solver crashes (
SATSolverError::ProcessCrashed) - The timeout is exceeded (
SATSolverError::Timeout) - The output cannot be parsed (
SATSolverError::OutputParseError)
Sourcefn parse_output(
&self,
stdout: &str,
stderr: &str,
) -> Result<SATResult, SATSolverError>
fn parse_output( &self, stdout: &str, stderr: &str, ) -> Result<SATResult, SATSolverError>
Parses the solver’s output to extract the result.
Each solver has its own output format. This method handles the solver-specific parsing logic.
§Arguments
stdout- The solver’s standard outputstderr- The solver’s standard error
§Errors
Returns SATSolverError::OutputParseError if the output cannot be parsed.