Struct Cnf

Source
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

Source

pub fn new() -> Cnf

Creates a new Cnf

Examples found in repository?
examples/profiling.rs (line 75)
68fn build_full_ub<PBE: BoundUpper + FromIterator<(Lit, usize)>>(lits: &[(Lit, usize)]) {
69    let mut enc = PBE::from_iter(lits.iter().copied());
70    let max_var = lits
71        .iter()
72        .fold(Var::new(0), |mv, (lit, _)| std::cmp::max(lit.var(), mv));
73    let mut var_manager = BasicVarManager::default();
74    var_manager.increase_next_free(max_var + 1);
75    let mut collector = Cnf::new();
76    enc.encode_ub(.., &mut collector, &mut var_manager).unwrap();
77}
Source

pub fn with_capacity(capacity: usize) -> Cnf

Creates a new Cnf with a given capacity of clauses

Source

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.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the allocated memory of the Cnf to fit the number of clauses

Source

pub fn capacity(&self) -> usize

Gets the capacity of the Cnf

Source

pub fn is_empty(&self) -> bool

Checks if the CNF is empty

Source

pub fn len(&self) -> usize

Returns the number of clauses in the instance

Source

pub fn clear(&mut self)

Clears the CNF formula

Source

pub fn add_nary(&mut self, lits: &[Lit])

Adds a clause from a slice of literals

Source

pub fn add_lit_impl_lit(&mut self, a: Lit, b: Lit)

Source

pub fn add_lit_impl_clause(&mut self, a: Lit, b: &[Lit])

Source

pub fn add_lit_impl_cube(&mut self, a: Lit, b: &[Lit])

Source

pub fn add_cube_impl_lit(&mut self, a: &[Lit], b: Lit)

Source

pub fn add_clause_impl_lit(&mut self, a: &[Lit], b: Lit)

Source

pub fn add_cube_impl_clause(&mut self, a: &[Lit], b: &[Lit])

Source

pub fn add_clause_impl_clause(&mut self, a: &[Lit], b: &[Lit])

Source

pub fn add_clause_impl_cube(&mut self, a: &[Lit], b: &[Lit])

Source

pub fn add_cube_impl_cube(&mut self, a: &[Lit], b: &[Lit])

Source

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.

Source

pub fn iter(&self) -> Iter<'_, Clause>

Returns an iterator over references to the clauses

Source

pub fn iter_mut(&mut self) -> IterMut<'_, Clause>

Returns an iterator over mutable references to the clauses

Source

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.

Source

pub fn sanitize(self) -> Self

Sanitizes the CNF by removing tautologies, removing redundant literals, etc.

Source

pub fn shuffle(self) -> Self

Available on crate feature rand only.

Randomly shuffles the order of clauses in the CNF

Source

pub fn add_clause(&mut self, clause: Clause)

Adds a clause to the CNF

Source

pub fn add_unit(&mut self, unit: Lit)

Adds a unit clause to the CNF

Source

pub fn add_binary(&mut self, lit1: Lit, lit2: Lit)

Adds a binary clause to the CNF

Source

pub fn add_ternary(&mut self, lit1: Lit, lit2: Lit, lit3: Lit)

Adds a ternary clause to the CNF

Source

pub fn write_dimacs_path<P: AsRef<Path>>( &self, path: P, n_vars: u32, ) -> Result<(), Error>

Writes the CNF to a DIMACS CNF file at a path

§Errors

If the file could not be written to, returns io::Error.

Source

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.

Source

pub fn evaluate(&self, assign: &Assignment) -> TernaryVal

Checks the value of the CNF under a given assignment

Source

pub fn is_sat(&self, assign: &Assignment) -> bool

👎Deprecated since 0.6.0: use evaluate instead and check against TernaryVal::True

Checks whether the CNF is satisfied by the given assignment

Trait Implementations§

Source§

impl Clone for Cnf

Source§

fn clone(&self) -> Cnf

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 CollectClauses for Cnf

Source§

fn n_clauses(&self) -> usize

Gets the number of clauses in the collection
Source§

fn extend_clauses<T>(&mut self, cl_iter: T) -> Result<(), OutOfMemory>
where T: IntoIterator<Item = Clause>,

Extends the clause collector with an iterator of clauses Read more
Source§

fn add_clause(&mut self, cl: Clause) -> Result<(), OutOfMemory>

Adds one clause to the collector Read more
Source§

impl Debug for Cnf

Source§

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

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

impl Default for Cnf

Source§

fn default() -> Cnf

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

impl<'de> Deserialize<'de> for Cnf

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Extend<Clause> for Cnf

Source§

fn extend<Iter: IntoIterator<Item = Clause>>(&mut self, iter: Iter)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<VM: ManageVars + Default> From<Cnf> for Instance<VM>

Source§

fn from(value: Cnf) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Clause> for Cnf

Source§

fn from_iter<T: IntoIterator<Item = Clause>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<CnfLine> for Cnf

Source§

fn from_iter<T: IntoIterator<Item = CnfLine>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<usize> for Cnf

Source§

type Output = Clause

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'slf> IntoIterator for &'slf Cnf

Source§

type Item = &'slf Clause

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'slf, Clause>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'slf> IntoIterator for &'slf mut Cnf

Source§

type Item = &'slf mut Clause

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'slf, Clause>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Cnf

Source§

type Item = Clause

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Clause>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Cnf

Source§

fn eq(&self, other: &Cnf) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Cnf

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Cnf

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<I> ClsIter for I
where I: IntoIterator<Item = Clause>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,