-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
176a66d
commit 92bbd7f
Showing
4 changed files
with
138 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::iterators::DomainIterator; | ||
use biodivine_lib_bdd::Bdd; | ||
use biodivine_lib_bdd::BddValuation; | ||
|
||
pub struct ImageIterator { | ||
domain_iterator: Box<dyn Iterator<Item = Vec<bool>>>, | ||
bdd: Bdd, | ||
} | ||
|
||
impl ImageIterator { | ||
pub(crate) fn new(input_count: usize, bdd: &Bdd) -> Self { | ||
Self { | ||
domain_iterator: Box::new(DomainIterator::from_count(input_count)), | ||
bdd: bdd.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl Iterator for ImageIterator { | ||
type Item = bool; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
self.domain_iterator | ||
.next() | ||
.map(|it| self.bdd.eval_in(&BddValuation::new(it))) | ||
} | ||
} | ||
|
||
// | ||
// #[cfg(test)] | ||
// mod tests { | ||
// use super::*; | ||
// use crate::expressions::var; | ||
// use crate::traits::BooleanFunction; | ||
// use std::collections::BTreeMap; | ||
// | ||
// #[test] | ||
// fn test_image_ok() { | ||
// let input = var("d") & var("b") | var("a"); | ||
// | ||
// let mut actual = input.image(); | ||
// let expected = [ | ||
// Some(input.evaluate(&BTreeMap::from([ | ||
// ("a".to_string(), false), | ||
// ("b".to_string(), false), | ||
// ("d".to_string(), false), | ||
// ]))), | ||
// Some(input.evaluate(&BTreeMap::from([ | ||
// ("a".to_string(), false), | ||
// ("b".to_string(), false), | ||
// ("d".to_string(), true), | ||
// ]))), | ||
// Some(input.evaluate(&BTreeMap::from([ | ||
// ("a".to_string(), false), | ||
// ("b".to_string(), true), | ||
// ("d".to_string(), false), | ||
// ]))), | ||
// Some(input.evaluate(&BTreeMap::from([ | ||
// ("a".to_string(), false), | ||
// ("b".to_string(), true), | ||
// ("d".to_string(), true), | ||
// ]))), | ||
// Some(input.evaluate(&BTreeMap::from([ | ||
// ("a".to_string(), true), | ||
// ("b".to_string(), false), | ||
// ("d".to_string(), false), | ||
// ]))), | ||
// Some(input.evaluate(&BTreeMap::from([ | ||
// ("a".to_string(), true), | ||
// ("b".to_string(), false), | ||
// ("d".to_string(), true), | ||
// ]))), | ||
// Some(input.evaluate(&BTreeMap::from([ | ||
// ("a".to_string(), true), | ||
// ("b".to_string(), true), | ||
// ("d".to_string(), false), | ||
// ]))), | ||
// Some(input.evaluate(&BTreeMap::from([ | ||
// ("a".to_string(), true), | ||
// ("b".to_string(), true), | ||
// ("d".to_string(), true), | ||
// ]))), | ||
// ]; | ||
// | ||
// assert_eq!(actual.next(), expected[0]); | ||
// assert_eq!(actual.next(), expected[1]); | ||
// assert_eq!(actual.next(), expected[2]); | ||
// assert_eq!(actual.next(), expected[3]); | ||
// assert_eq!(actual.next(), expected[4]); | ||
// assert_eq!(actual.next(), expected[5]); | ||
// assert_eq!(actual.next(), expected[6]); | ||
// assert_eq!(actual.next(), expected[7]); | ||
// | ||
// assert_eq!(actual.next(), None); | ||
// assert_eq!(actual.next(), None); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub use image::ImageIterator; | ||
pub use support::SupportIterator; | ||
|
||
mod image; | ||
mod support; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use biodivine_lib_bdd::{Bdd, BddSatisfyingValuations}; | ||
|
||
pub struct SupportIterator<'a> { | ||
inner: BddSatisfyingValuations<'a>, | ||
} | ||
|
||
impl<'a> SupportIterator<'a> { | ||
pub fn new(bdd: &Bdd) -> Self { | ||
let owned = bdd.clone(); | ||
Self { | ||
inner: owned.sat_valuations(), | ||
} | ||
} | ||
} | ||
|
||
impl Iterator for SupportIterator<'_> { | ||
type Item = Vec<bool>; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
self.inner.next().map(|it| it.vector()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters