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
impl BddPartialValuation
sourcepub fn empty() -> BddPartialValuation
pub fn empty() -> BddPartialValuation
Creates an empty valuation without any variables set.
Examples found in repository?
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()
);
}
}
}
sourcepub fn cardinality(&self) -> u16
pub fn cardinality(&self) -> u16
Return the number of fixed variables in this valuation.
sourcepub fn last_fixed_variable(&self) -> Option<BddVariable>
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.
sourcepub fn from_values(values: &[(BddVariable, bool)]) -> BddPartialValuation
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.
sourcepub fn to_values(&self) -> Vec<(BddVariable, bool)>
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?
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()
);
}
}
}
sourcepub fn get_value(&self, id: BddVariable) -> Option<bool>
pub fn get_value(&self, id: BddVariable) -> Option<bool>
Get a value stored for the given variable id, if any.
sourcepub fn has_value(&self, id: BddVariable) -> bool
pub fn has_value(&self, id: BddVariable) -> bool
Returns true
if this valuation has the value of id
variable set.
sourcepub fn set_value(&mut self, id: BddVariable, value: bool)
pub fn set_value(&mut self, id: BddVariable, value: bool)
Update value of the given id
variable.
sourcepub fn unset_value(&mut self, id: BddVariable)
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.
sourcepub fn extends(&self, valuation: &BddPartialValuation) -> bool
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
impl Clone for BddPartialValuation
source§fn clone(&self) -> BddPartialValuation
fn clone(&self) -> BddPartialValuation
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for BddPartialValuation
impl Debug for BddPartialValuation
source§impl Default for BddPartialValuation
impl Default for BddPartialValuation
source§impl From<BddValuation> for BddPartialValuation
impl From<BddValuation> for BddPartialValuation
source§fn from(value: BddValuation) -> Self
fn from(value: BddValuation) -> Self
source§impl Hash for BddPartialValuation
impl Hash for BddPartialValuation
source§impl Index<BddVariable> for BddPartialValuation
impl Index<BddVariable> for BddPartialValuation
source§impl IndexMut<BddVariable> for BddPartialValuation
impl IndexMut<BddVariable> for BddPartialValuation
source§impl PartialEq for BddPartialValuation
impl PartialEq for BddPartialValuation
source§impl TryFrom<BddPartialValuation> for BddValuation
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.