Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Gen_Centroid_Decomposition< GT, SA > Class Template Reference

Centroid decomposition over a rooted tree represented as an Aleph graph. More...

#include <Tree_Decomposition.H>

Collaboration diagram for Aleph::Gen_Centroid_Decomposition< GT, SA >:
[legend]

Public Types

using Node = typename GT::Node
 

Public Member Functions

 Gen_Centroid_Decomposition (const GT &g, Node *root, SA sa=SA())
 Construct using an explicit root node.
 
 Gen_Centroid_Decomposition (const GT &g, SA sa=SA())
 Construct using the first graph node as root.
 
 Gen_Centroid_Decomposition (const Gen_Centroid_Decomposition &other)=default
 Copy the centroid tree of another decomposition.
 
 Gen_Centroid_Decomposition (Gen_Centroid_Decomposition &&other) noexcept(std::is_nothrow_move_constructible_v< Topology >)
 Take the centroid tree of another decomposition, which is left empty.
 
Gen_Centroid_Decomposition & operator= (const Gen_Centroid_Decomposition &other)=default
 Copy the centroid tree of another decomposition.
 
Gen_Centroid_Decomposition & operator= (Gen_Centroid_Decomposition &&other) noexcept(noexcept(swap(other)))
 Exchange this decomposition with another, which is left with the previous centroid tree of this one.
 
void swap (Gen_Centroid_Decomposition &other) noexcept(std::is_nothrow_swappable_v< SA >)
 Exchange in O(1) this decomposition and another.
 
size_t size () const noexcept
 
bool is_empty () const noexcept
 
Node * root () const noexcept
 
size_t root_id () const noexcept
 
Node * node_of (const size_t id) const
 
size_t id_of (const Node *node) const
 
size_t centroid_root_id () const noexcept
 Root centroid ID of the centroid tree (or NONE if empty).
 
Node * centroid_root () const noexcept
 Root centroid node of the centroid tree (or nullptr if empty).
 
size_t centroid_parent_id (const size_t id) const
 Parent centroid ID of id (or NONE if centroid root).
 
Node * centroid_parent (const Node *node) const
 Parent centroid of node (or nullptr if centroid root).
 
size_t centroid_level_of_id (const size_t id) const
 Level of centroid id in centroid tree (root level = 0).
 
size_t centroid_level_of (const Node *node) const
 Level of centroid node in centroid tree (root level = 0).
 
size_t max_centroid_level () const noexcept
 Maximum centroid-tree level.
 
size_t centroid_path_length_of_id (const size_t id) const
 Number of centroid ancestors stored for node ID.
 
size_t centroid_path_length_of (const Node *node) const
 Number of centroid ancestors stored for node.
 
const Array< size_t > & centroid_ancestors_of_id (const size_t id) const
 Centroid ancestors of node ID from centroid root down to local centroid.
 
const Array< size_t > & centroid_distances_of_id (const size_t id) const
 Distances to centroid ancestors (aligned with centroid_ancestors_of_id).
 
const Array< size_t > & centroid_ancestors_of (const Node *node) const
 Centroid ancestors of node from centroid root down to local centroid.
 
const Array< size_t > & centroid_distances_of (const Node *node) const
 Distances to centroid ancestors (aligned with centroid_ancestors_of).
 
bool is_centroid_ancestor_id (const size_t ancestor, const size_t node) const
 True iff ancestor is in the centroid-ancestor chain of node.
 
size_t distance_to_centroid_id (const size_t node, const size_t centroid) const
 Distance from node ID to a centroid ancestor ID.
 
template<class F >
void for_each_centroid_ancestor_id (const size_t node, F &&f) const
 Visit each centroid ancestor of node ID.
 
template<class F >
void for_each_centroid_ancestor (const Node *node, F &&f) const
 Visit each centroid ancestor of node.
 

Private Types

using Topology = tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >
 

Private Member Functions

void ensure_not_empty (const char *where) const
 
void init_storage ()
 
Array< size_t > collect_component_nodes (const size_t start)
 
size_t choose_centroid (const Array< size_t > &nodes)
 
void append_centroid_annotations (const size_t centroid)
 
void build_centroid_tree ()
 

Private Attributes

Topology topology_
 
Array< char > removed_
 
Array< size_t > centroid_parent_
 
Array< size_t > centroid_level_
 
size_t centroid_root_ = NONE
 
Array< size_t > local_parent_
 
Array< size_t > local_subtree_
 
Array< Array< size_t > > centroid_ancestors_
 
Array< Array< size_t > > centroid_distances_
 

Static Private Attributes

static constexpr size_t NONE = Topology::NONE
 

Detailed Description

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
class Aleph::Gen_Centroid_Decomposition< GT, SA >

Centroid decomposition over a rooted tree represented as an Aleph graph.

Decomposes a tree recursively by centroids, building a centroid tree.

For each original node u, the class stores:

  • centroid_ancestors_of_id(u)
  • centroid_distances_of_id(u)

