rustsat::types

Struct Var

Source
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

Source

pub const MAX_IDX: u32 = 2_147_483_647u32

The maximum index that can be represented.

Source

pub const fn new(idx: u32) -> Var

Creates a new variables with a given index. Indices start from 0.

§Panics

If idx > Var::MAX_IDX.

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

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.

Source

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

Source

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));
Source

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());
Source

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());
Source

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());
Source

pub fn idx32(self) -> u32

Returns the 32 bit index of the variable.

§Examples
let var = Var::new(5);
assert_eq!(5, var.idx32());
Source

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.

Source

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 Add<u32> for Var

Incrementing variables

Source§

type Output = Var

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u32) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<u32> for Var

Source§

fn add_assign(&mut self, rhs: u32)

Performs the += operation. Read more
Source§

impl Clone for Var

Source§

fn clone(&self) -> Var

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 Var

Variables can be printed with the Debug trait

Source§

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

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

impl Display for Var

Variables can be printed with the Display trait

Source§

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

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

impl Hash for Var

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<Var> for Assignment

Source§

type Output = TernaryVal

The returned type after indexing.
Source§

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

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

impl IndexMut<Var> for Assignment

Source§

fn index_mut(&mut self, index: Var) -> &mut Self::Output

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

impl Ord for Var

Source§

fn cmp(&self, other: &Var) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Var

Source§

fn eq(&self, other: &Var) -> 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 PartialOrd for Var

Source§

fn partial_cmp(&self, other: &Var) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub<u32> for Var

Decrementing variables

Source§

type Output = Var

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u32) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<u32> for Var

Source§

fn sub_assign(&mut self, rhs: u32)

Performs the -= operation. Read more
Source§

impl Copy for Var

Source§

impl Eq for Var

Source§

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> 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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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