pub struct Var { /* private fields */ }Expand description
Type representing boolean variables in a SAT problem. Variables indexing in
RustSAT starts from 0 and the maximum index is (u32::MAX - 1) / 2. This is
because literals are represented as a single u32 as well. The memory
representation of variables is u32.
Implementations§
Source§impl Var
impl Var
Sourcepub fn new_with_error(idx: u32) -> Result<Var, TypeError>
pub fn new_with_error(idx: u32) -> Result<Var, TypeError>
Creates a new variables with a given index. Indices start from 0.
§Errors
TypeError::IdxTooHigh(idx, Var::MAX_IDX) if idx > Var::MAX_IDX.
Sourcepub const unsafe fn new_unchecked(idx: u32) -> Var
pub const unsafe fn new_unchecked(idx: u32) -> Var
Creates a new variables with a given index.
Indices start from 0.
Does not perform any check on the index, therefore might produce an inconsistent variable.
Only use this for performance reasons if you are sure that idx <= Var::MAX_IDX.
§Safety
idx must be guaranteed to be not higher than Var::MAX_IDX
Sourcepub const fn lit(self, negated: bool) -> Lit
pub const fn lit(self, negated: bool) -> Lit
Creates a literal with a given negation from the variable
§Examples
let var = Var::new(5);
let lit = Lit::positive(5);
assert_eq!(lit, var.lit(false));Sourcepub const fn pos_lit(self) -> Lit
pub const fn pos_lit(self) -> Lit
Creates a literal that is not negated.
§Examples
let var = Var::new(5);
let lit = Lit::positive(5);
assert_eq!(lit, var.pos_lit());Sourcepub const fn neg_lit(self) -> Lit
pub const fn neg_lit(self) -> Lit
Creates a negated literal.
§Examples
let var = Var::new(5);
let lit = Lit::negative(5);
assert_eq!(lit, var.neg_lit());Sourcepub fn idx(self) -> usize
pub fn idx(self) -> usize
Returns the index of the variable. This is a usize to enable easier
indexing of data structures like vectors, even though the internal
representation of a variable is u32. For the 32 bit index use
Var::idx32.
§Examples
let var = Var::new(5);
assert_eq!(5, var.idx());Sourcepub fn idx32(self) -> u32
pub fn idx32(self) -> u32
Returns the 32 bit index of the variable.
§Examples
let var = Var::new(5);
assert_eq!(5, var.idx32());Sourcepub fn to_ipasir(self) -> c_int
pub fn to_ipasir(self) -> c_int
Converts the variable to an integer as accepted by
IPASIR and the DIMACS file
format. The IPASIR variable
will have idx+1.
§Panics
If the variable index does not fit in c_int. As c_int will almost always be
i32, this is only the case on very
esoteric platforms.
Sourcepub fn to_ipasir_with_error(self) -> Result<c_int, TypeError>
pub fn to_ipasir_with_error(self) -> Result<c_int, TypeError>
Converts the variable to an integer as accepted by
IPASIR and the DIMACS file
format. The IPASIR literal
will have idx+1 and be negative if the literal is negated.
§Errors
TypeError::IdxTooHigh(_, _) if the literal does not fit into a c_int. As c_int will
almost always be i32, it is mostly
safe to simply use Self::to_ipasir instead.
Trait Implementations§
Source§impl AddAssign<u32> for Var
impl AddAssign<u32> for Var
Source§fn add_assign(&mut self, rhs: u32)
fn add_assign(&mut self, rhs: u32)
+= operation. Read moreSource§impl Index<Var> for Assignment
impl Index<Var> for Assignment
Source§impl IndexMut<Var> for Assignment
impl IndexMut<Var> for Assignment
Source§impl Ord for Var
impl Ord for Var
Source§impl PartialOrd for Var
impl PartialOrd for Var
Source§impl SubAssign<u32> for Var
impl SubAssign<u32> for Var
Source§fn sub_assign(&mut self, rhs: u32)
fn sub_assign(&mut self, rhs: u32)
-= operation. Read moreimpl Copy for Var
impl Eq for Var
impl StructuralPartialEq for Var
Auto Trait Implementations§
impl Freeze for Var
impl RefUnwindSafe for Var
impl Send for Var
impl Sync for Var
impl Unpin for Var
impl UnwindSafe for Var
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