pub struct Cnf { /* private fields */ }Expand description
Simple type representing a CNF formula. Other than Instance<VM>, this
type only supports clauses and does have an internal variable manager.
Implementations§
Source§impl Cnf
impl Cnf
Sourcepub fn with_capacity(capacity: usize) -> Cnf
pub fn with_capacity(capacity: usize) -> Cnf
Creates a new Cnf with a given capacity of clauses
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve memory for at least additional new clauses
§Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the allocated memory of the Cnf to fit the number of clauses
Sourcepub fn add_lit_impl_lit(&mut self, a: Lit, b: Lit)
pub fn add_lit_impl_lit(&mut self, a: Lit, b: Lit)
Sourcepub fn add_lit_impl_clause(&mut self, a: Lit, b: &[Lit])
pub fn add_lit_impl_clause(&mut self, a: Lit, b: &[Lit])
Sourcepub fn add_lit_impl_cube(&mut self, a: Lit, b: &[Lit])
pub fn add_lit_impl_cube(&mut self, a: Lit, b: &[Lit])
Sourcepub fn add_cube_impl_lit(&mut self, a: &[Lit], b: Lit)
pub fn add_cube_impl_lit(&mut self, a: &[Lit], b: Lit)
Sourcepub fn add_clause_impl_lit(&mut self, a: &[Lit], b: Lit)
pub fn add_clause_impl_lit(&mut self, a: &[Lit], b: Lit)
Sourcepub fn add_cube_impl_clause(&mut self, a: &[Lit], b: &[Lit])
pub fn add_cube_impl_clause(&mut self, a: &[Lit], b: &[Lit])
Sourcepub fn add_clause_impl_clause(&mut self, a: &[Lit], b: &[Lit])
pub fn add_clause_impl_clause(&mut self, a: &[Lit], b: &[Lit])
Sourcepub fn add_clause_impl_cube(&mut self, a: &[Lit], b: &[Lit])
pub fn add_clause_impl_cube(&mut self, a: &[Lit], b: &[Lit])
Sourcepub fn add_cube_impl_cube(&mut self, a: &[Lit], b: &[Lit])
pub fn add_cube_impl_cube(&mut self, a: &[Lit], b: &[Lit])
Sourcepub fn join(self, other: Cnf) -> Cnf
pub fn join(self, other: Cnf) -> Cnf
Joins the current CNF with another one. Like Cnf::extend but
consumes the object and returns a new object.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, Clause>
pub fn iter_mut(&mut self) -> IterMut<'_, Clause>
Returns an iterator over mutable references to the clauses
Sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Normalizes the CNF. This includes normalizing and sorting the clauses, removing duplicates and tautologies. Comparing two normalized CNFs is equal to comparing sets of sets of literals.
Sourcepub fn sanitize(self) -> Self
pub fn sanitize(self) -> Self
Sanitizes the CNF by removing tautologies, removing redundant literals, etc.
Sourcepub fn shuffle(self) -> Self
Available on crate feature rand only.
pub fn shuffle(self) -> Self
rand only.Randomly shuffles the order of clauses in the CNF
Sourcepub fn add_clause(&mut self, clause: Clause)
pub fn add_clause(&mut self, clause: Clause)
Adds a clause to the CNF
Sourcepub fn add_binary(&mut self, lit1: Lit, lit2: Lit)
pub fn add_binary(&mut self, lit1: Lit, lit2: Lit)
Adds a binary clause to the CNF
Sourcepub fn add_ternary(&mut self, lit1: Lit, lit2: Lit, lit3: Lit)
pub fn add_ternary(&mut self, lit1: Lit, lit2: Lit, lit3: Lit)
Adds a ternary clause to the CNF
Sourcepub fn write_dimacs<W: Write>(
&self,
writer: &mut W,
n_vars: u32,
) -> Result<(), Error>
pub fn write_dimacs<W: Write>( &self, writer: &mut W, n_vars: u32, ) -> Result<(), Error>
Writes the CNF to DIMACS CNF
§Performance
For performance, consider using a std::io::BufWriter instance.
§Errors
If writing fails, returns io::Error.
Sourcepub fn evaluate(&self, assign: &Assignment) -> TernaryVal
pub fn evaluate(&self, assign: &Assignment) -> TernaryVal
Checks the value of the CNF under a given assignment
Sourcepub fn is_sat(&self, assign: &Assignment) -> bool
👎Deprecated since 0.6.0: use evaluate instead and check against TernaryVal::True
pub fn is_sat(&self, assign: &Assignment) -> bool
evaluate instead and check against TernaryVal::TrueChecks whether the CNF is satisfied by the given assignment
Trait Implementations§
Source§impl CollectClauses for Cnf
impl CollectClauses for Cnf
Source§fn extend_clauses<T>(&mut self, cl_iter: T) -> Result<(), OutOfMemory>where
T: IntoIterator<Item = Clause>,
fn extend_clauses<T>(&mut self, cl_iter: T) -> Result<(), OutOfMemory>where
T: IntoIterator<Item = Clause>,
Source§fn add_clause(&mut self, cl: Clause) -> Result<(), OutOfMemory>
fn add_clause(&mut self, cl: Clause) -> Result<(), OutOfMemory>
Source§impl<'de> Deserialize<'de> for Cnf
impl<'de> Deserialize<'de> for Cnf
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Extend<Clause> for Cnf
impl Extend<Clause> for Cnf
Source§fn extend<Iter: IntoIterator<Item = Clause>>(&mut self, iter: Iter)
fn extend<Iter: IntoIterator<Item = Clause>>(&mut self, iter: Iter)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<Clause> for Cnf
impl FromIterator<Clause> for Cnf
Source§impl FromIterator<CnfLine> for Cnf
impl FromIterator<CnfLine> for Cnf
Source§impl<'slf> IntoIterator for &'slf Cnf
impl<'slf> IntoIterator for &'slf Cnf
Source§impl<'slf> IntoIterator for &'slf mut Cnf
impl<'slf> IntoIterator for &'slf mut Cnf
Source§impl IntoIterator for Cnf
impl IntoIterator for Cnf
impl Eq for Cnf
impl StructuralPartialEq for Cnf
Auto Trait Implementations§
impl Freeze for Cnf
impl RefUnwindSafe for Cnf
impl Send for Cnf
impl Sync for Cnf
impl Unpin for Cnf
impl UnwindSafe for Cnf
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more