|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Generic bottom-up tree dynamic programming. More...
#include <Tree_DP.H>
Public Types | |
| using | Node = typename GT::Node |
| Node type. | |
| using | Init_Fn = std::function< T(Node *)> |
| Initialization function signature. | |
| using | Combine_Fn = std::function< T(Node *, const T &, Node *, const T &)> |
| Combine function signature. | |
Public Member Functions | |
| Gen_Tree_DP (const GT &g, Node *root, Init_Fn init, Combine_Fn combine, SA sa=SA()) | |
| Construct and compute bottom-up DP. | |
| const T & | value (Node *node) const |
| Returns the DP value for a given node. | |
| const Array< T > & | values () const noexcept |
| Returns all DP values (indexed by internal node ID). | |
| size_t | size () const noexcept |
| Returns the number of nodes in the tree. | |
| Node * | node_of (size_t id) const |
| Returns the node pointer for a given internal ID. | |
| size_t | id_of (Node *node) const |
| Returns the internal ID for a given node pointer. | |
Private Attributes | |
| tree_dp_detail::Tree_Topology< GT, SA > | topo_ |
| Tree topology and order. | |
| Array< T > | dp_ |
| Computed DP values. | |
Generic bottom-up tree dynamic programming.
This class computes a DP value for every node in a rooted tree by combining the results of its children in post-order traversal.
The user defines the logic by providing:
Init_Fn to set the base value for each node.Combine_Fn to merge a child's result into the parent's accumulator.| GT | Graph type. |
| T | Value type computed at each node. |
| SA | Arc filter (default Dft_Show_Arc). |
|
inline |
Construct and compute bottom-up DP.
| [in] | g | The graph (must be a tree under filter SA). |
| [in] | root | Root node. |
| [in] | init | Initialization function for each node. |
| [in] | combine | Combine function to fold children. |
| [in] | sa | Arc filter. |
Definition at line 369 of file Tree_DP.H.
References Aleph::Array< T >::create(), Aleph::Gen_Tree_DP< GT, T, SA >::dp_, Aleph::init, k, and Aleph::Gen_Tree_DP< GT, T, SA >::topo_.
|
inline |
Returns the internal ID for a given node pointer.
| [in] | node | Node pointer. |
Definition at line 428 of file Tree_DP.H.
References Aleph::Gen_Tree_DP< GT, T, SA >::topo_.
Referenced by TEST().
|
inline |
Returns the node pointer for a given internal ID.
| [in] | id | Internal node ID. |
Definition at line 419 of file Tree_DP.H.
References Aleph::Gen_Tree_DP< GT, T, SA >::topo_.
|
inlinenoexcept |
Returns the number of nodes in the tree.
Definition at line 410 of file Tree_DP.H.
References Aleph::Gen_Tree_DP< GT, T, SA >::topo_.
Returns the DP value for a given node.
| [in] | node | Node pointer. |
Definition at line 398 of file Tree_DP.H.
References Aleph::Gen_Tree_DP< GT, T, SA >::dp_, and Aleph::Gen_Tree_DP< GT, T, SA >::topo_.
Referenced by main().
Returns all DP values (indexed by internal node ID).
Definition at line 404 of file Tree_DP.H.
References Aleph::Gen_Tree_DP< GT, T, SA >::dp_.
Referenced by Aleph::tree_subtree_sizes().
|
private |
Computed DP values.
Definition at line 358 of file Tree_DP.H.
Referenced by Aleph::Gen_Tree_DP< GT, T, SA >::Gen_Tree_DP(), Aleph::Gen_Tree_DP< GT, T, SA >::value(), and Aleph::Gen_Tree_DP< GT, T, SA >::values().
|
private |
Tree topology and order.
Definition at line 357 of file Tree_DP.H.
Referenced by Aleph::Gen_Tree_DP< GT, T, SA >::Gen_Tree_DP(), Aleph::Gen_Tree_DP< GT, T, SA >::id_of(), Aleph::Gen_Tree_DP< GT, T, SA >::node_of(), Aleph::Gen_Tree_DP< GT, T, SA >::size(), and Aleph::Gen_Tree_DP< GT, T, SA >::value().