BDD

Struct BDD 

Source
pub struct BDD<T>
where T: Clone + Debug + Eq + Hash,
{ /* private fields */ }
Expand description

A BDD is a Binary Decision Diagram, an efficient way to represent a Boolean function in a canonical way. (It is actually a “Reduced Ordered Binary Decision Diagram”, which gives it its canonicity assuming terminals are ordered consistently.)

A BDD is built up from terminals (free variables) and constants, combined with the logical combinators AND, OR, and NOT. It may be evaluated with certain terminal assignments.

The major advantage of a BDD is that its logical operations are performed, it will “self-simplify”: i.e., taking the OR of And(a, b) and And(a, Not(b)) will produce a without any further simplification step. Furthermore, the BDDFunc representing this value is canonical: if two different expressions are produced within the same BDD and they both result in (simplify down to) a, then the BDDFunc values will be equal. The tradeoff is that logical operations may be expensive: they are linear in BDD size, but BDDs may have exponential size (relative to terminal count) in the worst case.

Implementations§

Source§

impl<T> BDD<T>
where T: Clone + Debug + Eq + Hash,

Source

pub fn new() -> BDD<T>

Produce a new, empty, BDD.

Source

pub fn terminal(&mut self, t: T) -> BDDFunc

Produce a function within the BDD representing the terminal t. If this terminal has been used in the BDD before, the same BDDFunc will be returned.

Source

pub fn constant(&mut self, val: bool) -> BDDFunc

Produce a function within the BDD representing the constant value val.

Source

pub fn ite(&mut self, i: BDDFunc, t: BDDFunc, e: BDDFunc) -> BDDFunc

Produce a function within the BDD representing the logical if-then-else of the functions i, t, and e

Source

pub fn not(&mut self, n: BDDFunc) -> BDDFunc

Produce a function within the BDD representing the logical complement of the function n.

Source

pub fn and(&mut self, a: BDDFunc, b: BDDFunc) -> BDDFunc

Produce a function within the BDD representing the logical AND of the functions a and b.

Source

pub fn or(&mut self, a: BDDFunc, b: BDDFunc) -> BDDFunc

Produce a function within the BDD representing the logical OR of the functions a and b.

Source

pub fn xor(&mut self, a: BDDFunc, b: BDDFunc) -> BDDFunc

Produce a function within the BDD representing the logical XOR of the functions a and b.

Source

pub fn implies(&mut self, a: BDDFunc, b: BDDFunc) -> BDDFunc

Produce a function within the BDD representing the logical implication a -> b.

Source

pub fn sat(&self, f: BDDFunc) -> bool

Check whether the function f within the BDD is satisfiable.

Source

pub fn restrict(&mut self, f: BDDFunc, t: T, val: bool) -> BDDFunc

Return a new function based on f but with the given label forced to the given value.

Source

pub fn from_expr(&mut self, e: &Expr<T>) -> BDDFunc

Produce a function within the BDD representing the given expression e, which may contain ANDs, ORs, NOTs, terminals, and constants.

Source

pub fn evaluate(&self, f: BDDFunc, values: &HashMap<T, bool>) -> bool

Evaluate the function f in the BDD with the given terminal assignments. Any terminals not specified in values default to false.

Source

pub fn sat_one(&self, f: BDDFunc) -> Option<HashMap<T, bool>>

Compute an assignment for terminals which satisfies ‘f’. If satisfiable, this function returns a HashMap with the assignments (true, false) for terminals unless a terminal’s assignment does not matter for satisfiability. If ‘f’ is not satisfiable, returns None.

Example: for the boolean function “a or b”, this function could return one of the following two HashMaps: {“a” -> true} or {“b” -> true}.

Source

pub fn to_expr(&self, f: BDDFunc) -> Expr<T>

Convert the BDD to a minimized sum-of-products expression.

Source

pub fn to_dot(&self, f: BDDFunc) -> String

Export BDD to dot format (from the graphviz package) to enable visualization.

Source

pub fn max_sat(&mut self, funcs: &[BDDFunc]) -> BDDFunc

Produce a function that is true when the maximal number of given input functions are true.

Source

pub fn labels(&self) -> Vec<T>

Return a vector of all labels in the BDD.

Trait Implementations§

Source§

impl<T> Clone for BDD<T>
where T: Clone + Debug + Eq + Hash + Clone,

Source§

fn clone(&self) -> BDD<T>

Returns a duplicate 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<T> Debug for BDD<T>
where T: Clone + Debug + Eq + Hash + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for BDD<T>

§

impl<T> RefUnwindSafe for BDD<T>
where T: RefUnwindSafe,

§

impl<T> Send for BDD<T>
where T: Send,

§

impl<T> Sync for BDD<T>
where T: Sync,

§

impl<T> Unpin for BDD<T>
where T: Unpin,

§

impl<T> UnwindSafe for BDD<T>
where T: UnwindSafe,

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, dest: *mut u8)

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