|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Generic bottom-up tree DP. More...
#include <Tree_DP.H>
Public Types | |
| using | Node = typename GT::Node |
| Node type. | |
| using | Init_Fn = std::function< T(Node *)> |
| Initialization function: maps a leaf/node to its base value. | |
| using | Combine_Fn = std::function< T(Node *, const T &, Node *, const T &)> |
| Combine function: folds a child's value into the accumulator. | |
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 DP.
Computes a value for each node by combining children's values in post-order.
| GT | Graph type. |
| T | Value type computed at each node. |
| SA | Arc filter (default Dft_Show_Arc). |
| using Aleph::Gen_Tree_DP< GT, T, SA >::Combine_Fn = std::function<T(Node *, const T &, Node *, const T &)> |
Combine function: folds a child's value into the accumulator.
Parameters: (parent_node, accumulated_value, child_node, child_dp_value) Returns: new accumulated value.
|
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 360 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 421 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 412 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 403 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 391 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 397 of file Tree_DP.H.
References Aleph::Gen_Tree_DP< GT, T, SA >::dp_.
Referenced by Aleph::tree_subtree_sizes().
Computed DP values.
Definition at line 349 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 348 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().