Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
generate_df_tree.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
63#ifndef GENERATE_DF_TREE_H
64#define GENERATE_DF_TREE_H
65
66# include <ah-graph-concepts.H>
67
68#include <tpl_graph_utils.H>
69#include <tpl_tree_node.H>
70#include <generate_tree.H>
71
73static long global_counter = 0;
74
80struct Clave
81{
82 int key;
83 long count;
84 long low;
85};
86
92{
93 bool operator () (const Clave & c1, const Clave & c2) const
94 {
95 return c1.key == c2.key;
96 }
97};
98
105{
107 {
108 Grafo::Node * gnode = static_cast<Grafo::Node *>(NODE_COOKIE(tnode));
109
110 Clave & clave = t->get_key();
111 clave.key = tnode->get_info().clave;
112 clave.count = gnode->get_info().df;
113 clave.low = gnode->get_info().low;
114 }
115};
116
122{
123 static const size_t Buf_Size = 512;
124
126 {
127 char str[2];
128 str[0] = p->get_key().key;
129 str[1] = '\0';
130 return std::string(str);
131 }
132};
133
140{
141 static const size_t Buf_Size = 512;
142
144 {
145 char buf[Buf_Size];
146 snprintf(buf, Buf_Size, "(%c,%ld)", p->get_key().key, p->get_key().count);
147 return std::string(buf);
148 }
149};
150
158{
159 static const size_t Buf_Size = 512;
160
162 {
163 char buf[Buf_Size];
164
165 if (p->get_key().low >= 0)
166 snprintf(buf, Buf_Size, "%d,%ld,%ld",
167 p->get_key().key, p->get_key().count, p->get_key().low);
168 else
169 snprintf(buf, Buf_Size, "%d,%ld,-",
170 p->get_key().key, p->get_key().count);
171
172 return std::string(buf);
173 }
174};
175
182{
183 nodo->get_info().df = global_counter++;
184}
185
191{
192 nodo->get_info().low = reinterpret_cast<long>(nodo->cookie);
193}
194
195
219template <AlephGraph GT, class Key>
220void write_df_low_tree(GT & g, typename GT::Node * src, std::ofstream & f)
221{
222 // Compute cut nodes (articulation points)
224
225 depth_first_traversal(g, src, &visitar_df); // Copy df numbers
226 depth_first_traversal(g, src, &visitar_low); // Copy low-link values
227
229
230 // Compute non-tree arcs (back edges)
231 DynDlist<No_Tree_Arc> arc_list;
232 generate_non_tree_arcs(g, arc_list);
233
234 typename GT::Node * td = static_cast<typename GT::Node *>(NODE_COOKIE(src));
235
236 Tree_Node<Key> * rd = Graph_To_Tree_Node () <Grafo, Key, Convertir>(tree, td);
237
239
240 write_non_tree_arcs(arc_list, rd, f);
241}
242
243#endif // GENERATE_DF_TREE_H
C++20 concepts for the protocol shared by graph algorithms.
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:3960
typename BaseGraph::Arc Arc
Definition graph-dry.H:3964
typename BaseGraph::Node Node
Definition graph-dry.H:3963
Dynamic doubly linked list with O(1) size and bidirectional access.
Functor class to convert a tree graph to Tree_Node structure.
Forward declaration used by CRTP helpers before the full node definition.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
static long global_counter
void visitar_df(Grafo &, Grafo::Node *nodo, Grafo::Arc *)
DFS visitor that assigns discovery numbers.
void visitar_low(Grafo &, Grafo::Node *nodo, Grafo::Arc *)
DFS visitor that copies low-link values from cookies.
Tree visualization and output generation.
size_t depth_first_traversal(const GT &g, typename GT::Node *start_node, bool(*visit)(const GT &g, typename GT::Node *, typename GT::Arc *))
Depth-first traversal starting from a given node.
void write_df_low_tree(GT &g, typename GT::Node *src, std::ofstream &f)
Generate a DFS tree picture with low-link values.
DynList< typename GT::Node * > compute_cut_nodes(const GT &g, typename GT::Node *start)
Compute articulation points (cut vertices) of an undirected graph.
#define NODE_COOKIE(p)
Return the node cookie
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
GT find_depth_first_spanning_tree(const GT &g, typename GT::Node *gnode)
Build a depth-first spanning tree (mapped to the original graph).
Equality comparator for Clave structures.
bool operator()(const Clave &c1, const Clave &c2) const
Key structure for DFS tree nodes.
int key
Original node identifier.
long count
DFS discovery number (pre-order)
long low
Low-link value (minimum reachable via back edges)
Converter from graph node to Tree_Node<Clave>.
void operator()(Grafo::Node *tnode, Tree_Node< Clave > *t)
Writer that outputs node key and DFS number.
static const size_t Buf_Size
std::string operator()(Tree_Node< Clave > *p)
Writer that outputs node key, DFS number, and low-link value.
std::string operator()(Tree_Node< Clave > *p)
static const size_t Buf_Size
Writer that outputs only the node key.
std::string operator()(Tree_Node< Clave > *p)
static const size_t Buf_Size
Utility algorithms and operations for graphs.
General tree (n-ary tree) node.
List_Digraph< Node_Nodo, Arco_Arco > Grafo