43# ifndef GENERATE_TREE_H
44# define GENERATE_TREE_H
89 return to_str(p->get_key());
100 template <
typename Node,
class Write>
104 const size_t & current_level,
109 <<
"Allocated size for deway array has been exceeded";
113 for (
size_t i = 0; i < current_level; ++i)
117 if (i < current_level - 1)
120 output <<
" \"" <<
Write()(node) <<
"\" " << std::endl;
122 Node *child =
static_cast<Node *
>(node->get_left_child());
123 for (
int i = 0; child !=
nullptr;
124 i++, child =
static_cast<Node *
>(child->get_right_sibling()))
126 deway[current_level + 1] = i;
158 template <
typename Node,
class Write = Dft_Write<Node>>
163 out <<
"Root \"" <<
Write()(
root) <<
"\" " << std::endl;
167 constexpr int level = 0;
171 Node *child =
static_cast<Node *
>(
root->get_left_child());
172 for (
int i = 0; child !=
nullptr;
173 i++, child =
static_cast<Node *
>(child->get_right_sibling()))
204 template <
typename Node,
class Write = Dft_Write<Node>>
209 for (
int i = 0; tree !=
nullptr; i++, tree = tree->get_right_sibling())
237 template <
typename Node,
class Write>
240 out <<
"start-prefix ";
264 template <
typename Node,
class Write = Dft_Write<Node>>
267 out <<
"digraph Tree {" << std::endl;
268 out <<
" node [shape=circle, fontname=\"Helvetica\"];" << std::endl;
269 out <<
" edge [fontname=\"Helvetica\"];" << std::endl;
273 out <<
"}" << std::endl;
281 out <<
" \"" << p <<
"\" [label=\""
284 for (
typename Node::Children_Iterator it(p); it.has_curr(); it.next())
286 Node * child = it.get_curr();
287 out <<
" \"" << p <<
"\" -> \"" << child <<
"\";" << std::endl;
293 out <<
"}" << std::endl;
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
WeightedDigraph::Node Node
void deway(Tree_Node< int > *p, int prefix[], const int &len, const size_t &dim)
Recursively compute and print Deway numbering for a tree node.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
void generate_btree(Node *root, std::ostream &out)
Generate a binary tree specification for the btreepic drawing tool.
void generate_forest(Node *root, std::ostream &out)
Generate a forest specification for the ntreepic drawing tool.
void generate_tree(Node *root, std::ostream &out, const int &tree_number=0)
Generate a tree specification for the ntreepic drawing tool.
void generate_tree_graphviz(Node *root, std::ostream &out)
Generate a Graphviz DOT specification for a tree.
Main namespace for Aleph-w library functions.
constexpr size_t Max_Tree_Node_Depth
size_t size(Node *root) noexcept
bool traverse(Node *root, Op op)
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::string escape_dot_label(const std::string &text)
std::string to_str(const double d)
Convert double to a std::string with maximum round-trip precision.
static void __generate_tree(Node *node, int deway[], const size_t ¤t_level, const size_t &size, std::ostream &output)
std::string operator()(Node *p)
Utility functions for binary tree operations.
General tree (n-ary tree) node.