Skip to main content

TreeDecomposition

Struct TreeDecomposition 

Source
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

Source

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.

Source

pub fn num_vertices(&self) -> u32

Number of vertices in the graph this decomposition was built for.

Source

pub fn bags(&self) -> &[TdBag]

Bags in index order.

Source

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.

Source

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.

Source

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.

Source

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?
examples/basic.rs (line 25)
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

Source

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.

Source

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

Source

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?
examples/basic.rs (line 26)
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

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

Source§

fn clone(&self) -> TreeDecomposition

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TreeDecomposition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TreeDecomposition

Source§

impl PartialEq for TreeDecomposition

Source§

fn eq(&self, other: &TreeDecomposition) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TreeDecomposition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.