|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Centroid decomposition over a rooted tree represented as an Aleph graph. More...
#include <Tree_Decomposition.H>
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 |
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)
| GT | Graph type. |
| SA | Arc filter type. |
Definition at line 1195 of file Tree_Decomposition.H.
| using Aleph::Gen_Centroid_Decomposition< GT, SA >::Node = typename GT::Node |
Definition at line 1198 of file Tree_Decomposition.H.
|
private |
Definition at line 1201 of file Tree_Decomposition.H.
|
inline |
Construct using an explicit root node.
Definition at line 1409 of file Tree_Decomposition.H.
|
inline |
Construct using the first graph node as root.
Definition at line 1416 of file Tree_Decomposition.H.
|
default |
Copy the centroid tree of another decomposition.
| [in] | other | decomposition to copy. |
|
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.
| [in,out] | other | decomposition to move from. |
Definition at line 1436 of file Tree_Decomposition.H.
|
inlineprivate |
Definition at line 1330 of file Tree_Decomposition.H.
References Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::adjacency(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_ancestors_, Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_distances_, Aleph::DynListStack< T >::is_empty(), Aleph::Gen_Centroid_Decomposition< GT, SA >::NONE, Aleph::DynListStack< T >::pop(), Aleph::DynListStack< T >::push(), Aleph::Gen_Centroid_Decomposition< GT, SA >::removed_, and Aleph::Gen_Centroid_Decomposition< GT, SA >::topology_.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree().
|
inlineprivate |
Definition at line 1359 of file Tree_Decomposition.H.
References Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::adjacency(), Aleph::Gen_Centroid_Decomposition< GT, SA >::append_centroid_annotations(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_level_, Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_parent_, Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_root_, Aleph::Gen_Centroid_Decomposition< GT, SA >::choose_centroid(), Aleph::Gen_Centroid_Decomposition< GT, SA >::collect_component_nodes(), Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage(), Aleph::DynListStack< T >::is_empty(), nodes, Aleph::Gen_Centroid_Decomposition< GT, SA >::NONE, Aleph::DynListStack< T >::pop(), Aleph::DynListStack< T >::push(), Aleph::Gen_Centroid_Decomposition< GT, SA >::removed_, Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::root_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::size(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::topology_.
|
inline |
Centroid ancestors of node from centroid root down to local centroid.
Definition at line 1578 of file Tree_Decomposition.H.
|
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().
|
inline |
Distances to centroid ancestors (aligned with centroid_ancestors_of).
Definition at line 1584 of file Tree_Decomposition.H.
|
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().
|
inline |
Level of centroid node in centroid tree (root level = 0).
Definition at line 1536 of file Tree_Decomposition.H.
|
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().
|
inline |
Parent centroid of node (or nullptr if centroid root).
Definition at line 1522 of file Tree_Decomposition.H.
Referenced by TYPED_TEST().
|
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().
|
inline |
Number of centroid ancestors stored for node.
Definition at line 1558 of file Tree_Decomposition.H.
|
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().
|
inlinenoexcept |
Root centroid node of the centroid tree (or nullptr if empty).
Definition at line 1509 of file Tree_Decomposition.H.
Referenced by Moved_From_Case< Centroid_Decomposition< Graph > >::is_empty(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().
|
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().
|
inlineprivate |
Definition at line 1280 of file Tree_Decomposition.H.
References Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::adjacency(), ah_runtime_error_unless, Aleph::Gen_Centroid_Decomposition< GT, SA >::local_parent_, Aleph::Gen_Centroid_Decomposition< GT, SA >::local_subtree_, nodes, Aleph::Gen_Centroid_Decomposition< GT, SA >::removed_, Aleph::Gen_Centroid_Decomposition< GT, SA >::size(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::topology_.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree().
|
inlineprivate |
Definition at line 1250 of file Tree_Decomposition.H.
References Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::adjacency(), Aleph::DynListStack< T >::is_empty(), Aleph::Gen_Centroid_Decomposition< GT, SA >::local_parent_, nodes, Aleph::Gen_Centroid_Decomposition< GT, SA >::NONE, Aleph::DynListStack< T >::pop(), Aleph::DynListStack< T >::push(), Aleph::Gen_Centroid_Decomposition< GT, SA >::removed_, Aleph::Gen_Centroid_Decomposition< GT, SA >::size(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::topology_.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree().
|
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().
|
inlineprivate |
Definition at line 1217 of file Tree_Decomposition.H.
References ah_domain_error_if, and Aleph::Gen_Centroid_Decomposition< GT, SA >::is_empty().
|
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().
|
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().
|
inline |
Definition at line 1497 of file Tree_Decomposition.H.
Referenced by main(), TYPED_TEST(), and TYPED_TEST().
|
inlineprivate |
Definition at line 1222 of file Tree_Decomposition.H.
References Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_ancestors_, Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_distances_, Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_level_, Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_parent_, Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_root_, Aleph::Array< T >::create(), Aleph::Gen_Centroid_Decomposition< GT, SA >::is_empty(), Aleph::Gen_Centroid_Decomposition< GT, SA >::local_parent_, Aleph::Gen_Centroid_Decomposition< GT, SA >::local_subtree_, Aleph::Gen_Centroid_Decomposition< GT, SA >::NONE, Aleph::Gen_Centroid_Decomposition< GT, SA >::removed_, and Aleph::Gen_Centroid_Decomposition< GT, SA >::size().
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree().
|
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().
|
inlinenoexcept |
Definition at line 1487 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::ensure_not_empty(), Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage(), Moved_From_Case< Centroid_Decomposition< Graph > >::is_empty(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().
|
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().
|
inline |
Definition at line 1492 of file Tree_Decomposition.H.
Referenced by TYPED_TEST().
|
default |
Copy the centroid tree of another decomposition.
| [in] | other | decomposition to copy. |
|
inlinenoexcept |
Exchange this decomposition with another, which is left with the previous centroid tree of this one.
| [in,out] | other | decomposition to move from. |
Definition at line 1459 of file Tree_Decomposition.H.
References Aleph::swap().
|
inlinenoexcept |
Definition at line 1489 of file Tree_Decomposition.H.
|
inlinenoexcept |
Definition at line 1490 of file Tree_Decomposition.H.
|
inlinenoexcept |
Definition at line 1486 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree(), Aleph::Gen_Centroid_Decomposition< GT, SA >::choose_centroid(), Aleph::Gen_Centroid_Decomposition< GT, SA >::collect_component_nodes(), Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage(), Moved_From_Case< Centroid_Decomposition< Graph > >::is_empty(), main(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< Centroid_Decomposition< Graph > >::use().
|
inlinenoexcept |
Exchange in O(1) this decomposition and another.
| [in,out] | other | decomposition to exchange with. |
| what | swapping 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.
|
private |
Definition at line 1214 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::append_centroid_annotations(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage().
|
private |
Definition at line 1215 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::append_centroid_annotations(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage().
|
private |
Definition at line 1208 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage().
|
private |
Definition at line 1207 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage().
|
private |
Definition at line 1209 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage().
|
private |
|
private |
Definition at line 1212 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::choose_centroid(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage().
|
staticconstexprprivate |
Definition at line 1202 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::append_centroid_annotations(), Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree(), Aleph::Gen_Centroid_Decomposition< GT, SA >::collect_component_nodes(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage().
|
private |
Definition at line 1206 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::append_centroid_annotations(), Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree(), Aleph::Gen_Centroid_Decomposition< GT, SA >::choose_centroid(), Aleph::Gen_Centroid_Decomposition< GT, SA >::collect_component_nodes(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::init_storage().
|
private |
Definition at line 1204 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Centroid_Decomposition< GT, SA >::append_centroid_annotations(), Aleph::Gen_Centroid_Decomposition< GT, SA >::build_centroid_tree(), Aleph::Gen_Centroid_Decomposition< GT, SA >::choose_centroid(), and Aleph::Gen_Centroid_Decomposition< GT, SA >::collect_component_nodes().