-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from sybila/new-restrict
A faster restriction algorithm.
- Loading branch information
Showing
2 changed files
with
130 additions
and
8 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,36 @@ | ||
use biodivine_lib_bdd::{Bdd, BddPartialValuation}; | ||
use rand::prelude::{SliceRandom, StdRng}; | ||
use rand::{Rng, SeedableRng}; | ||
use std::time::Instant; | ||
|
||
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() | ||
); | ||
} | ||
} | ||
} |
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