Aleph-w  1.5a.2
Biblioteca general de algoritmos y estructuras de datos
 Todo Clases Archivos Funciones Variables 'typedefs' Enumeraciones Amigas Grupos Páginas
generate_df_tree.H
1 
2 # include <tpl_graph_utils.H>
3 # include <tpl_tree_node.H>
4 # include <generate_tree.H>
5 
6 
7 static long global_counter = 0;
8 
9 
10 struct Clave
11 {
12  int key;
13  long count;
14  long low;
15 };
16 
17 
19 {
20  const bool operator () (const Clave & c1, const Clave & c2) const
21  {
22  return c1.key == c2.key;
23  }
24 };
25 
26 
27 struct Convertir
28 {
29  void operator () (Grafo::Node * tnode, Tree_Node<Clave> * t)
30  {
31  Grafo::Node * gnode = static_cast<Grafo::Node *>(NODE_COOKIE(tnode));
32 
33  Clave & clave = t->get_key();
34  clave.key = tnode->get_info().clave;
35  clave.count = gnode->get_info().df;
36  clave.low = gnode->get_info().low;
37  }
38 };
39 
40 
41 struct Write_Node
42 {
43  static const size_t Buf_Size = 512;
44 
45  const string operator () (Tree_Node<Clave> * p)
46  {
47  char str[2];
48 
49  str[0] = p->get_key().key;
50  str[1] = '\0';
51  return string(str);
52  }
53 };
54 
55 struct Write_Df
56 {
57  static const size_t Buf_Size = 512;
58 
59  const string operator () (Tree_Node<Clave> * p)
60  {
61  char buf[Buf_Size];
62 
63  snprintf(buf, Buf_Size, "(%c,%ld)", p->get_key().key, p->get_key().count);
64 
65  return string(buf);
66  }
67 };
68 
69 struct Write_Low
70 {
71  static const size_t Buf_Size = 512;
72 
73  const string operator () (Tree_Node<Clave> * p)
74  {
75  char buf[Buf_Size];
76 
77  if (p->get_key().low >= 0)
78  snprintf(buf, Buf_Size, "%d,%ld,%ld",
79  p->get_key().key, p->get_key().count, p->get_key().low);
80  else
81  snprintf(buf, Buf_Size, "%d,%ld,-",
82  p->get_key().key, p->get_key().count);
83 
84  return string(buf);
85  }
86 };
87 
88 
89 
90 void visitar_df(Grafo &, Grafo::Node * nodo, Grafo::Arc *)
91 {
92  nodo->get_info().df = global_counter++;
93 }
94 
95 void visitar_low(Grafo &, Grafo::Node * nodo, Grafo::Arc *)
96 {
97  nodo->get_info().low = (long) (nodo->cookie);
98 }
99 
100 
101  template <class GT, class Key>
102 void write_df_low_tree(GT & g, typename GT::Node * src, ofstream & f)
103 {
104  // calcular puntos de corte
106  compute_cut_nodes(g, node_list);
107 
108  depth_first_traversal(g, src, &visitar_df); // copiar df
109 
110  depth_first_traversal(g, src, &visitar_low); // copiar low
111 
112  Grafo tree; // árbol abarcador
113 
114  // calcular árbol abarcador en profundidad
115  find_depth_first_spanning_tree <GT> (g, src, tree);
116 
117  // calcular arcos no abarcadores
118  DynDlist<No_Tree_Arc> arc_list;
119  generate_non_tree_arcs(g, arc_list);
120 
121  typename GT::Node * td = static_cast<typename GT::Node *>(NODE_COOKIE(src));
122 
123  Tree_Node<Key> * rd = Graph_To_Tree_Node () <Grafo, Key, Convertir>(tree, td);
124 
125  generate_tree <Tree_Node<Key>, Write_Low> (rd, f);
126 
127  write_non_tree_arcs(arc_list, rd, f);
128 }
129 
Definition: generate_df_tree.H:55
Definition: generate_df_tree.H:69
#define NODE_COOKIE(p)
Definition: aleph-graph.H:248
size_t depth_first_traversal(GT &g, typename GT::Node *start_node, bool(*visit)(GT &g, typename GT::Node *, typename GT::Arc *), SA sa=SA())
Definition: tpl_graph_utils.H:66
Definition: generate_df_tree.H:41
Definition: tpl_tree_node.H:35
Definition: graph_to_tree.H:170
T & get_key()
retorna referencia modificable al contenido del nodo.
Definition: tpl_tree_node.H:76
void compute_cut_nodes(GT &g, typename GT::Node *start, DynDlist< typename GT::Node * > &list)
Definition: tpl_graph_utils.H:1638
Definition: generate_df_tree.H:10
Definition: generate_df_tree.H:27
Definition: generate_df_tree.H:18

Leandro Rabindranath León