Skip to content

Commit

Permalink
refactor: simple cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukáš Chudíček committed Jan 14, 2024
1 parent 5134380 commit 2dda391
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 6,365 deletions.
1 change: 0 additions & 1 deletion src/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod reachability;
pub mod rewritten_reachability;
mod utils;
50 changes: 21 additions & 29 deletions src/benchmarks/rewritten_reachability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ use biodivine_lib_bdd::Bdd;
use std::fmt::Debug;

use crate::{
benchmarks::utils::{count_states, log_percent, pick_state_bdd, unit_vertex_set},
prelude::find_start_of,
symbolic_domains::symbolic_domain::SymbolicDomainOrd,
prelude::find_start_of, symbolic_domains::symbolic_domain::SymbolicDomainOrd,
update::update_fn::SmartSystemUpdateFn as RewrittenSmartSystemUpdateFn,
};

pub fn log_percent(set: &Bdd, universe: &Bdd) -> f64 {
set.cardinality().log2() / universe.cardinality().log2() * 100.0
}

pub fn reachability_benchmark<DO: SymbolicDomainOrd<u8> + Debug>(sbml_path: &str) {
let smart_system_update_fn = {
let mut xml = xml::reader::EventReader::new(std::io::BufReader::new(
Expand All @@ -21,22 +23,20 @@ pub fn reachability_benchmark<DO: SymbolicDomainOrd<u8> + Debug>(sbml_path: &str
.expect("Loading system fn update failed.")
};

let unit = unit_vertex_set(&smart_system_update_fn);
let system_var_count = smart_system_update_fn
.variables_transition_relation_and_domain
.len();
let unit = smart_system_update_fn.unit_vertex_set();
let system_var_count = smart_system_update_fn.standard_variables().len();
println!(
"Variables: {}, expected states {}",
system_var_count,
1 << system_var_count
);
println!(
"Computed state count: {}",
count_states(&smart_system_update_fn, &unit)
smart_system_update_fn.count_states(&unit)
);
let mut universe = unit.clone();
while !universe.is_false() {
let mut weak_scc = pick_state_bdd(&smart_system_update_fn, &universe);
let mut weak_scc = smart_system_update_fn.pick_state_bdd(&universe);
loop {
let bwd_reachable = reach_bwd(&smart_system_update_fn, &weak_scc, &universe);
let fwd_bwd_reachable = reach_fwd(&smart_system_update_fn, &bwd_reachable, &universe);
Expand All @@ -45,7 +45,7 @@ pub fn reachability_benchmark<DO: SymbolicDomainOrd<u8> + Debug>(sbml_path: &str
if !fwd_bwd_reachable.imp(&weak_scc).is_true() {
println!(
" + SCC increased to (states={}, size={})",
count_states(&smart_system_update_fn, &weak_scc),
smart_system_update_fn.count_states(&weak_scc),
weak_scc.size()
);
weak_scc = fwd_bwd_reachable;
Expand All @@ -55,15 +55,15 @@ pub fn reachability_benchmark<DO: SymbolicDomainOrd<u8> + Debug>(sbml_path: &str
}
println!(
" + Found weak SCC (states={}, size={})",
count_states(&smart_system_update_fn, &weak_scc),
smart_system_update_fn.count_states(&weak_scc),
weak_scc.size()
);
// Remove the SCC from the universe set and start over.
universe = universe.and_not(&weak_scc);
println!(
" + Remaining states: {}/{}",
count_states(&smart_system_update_fn, &universe),
count_states(&smart_system_update_fn, &unit),
smart_system_update_fn.count_states(&universe),
smart_system_update_fn.count_states(&unit),
);
}
}
Expand All @@ -79,15 +79,11 @@ pub fn reach_fwd<D: SymbolicDomainOrd<u8> + Debug>(
) -> Bdd {
// The list of system variables, sorted in descending order (i.e. opposite order compared
// to the ordering inside BDDs).
let sorted_variables = system
.variables_transition_relation_and_domain
.iter()
.map(|(var_name, _)| var_name)
.collect::<Vec<_>>();
let sorted_variables = system.get_system_variables();
let mut result = initial.clone();
println!(
"Start forward reachability: (states={}, size={})",
count_states(system, &result),
system.count_states(&result),
result.size()
);
'fwd: loop {
Expand All @@ -100,7 +96,7 @@ pub fn reach_fwd<D: SymbolicDomainOrd<u8> + Debug>(
println!(
" >> (progress={:.2}%%, states={}, size={})",
log_percent(&result, universe),
count_states(system, &result),
system.count_states(&result),
result.size()
);
continue 'fwd;
Expand All @@ -110,7 +106,7 @@ pub fn reach_fwd<D: SymbolicDomainOrd<u8> + Debug>(
// No further successors were computed across all variables. We are done.
println!(
" >> Done. (states={}, size={})",
count_states(system, &result),
system.count_states(&result),
result.size()
);
return result;
Expand All @@ -126,15 +122,11 @@ pub fn reach_bwd<D: SymbolicDomainOrd<u8> + Debug>(
initial: &Bdd,
universe: &Bdd,
) -> Bdd {
let sorted_variables = system
.variables_transition_relation_and_domain
.iter()
.map(|(var_name, _)| var_name)
.collect::<Vec<_>>();
let sorted_variables = system.get_system_variables();
let mut result = initial.clone();
println!(
"Start backward reachability: (states={}, size={})",
count_states(system, &result),
system.count_states(&result),
result.size()
);
'bwd: loop {
Expand All @@ -147,7 +139,7 @@ pub fn reach_bwd<D: SymbolicDomainOrd<u8> + Debug>(
println!(
" >> (progress={:.2}%%, states={}, size={})",
log_percent(&result, universe),
count_states(system, &result),
system.count_states(&result),
result.size()
);
continue 'bwd;
Expand All @@ -157,7 +149,7 @@ pub fn reach_bwd<D: SymbolicDomainOrd<u8> + Debug>(
// No further predecessors were computed across all variables. We are done.
println!(
" >> Done. (states={}, size={})",
count_states(system, &result),
system.count_states(&result),
result.size()
);
return result;
Expand Down
69 changes: 0 additions & 69 deletions src/benchmarks/utils.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/expression_components/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,3 @@ pub enum Expression<T> {
Xor(Box<Expression<T>>, Box<Expression<T>>),
Implies(Box<Expression<T>>, Box<Expression<T>>),
}

// // todo
// // really torn apart between keeping this here, moving it to a separate file within
// // this module, and moving it into the `xml_parsing` module
// impl<T: FromStr> Expression<T> {
// pub fn try_from_xml<XR, BR>(_xml: &mut XR)
// where
// XR: XmlReader<BR>,
// BR: BufRead,
// {
// unimplemented!()
// }
// }
4 changes: 1 addition & 3 deletions src/expression_components/proposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl ComparisonOperator {
}

impl FromStr for ComparisonOperator {
type Err = (); // todo maybe better error
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
Expand Down Expand Up @@ -62,9 +62,7 @@ impl ToString for ComparisonOperator {
#[derive(Debug)]
pub struct Proposition<T> {
pub comparison_operator: ComparisonOperator,
// ci = variable name in the xml file // todo remove this comment likely; user of this file should not care about xml
pub variable: String,
// cn = constant value in the xml file // todo remove this comment likely; user of this file should not care about xml
pub value: T,
}

Expand Down
Loading

0 comments on commit 2dda391

Please sign in to comment.