where element k in both arrays corresponds to the same centroid ancestor.

Build complexity: O(n log n) Storage complexity: O(n log n)

Template Parameters
GTGraph type.
SAArc filter type.

Definition at line 1195 of file Tree_Decomposition.H.

Member Typedef Documentation

◆ Node

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Gen_Centroid_Decomposition< GT, SA >::Node = typename GT::Node

Definition at line 1198 of file Tree_Decomposition.H.

◆ Topology

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Gen_Centroid_Decomposition< GT, SA >::Topology = tree_decomposition_detail::Rooted_Tree_Topology<GT, SA>
private

Definition at line 1201 of file Tree_Decomposition.H.

Constructor & Destructor Documentation

◆ Gen_Centroid_Decomposition() [1/4]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Gen_Centroid_Decomposition< GT, SA >::Gen_Centroid_Decomposition ( const GT &  g,
Node *  root,
SA  sa = SA() 
)
inline

Construct using an explicit root node.

Definition at line 1409 of file Tree_Decomposition.H.

◆ Gen_Centroid_Decomposition() [2/4]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Gen_Centroid_Decomposition< GT, SA >::Gen_Centroid_Decomposition ( const GT &  g,
SA  sa = SA() 
)
inline

Construct using the first graph node as root.

Definition at line 1416 of file Tree_Decomposition.H.

◆ Gen_Centroid_Decomposition() [3/4]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Gen_Centroid_Decomposition< GT, SA >::Gen_Centroid_Decomposition ( const Gen_Centroid_Decomposition< GT, SA > &  other)
default

Copy the centroid tree of another decomposition.

Parameters
[in]otherdecomposition to copy.

◆ Gen_Centroid_Decomposition() [4/4]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Gen_Centroid_Decomposition< GT, SA >::Gen_Centroid_Decomposition ( Gen_Centroid_Decomposition< GT, SA > &&  other)
inlinenoexcept

Take the centroid tree of another decomposition, which is left empty.

The implicit move took the arrays but copied the root centroid: the moved-from decomposition then reported it for an empty tree, and centroid_root() looked it up in a topology without nodes.

Parameters
[in,out]otherdecomposition to move from.

Definition at line 1436 of file Tree_Decomposition.H.

Member Function Documentation

◆ append_centroid_annotations()

◆ build_centroid_tree()

◆ centroid_ancestors_of()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
const Array< size_t > & Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_ancestors_of ( const Node *  node) const
inline

Centroid ancestors of node from centroid root down to local centroid.

Definition at line 1578 of file Tree_Decomposition.H.

◆ centroid_ancestors_of_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
const Array< size_t > & Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_ancestors_of_id ( const size_t  id) const
inline

Centroid ancestors of node ID from centroid root down to local centroid.

Definition at line 1564 of file Tree_Decomposition.H.

Referenced by TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().

◆ centroid_distances_of()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
const Array< size_t > & Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_distances_of ( const Node *  node) const
inline

Distances to centroid ancestors (aligned with centroid_ancestors_of).

Definition at line 1584 of file Tree_Decomposition.H.

◆ centroid_distances_of_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
const Array< size_t > & Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_distances_of_id ( const size_t  id) const
inline

Distances to centroid ancestors (aligned with centroid_ancestors_of_id).

Definition at line 1571 of file Tree_Decomposition.H.

Referenced by TYPED_TEST(), and TYPED_TEST().

◆ centroid_level_of()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_level_of ( const Node *  node) const
inline

Level of centroid node in centroid tree (root level = 0).

Definition at line 1536 of file Tree_Decomposition.H.

◆ centroid_level_of_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_level_of_id ( const size_t  id) const
inline

Level of centroid id in centroid tree (root level = 0).

Definition at line 1529 of file Tree_Decomposition.H.

Referenced by TYPED_TEST(), and TYPED_TEST().

◆ centroid_parent()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Node * Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_parent ( const Node *  node) const
inline

Parent centroid of node (or nullptr if centroid root).

Definition at line 1522 of file Tree_Decomposition.H.

Referenced by TYPED_TEST().

◆ centroid_parent_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_parent_id ( const size_t  id) const
inline

Parent centroid ID of id (or NONE if centroid root).

Definition at line 1515 of file Tree_Decomposition.H.

Referenced by TYPED_TEST(), and TYPED_TEST().

◆ centroid_path_length_of()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_path_length_of ( const Node *  node) const
inline

Number of centroid ancestors stored for node.

Definition at line 1558 of file Tree_Decomposition.H.

◆ centroid_path_length_of_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_path_length_of_id ( const size_t  id) const
inline

Number of centroid ancestors stored for node ID.

Definition at line 1551 of file Tree_Decomposition.H.

Referenced by TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().

◆ centroid_root()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Node * Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_root ( ) const
inlinenoexcept

◆ centroid_root_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_root_id ( ) const
inlinenoexcept

Root centroid ID of the centroid tree (or NONE if empty).

