Struct splr::solver::Solver

source ·
pub struct Solver {
    pub asg: AssignStack,
    pub cdb: ClauseDB,
    pub state: State,
}
Expand description

The SAT solver object consisting of 6 sub modules.

use crate::splr::*;
use crate::splr::{assign::{AssignIF, VarManipulateIF}, state::{State, StateIF}, types::*};
use std::path::Path;

let mut s = Solver::try_from(Path::new("cnfs/sample.cnf")).expect("can't load");
assert_eq!(s.asg.derefer(assign::property::Tusize::NumVar), 250);
assert_eq!(s.asg.derefer(assign::property::Tusize::NumUnassertedVar), 250);
if let Ok(Certificate::SAT(v)) = s.solve() {
    assert_eq!(v.len(), 250);
    // But don't expect `s.asg.var_stats().3 == 0` at this point.
    // It returns the number of vars which were assigned at decision level 0.
} else {
    panic!("It should be satisfied!");
}
assert_eq!(Solver::try_from(Path::new("cnfs/unsat.cnf")).expect("can't load").solve(), Ok(Certificate::UNSAT));

Fields§

§asg: AssignStack

assignment management

§cdb: ClauseDB

clause container

§state: State

misc data holder

Trait Implementations§

source§

impl Clone for Solver

source§

fn clone(&self) -> Solver

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Solver

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Solver

source§

fn default() -> Solver

Returns the “default value” for a type. Read more
source§

impl Instantiate for Solver

source§

fn instantiate(config: &Config, cnf: &CNFDescription) -> Solver

use crate::{splr::config::Config, splr::types::*};
use splr::solver::Solver;
let s = Solver::instantiate(&Config::default(), &CNFDescription::default());
source§

fn handle(&mut self, _e: SolverEvent)

update by a solver event.
source§

impl SatSolverIF for Solver

source§

fn build(config: &Config) -> Result<Solver, SolverError>

Examples
use splr::config::Config;
use splr::solver::{SatSolverIF, Solver};

let config = Config::from("cnfs/sample.cnf");
assert!(Solver::build(&config).is_ok());
source§

fn save_certification(&mut self)

dump an UNSAT certification file

source§

fn dump_cnf(&self, fname: &Path)

dump all active clauses and assertions as a CNF file.

source§

fn add_assignment(&mut self, val: i32) -> Result<&mut Solver, SolverError>

add an assignment to Solver. Read more
source§

fn add_clause<V>(&mut self, vec: V) -> Result<&mut Solver, SolverError>where V: AsRef<[i32]>,

add a literal to Solver. Read more
source§

fn add_var(&mut self) -> VarId

add a var to solver and return the number of vars. Read more
source§

fn reset(&mut self)

reinitialize a solver for incremental solving. Requires ‘incremental_solver’ feature
source§

impl SolveIF for Solver

source§

fn solve(&mut self) -> SolverResult

Examples
use splr::*;

let config = Config::from("cnfs/sample.cnf");
if let Ok(mut s) = Solver::build(&config) {
    let res = s.solve();
    assert!(res.is_ok());
    assert_ne!(res.unwrap(), Certificate::UNSAT);
}
source§

impl TryFrom<&Path> for Solver

source§

fn try_from(s: &Path) -> Result<Self, Self::Error>

return a new solver build for a CNF file.

Example
use crate::splr::solver::{SatSolverIF, Solver};
use std::path::Path;

let mut s = Solver::try_from(Path::new("cnfs/sample.cnf")).expect("fail to load");
§

type Error = SolverError

The type returned in the event of a conversion error.
source§

impl<V> TryFrom<(Config, &[V])> for Solverwhere V: AsRef<[i32]>,

Example

 use crate::splr::*;

 let v: Vec<Vec<i32>> = vec![];
 assert!(matches!(
     Solver::try_from((Config::default(), v.as_ref())),
     Ok(_)
 ));
 assert!(matches!(
     Solver::try_from((Config::default(), vec![vec![0_i32]].as_ref())),
     Err(Err(SolverError::InvalidLiteral))
 ));
§

type Error = Result<Certificate, SolverError>

The type returned in the event of a conversion error.
source§

fn try_from((config, vec): (Config, &[V])) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl ValidateIF for Solver

source§

fn inject_assignment(&mut self, vec: &[i32]) -> MaybeInconsistent

inject an assignment set into solver. An assignment set is represented by a list of i32.

#Example

use crate::{splr::config::Config, splr::types::*};
use splr::solver::{Solver, ValidateIF};

let cnf = CNFDescription {
        num_of_variables: 4,
        ..CNFDescription::default()
    };
let mut s = Solver::instantiate(&Config::default(), &cnf);
assert_eq!(s.inject_assignment(&[1i32, -2, 3]), Ok(()));
source§

fn validate(&self) -> Option<Vec<i32>>

returns None if the given assignment is a model of a problem. Otherwise returns a clause which is not satisfiable under a given assignment.

#Example

use crate::{splr::config::Config, splr::types::*};
use splr::solver::{Solver, ValidateIF};

let cnf = CNFDescription {
        num_of_variables: 4,
        ..CNFDescription::default()
    };
let mut s = Solver::instantiate(&Config::default(), &cnf);
s.inject_assignment(&[1i32, -2, 3]);
assert_eq!(s.validate(), None);

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.