Struct biodivine_lib_bdd::BddPartialValuation

source ·
pub struct BddPartialValuation(/* private fields */);
Expand description

Describes assignment of some arbitrary number of Bdd variables.

A partial valuation can be used to quickly construct simple conjunctive/disjunctive clauses. It also exactly describes one path in a Bdd and hence can be used as an intermediate value when traversing the valuations of a Bdd.

Implementations§

source§

impl BddPartialValuation

source

pub fn empty() -> BddPartialValuation

Creates an empty valuation without any variables set.

Examples found in repository?
examples/bench_restrict.rs (line 16)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    let args = std::env::args().collect::<Vec<_>>();
    let mut file = std::fs::File::open(args[1].as_str()).unwrap();
    let bdd = Bdd::read_as_bytes(&mut file).unwrap();
    println!("Loaded: {} as Bdd({})", args[1].as_str(), bdd.size());

    let mut support = Vec::from_iter(bdd.support_set());

    for k in 1..5 {
        // Fix variables randomly.
        let mut reduction = BddPartialValuation::empty();
        let mut rng = StdRng::seed_from_u64(0);
        support.sort(); // Don't leak previous shuffled state.
        support.shuffle(&mut rng);

        for var in &support[0..k] {
            reduction[*var] = Some(rng.gen_bool(0.5));
        }

        // Run restriction.
        for _ in 0..5 {
            let start = Instant::now();
            let result = bdd.restrict(&reduction.to_values());
            println!(
                "Result: Bdd({}) in {}ms",
                result.size(),
                (Instant::now() - start).as_millis()
            );
        }
    }
}
source

pub fn is_empty(&self) -> bool

True if the valuation contains no values.

source

pub fn cardinality(&self) -> u16

Return the number of fixed variables in this valuation.

source

pub fn last_fixed_variable(&self) -> Option<BddVariable>

Return the identifier of the last fixed variable in this valuation. Returns None if no variable is fixed.

source

pub fn from_values(values: &[(BddVariable, bool)]) -> BddPartialValuation

Create a partial valuation from a list of variables and values.

The order of variables in the slice can be arbitrary. The operation does not perform any uniqueness checking. If the slice contains multiple copies of the same variable, the last value is accepted.

source

pub fn to_values(&self) -> Vec<(BddVariable, bool)>

Consume this valuation and turn it into a vector of values which are stored in it.

Examples found in repository?
examples/bench_restrict.rs (line 28)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    let args = std::env::args().collect::<Vec<_>>();
    let mut file = std::fs::File::open(args[1].as_str()).unwrap();
    let bdd = Bdd::read_as_bytes(&mut file).unwrap();
    println!("Loaded: {} as Bdd({})", args[1].as_str(), bdd.size());

    let mut support = Vec::from_iter(bdd.support_set());

    for k in 1..5 {
        // Fix variables randomly.
        let mut reduction = BddPartialValuation::empty();
        let mut rng = StdRng::seed_from_u64(0);
        support.sort(); // Don't leak previous shuffled state.
        support.shuffle(&mut rng);

        for var in &support[0..k] {
            reduction[*var] = Some(rng.gen_bool(0.5));
        }

        // Run restriction.
        for _ in 0..5 {
            let start = Instant::now();
            let result = bdd.restrict(&reduction.to_values());
            println!(
                "Result: Bdd({}) in {}ms",
                result.size(),
                (Instant::now() - start).as_millis()
            );
        }
    }
}
source

pub fn get_value(&self, id: BddVariable) -> Option<bool>

Get a value stored for the given variable id, if any.

source

pub fn has_value(&self, id: BddVariable) -> bool

Returns true if this valuation has the value of id variable set.

source

pub fn set_value(&mut self, id: BddVariable, value: bool)

Update value of the given id variable.

source

pub fn unset_value(&mut self, id: BddVariable)

Remove value of a variable from this valuation.

If the value was not set, this operation has no effect.

source

pub fn extends(&self, valuation: &BddPartialValuation) -> bool

Returns true if the values set in this partial valuation match the values fixed in the other given valuation. I.e. the two valuations agree on fixed values in valuation.

In other words this >= valuation in terms of specificity.

Trait Implementations§

source§

impl Clone for BddPartialValuation

source§

fn clone(&self) -> BddPartialValuation

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 BddPartialValuation

source§

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

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

impl Default for BddPartialValuation

source§

fn default() -> Self

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

impl From<BddValuation> for BddPartialValuation

source§

fn from(value: BddValuation) -> Self

Converts to this type from the input type.
source§

impl Hash for BddPartialValuation

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<BddVariable> for BddPartialValuation

§

type Output = Option<bool>

The returned type after indexing.
source§

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

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

impl IndexMut<BddVariable> for BddPartialValuation

source§

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

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

impl PartialEq for BddPartialValuation

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<BddPartialValuation> for BddValuation

If possible, convert the given partial valuation to valuation with the same number of variables. Partial valuation must contain values of all variables.

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(value: BddPartialValuation) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for BddPartialValuation

Auto Trait Implementations§

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> 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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