Definition at line 1503 of file Tree_Decomposition.H.

Referenced by Moved_From_Case< Centroid_Decomposition< Graph > >::is_empty(), main(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().

◆ choose_centroid()

◆ collect_component_nodes()

◆ distance_to_centroid_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::distance_to_centroid_id ( const size_t  node,
const size_t  centroid 
) const
inline

Distance from node ID to a centroid ancestor ID.

Returns NONE if centroid is not in node's centroid-ancestor chain.

Definition at line 1608 of file Tree_Decomposition.H.

References chain().

Referenced by TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().

◆ ensure_not_empty()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_Centroid_Decomposition< GT, SA >::ensure_not_empty ( const char *  where) const
inlineprivate

◆ for_each_centroid_ancestor()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<class F >
void Aleph::Gen_Centroid_Decomposition< GT, SA >::for_each_centroid_ancestor ( const Node *  node,
F &&  f 
) const
inline

Visit each centroid ancestor of node.

Callback signature: f(centroid_id, distance, index).

Definition at line 1649 of file Tree_Decomposition.H.

Referenced by TYPED_TEST().

◆ for_each_centroid_ancestor_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<class F >
void Aleph::Gen_Centroid_Decomposition< GT, SA >::for_each_centroid_ancestor_id ( const size_t  node,
F &&  f 
) const
inline

Visit each centroid ancestor of node ID.

Callback signature: f(centroid_id, distance, index).

Definition at line 1629 of file Tree_Decomposition.H.

References ah_runtime_error_unless, and chain().

Referenced by main(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().

◆ id_of()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::id_of ( const Node *  node) const
inline

Definition at line 1497 of file Tree_Decomposition.H.

Referenced by main(), TYPED_TEST(), and TYPED_TEST().

◆ init_storage()

◆ is_centroid_ancestor_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
bool Aleph::Gen_Centroid_Decomposition< GT, SA >::is_centroid_ancestor_id ( const size_t  ancestor,
const size_t  node 
) const
inline

True iff ancestor is in the centroid-ancestor chain of node.

Definition at line 1590 of file Tree_Decomposition.H.

References chain().

Referenced by TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().

◆ is_empty()

◆ max_centroid_level()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::max_centroid_level ( ) const
inlinenoexcept

Maximum centroid-tree level.

Definition at line 1542 of file Tree_Decomposition.H.

References Aleph::size().

Referenced by TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().

◆ node_of()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Node * Aleph::Gen_Centroid_Decomposition< GT, SA >::node_of ( const size_t  id) const
inline

Definition at line 1492 of file Tree_Decomposition.H.

Referenced by TYPED_TEST().

◆ operator=() [1/2]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Gen_Centroid_Decomposition & Aleph::Gen_Centroid_Decomposition< GT, SA >::operator= ( const Gen_Centroid_Decomposition< GT, SA > &  other)
default

Copy the centroid tree of another decomposition.

Parameters
[in]otherdecomposition to copy.
Returns
this decomposition.

◆ operator=() [2/2]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Gen_Centroid_Decomposition & Aleph::Gen_Centroid_Decomposition< GT, SA >::operator= ( Gen_Centroid_Decomposition< GT, SA > &&  other)
inlinenoexcept

Exchange this decomposition with another, which is left with the previous centroid tree of this one.

Parameters
[in,out]otherdecomposition to move from.
Returns
this decomposition.

Definition at line 1459 of file Tree_Decomposition.H.

References Aleph::swap().

◆ root()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Node * Aleph::Gen_Centroid_Decomposition< GT, SA >::root ( ) const
inlinenoexcept

Definition at line 1489 of file Tree_Decomposition.H.

◆ root_id()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::root_id ( ) const
inlinenoexcept

Definition at line 1490 of file Tree_Decomposition.H.

◆ size()

◆ swap()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_Centroid_Decomposition< GT, SA >::swap ( Gen_Centroid_Decomposition< GT, SA > &  other)
inlinenoexcept

Exchange in O(1) this decomposition and another.

Parameters
[in,out]otherdecomposition to exchange with.
Exceptions
whatswapping the filters throws. They are exchanged first, so that, if that swap throws, nothing else is exchanged, and both decompositions are left as they were if it left its arguments as they were.

Definition at line 1473 of file Tree_Decomposition.H.

Member Data Documentation

◆ centroid_ancestors_

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Array<Array<size_t> > Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_ancestors_
private

◆ centroid_distances_

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Array<Array<size_t> > Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_distances_
private

◆ centroid_level_

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Array<size_t> Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_level_
private

◆ centroid_parent_

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Array<size_t> Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_parent_
private

◆ centroid_root_

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_root_ = NONE
private

◆ local_parent_

◆ local_subtree_

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Array<size_t> Aleph::Gen_Centroid_Decomposition< GT, SA >::local_subtree_
private

◆ NONE

◆ removed_

◆ topology_


The documentation for this class was generated from the following file: