use crate::{Graph, TdBag, TreeDecomposition};
pub(crate) type NamedGraph = (&'static str, u32, &'static [(u32, u32)]);
pub(crate) type GraphAtItsWidth = (&'static str, u32, &'static [(u32, u32)], u32);
pub(crate) fn make_td(bags: Vec<Vec<u32>>, tree_edges: Vec<(usize, usize)>) -> TreeDecomposition {
let num_vertices = bags
.iter()
.flatten()
.copied()
.max()
.map_or(0, |vertex| vertex + 1);
make_td_for(num_vertices, bags, tree_edges)
}
pub(crate) fn make_td_for(
num_vertices: u32,
bags: Vec<Vec<u32>>,
tree_edges: Vec<(usize, usize)>,
) -> TreeDecomposition {
let mut adj = vec![Vec::new(); bags.len()];
for &(a, b) in &tree_edges {
adj[a].push(b);
adj[b].push(a);
}
TreeDecomposition::from_parts(
num_vertices,
bags.into_iter().map(TdBag::new).collect(),
adj,
)
}
pub(crate) fn assert_valid_td(td: &TreeDecomposition, num_vertices: u32, edges: &[(u32, u32)]) {
let graph = Graph::new(num_vertices, edges.iter().copied());
td.validate(&graph)
.unwrap_or_else(|error| panic!("invalid tree decomposition: {error}"));
}
pub(crate) fn make_test_td() -> TreeDecomposition {
make_td(
vec![vec![0, 1, 2], vec![1, 2, 3], vec![3, 4, 5]],
vec![(0, 1), (1, 2)],
)
}