pub struct Solutions {
pub assignments: FxHashSet<NonZeroI32>,
}Expand description
Represents a satisfying assignment (a model) for a CNF formula.
The assignments are stored as a set of NonZeroI32, where:
- A positive integer
vmeans variablevis assigned true. - A negative integer
-vmeans variablevis assigned false. This aligns with the DIMACS convention for representing literals.
Fields§
§assignments: FxHashSet<NonZeroI32>A set of non-zero integers representing the truth assignments of variables.
Positive v means variable v is true; negative -v means variable v is false.
Implementations§
Source§impl Solutions
impl Solutions
Sourcepub fn new(s: &[i32]) -> Self
pub fn new(s: &[i32]) -> Self
Creates a new Solutions instance from a slice of i32 (DIMACS literals).
Zero values in the input slice are ignored, as NonZeroI32 cannot be zero.
Sourcepub fn iter(&self) -> impl Iterator<Item = &NonZeroI32>
pub fn iter(&self) -> impl Iterator<Item = &NonZeroI32>
Returns an iterator over the assigned literals (&NonZeroI32).
Sourcepub fn check(&self, i: NonZeroI32) -> bool
pub fn check(&self, i: NonZeroI32) -> bool
Checks if a given literal (represented by NonZeroI32) is part of the solution.
For example, check(NonZeroI32::new(1).unwrap()) checks if variable 1 is true.
check(NonZeroI32::new(-2).unwrap()) checks if variable 2 is false.
Sourcepub fn add(&mut self, i: NonZeroI32)
pub fn add(&mut self, i: NonZeroI32)
Adds a literal assignment to the solution set.
Trait Implementations§
impl Eq for Solutions
impl StructuralPartialEq for Solutions
Auto Trait Implementations§
impl Freeze for Solutions
impl RefUnwindSafe for Solutions
impl Send for Solutions
impl Sync for Solutions
impl Unpin for Solutions
impl UnwindSafe for Solutions
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
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>
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 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>
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