pub struct TreeDecomposition { /* private fields */ }Expand description
A tree decomposition: bags of vertices, and an acyclic adjacency over them.
TreeDecomposition::new validates the full graph contract. PACE text can
be parsed before its input graph is available, so call
TreeDecomposition::validate on a value returned by
TreeDecomposition::from_td. A disconnected graph may have one bag-tree
component per graph component.
Implementations§
Source§impl TreeDecomposition
impl TreeDecomposition
Sourcepub fn new(
graph: &Graph,
bags: impl IntoIterator<Item = Vec<u32>>,
tree_edges: impl IntoIterator<Item = (usize, usize)>,
) -> Result<Self, Error>
pub fn new( graph: &Graph, bags: impl IntoIterator<Item = Vec<u32>>, tree_edges: impl IntoIterator<Item = (usize, usize)>, ) -> Result<Self, Error>
Build and validate a tree decomposition of graph.
tree_edges are undirected pairs of indices into bags.
Sourcepub fn num_vertices(&self) -> u32
pub fn num_vertices(&self) -> u32
Number of vertices in the graph this decomposition was built for.
Sourcepub fn adjacency(&self) -> &[Vec<usize>]
pub fn adjacency(&self) -> &[Vec<usize>]
Undirected bag adjacency, indexed like Self::bags. A decomposition
built with Self::new has neighbours sorted by bag index; algorithms
constructing a decomposition directly may expose their stable traversal
order instead.
Sourcepub fn treewidth(&self) -> u32
pub fn treewidth(&self) -> u32
This decomposition’s width: the vertices in its largest bag, less one.
0 where there is nothing to separate — no bags, one empty bag and one
single-vertex bag alike.
An upper bound on the decomposed graph’s treewidth, which is the minimum width over all of its decompositions.
Sourcepub fn total_bag_size(&self) -> usize
pub fn total_bag_size(&self) -> usize
Sum of bag sizes: the secondary quality signal beside the width. Two decompositions of equal width can have very different total bag volume.
Sourcepub fn validate(&self, graph: &Graph) -> Result<(), Error>
pub fn validate(&self, graph: &Graph) -> Result<(), Error>
Check that this is a tree decomposition of graph.
This checks bag contents and acyclic bag adjacency, vertex and edge coverage, and the running intersection property. An empty decomposition is valid for an empty graph.
Examples found in repository?
4fn main() {
5 let graph = Graph::new(
6 8,
7 [
8 (0, 1),
9 (1, 2),
10 (3, 4),
11 (4, 5),
12 (0, 3),
13 (1, 4),
14 (2, 5),
15 (1, 3),
16 (2, 4),
17 (4, 6),
18 (5, 6),
19 (5, 7),
20 (6, 7),
21 ],
22 );
23 let td = decompose(&graph, Order::MinFill, 0, None).expect("valid order");
24
25 td.validate(&graph).expect("a valid decomposition");
26 print!("{}", td.to_td());
27}Source§impl TreeDecomposition
impl TreeDecomposition
Sourcepub fn rooted_forest(
&self,
roots: impl IntoIterator<Item = usize>,
) -> Result<RootedForest, Error>
pub fn rooted_forest( &self, roots: impl IntoIterator<Item = usize>, ) -> Result<RootedForest, Error>
Root this decomposition’s bag forest and walk it breadth-first.
Each entry in roots that has not already been reached opens a new
component. Any component not named in roots is then rooted at its
first bag, so every bag occurs in the result.
§Errors
Returns an error when a root is not a bag index.
Sourcepub fn project(&self, keep: &[u32]) -> Result<Projection, Error>
pub fn project(&self, keep: &[u32]) -> Result<Projection, Error>
Project onto keep, renumbering its sorted unique vertex ids to 0..k.
Projecting onto an empty set returns an empty decomposition.
§Errors
Returns an error when a requested vertex is outside this decomposition’s vertex range or occurs in no bag.
Source§impl TreeDecomposition
impl TreeDecomposition
Sourcepub fn to_td(&self) -> String
pub fn to_td(&self) -> String
Render as a PACE .td decomposition (1-indexed bags and vertices).
A decomposition forest is connected between component roots for the
PACE format; an empty decomposition is written as one empty bag.
Examples found in repository?
4fn main() {
5 let graph = Graph::new(
6 8,
7 [
8 (0, 1),
9 (1, 2),
10 (3, 4),
11 (4, 5),
12 (0, 3),
13 (1, 4),
14 (2, 5),
15 (1, 3),
16 (2, 4),
17 (4, 6),
18 (5, 6),
19 (5, 7),
20 (6, 7),
21 ],
22 );
23 let td = decompose(&graph, Order::MinFill, 0, None).expect("valid order");
24
25 td.validate(&graph).expect("a valid decomposition");
26 print!("{}", td.to_td());
27}Sourcepub fn from_td(text: &str) -> Result<Self, Error>
pub fn from_td(text: &str) -> Result<Self, Error>
Read a PACE .td decomposition — a treewidth solver’s output.
§Errors
Error::Parse describing what is wrong with text: a malformed
solution or bag line, an unparseable id, a bag or vertex id outside the
range the solution line declares, a bag list that does not define each
declared bag exactly once, a maximum-bag-size mismatch, a bag graph that
is not one tree, a missing declared vertex, a failed running-intersection
check, or no bags at all.
Trait Implementations§
Source§impl Clone for TreeDecomposition
impl Clone for TreeDecomposition
Source§fn clone(&self) -> TreeDecomposition
fn clone(&self) -> TreeDecomposition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more