Skip to content

Commit

Permalink
A minor bugfix for the cases where variable zero is repeatedly added …
Browse files Browse the repository at this point in the history
…to the FVS unintentionally.
  • Loading branch information
daemontus committed Feb 8, 2024
1 parent 44ea59e commit c267750
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ impl SdGraph {
}
}

if best.1 == usize::MAX {
// The remaining graph is acyclic!
return result;
}

result.insert(best.0);
subgraph.remove(&best.0);
candidates.remove(&best.0);
Expand Down Expand Up @@ -132,9 +137,10 @@ impl SdGraph {

#[cfg(test)]
mod tests {
use crate::RegulatoryGraph;
use crate::_impl_regulatory_graph::signed_directed_graph::SdGraph;
use crate::_impl_regulatory_graph::signed_directed_graph::Sign::{Negative, Positive};
use crate::{BooleanNetwork, RegulatoryGraph, VariableId};
use std::collections::HashSet;

#[test]
pub fn test_feedback_vertex_set() {
Expand Down Expand Up @@ -194,4 +200,22 @@ mod tests {
assert!(p_fvs.contains(&d_1) || p_fvs.contains(&d_2));
assert!(n_fvs.contains(&d_1) || n_fvs.contains(&d_2) || n_fvs.contains(&d_3));
}

#[test]
fn test_feedback_vertex_set_2() {
let bn = BooleanNetwork::try_from(
r#"
a -> b
b -|? c
c -? a
a -| c
c -> d
e -| b
"#,
)
.unwrap();

let expected = HashSet::from_iter([VariableId::from_index(2)]);
assert_eq!(expected, bn.as_graph().feedback_vertex_set());
}
}

0 comments on commit c267750

Please sign in to comment.