Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
graph_to_tree.H File Reference

Convert spanning tree graphs to Tree_Node structures. More...

#include <memory>
#include <ah-graph-concepts.H>
#include <tpl_tree_node.H>
#include <tpl_dfs_stack.H>
#include <tpl_graph.H>
#include <tpl_graph_utils.H>
#include <tpl_test_acyclique.H>
#include <ah-errors.H>
Include dependency graph for graph_to_tree.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::graph_to_tree_detail::Frame< GT, Key, SA >
 A node of the tree being built that waits for the one that it visits, its image in the tree, the arc through which it was reached and the next arc of it to look at. More...
 
class  Aleph::Graph_To_Tree_Node< GT, Key, Convert, SA >
 Functor class to convert a tree graph to Tree_Node structure. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::graph_to_tree_detail
 

Functions

template<class GT , typename Key , class SA , class Convert , class... Args>
void Aleph::graph_to_tree_detail::build (Tree_Node< Key > *troot, Convert &&convert, typename GT::Node *groot, Args &&... args)
 
template<AlephGraph GT, typename Key , typename Convert , ArcFilter< GT > SA>
static void Aleph::__graph_to_tree_node (GT &g, typename GT::Node *groot, Tree_Node< Key > *troot, const SA &sa)
 
template<AlephGraph GT, typename Key , class Convert , ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Tree_Node< Key > * Aleph::graph_to_tree_node (GT &g, typename GT::Node *groot, SA sa=SA())
 Convert a tree graph to a Tree_Node structure.
 

Detailed Description

Convert spanning tree graphs to Tree_Node structures.

This file provides utilities for converting spanning trees represented as adjacency-list graphs into Tree_Node<Key> structures, enabling the use of tree-specific algorithms and visualization tools.

Purpose

While spanning trees can be represented using graph structures like List_Graph, the Tree_Node representation offers advantages for:

  • Tree drawing and visualization (e.g., with ntreepic)
  • Tree-specific traversal algorithms
  • Simpler recursive tree operations

Key Limitations

Tree_Node<Key> is less versatile than graph representations:

  • No storage for arc/edge data (only node data)
  • Key type may differ from the graph's node type
  • Requires a Convert class to map graph nodes to tree keys
Example: Converting graph to DFS tree
using GT = List_Graph<Graph_Node<string>, Graph_Arc<int>>;
GT g;
auto a = g.insert_node("A");
auto b = g.insert_node("B");
auto c = g.insert_node("C");
g.insert_arc(a, b);
g.insert_arc(a, c);
// Define converter from graph node to tree node
struct CopyInfo {
void operator()(GT::Node* gnode, Tree_Node<string>* tnode) {
tnode->get_key() = gnode->get_info();
}
};
Tree_Node<string> tree_root;
DynMapTree<GT::Node*, Tree_Node<string>*> node_map;
build_tree_dfs<GT, Tree_Node<string>, CopyInfo>(g, a, tree_root, node_map);
// tree_root now contains the DFS spanning tree
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:535
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:618
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
Definition graph-dry.H:753
Example: BFS tree with node mapping
build_tree_bfs<GT, Tree_Node<string>, CopyInfo>(g, a, tree_root, node_map);
// Use mapping to find tree node from graph node
auto tree_node = node_map[b]; // Get tree node for graph node b
See also
Tree_Node For the target tree structure
generate_tree.H For tree visualization
tpl_spanning_tree.H For spanning tree algorithms
Author
Leandro Rabindranath León

Definition in file graph_to_tree.H.