1 # ifndef TPL_CUT_NODES_H
2 # define TPL_CUT_NODES_H
4 # include <tpl_graph_utils.H>
67 template <
class GT,
class SA = Dft_Show_Arc<GT> >
76 enum State { Init, Cut_Nodes_Computed, Painted } state;
78 void cut_nodes(
typename GT::Node * p,
typename GT::Arc * a)
81 low <GT> (p) = df <GT> (p) = curr_df++;
84 bool p_is_cut_node =
false;
87 typename GT::Arc * arc = i.get_current_arc();
91 typename GT::Node * tgt = i.get_tgt_node();
95 if (df<GT>(tgt) < low<GT>(p))
96 low<GT>(p) = df<GT>(tgt);
104 ARC_BITS(arc).set_bit(Depth_First,
true);
108 if (low<GT>(tgt) < low<GT>(p))
109 low<GT>(p) = low<GT>(tgt);
111 if (low<GT>(tgt) >= df<GT>(p) and df<GT>(tgt) != 0)
112 p_is_cut_node =
true;
150 NODE_BITS(start).set_bit(Depth_First,
true);
151 df <GT> (start) = curr_df++;
153 int call_counter = 0;
157 it.has_curr() and curr_df < gptr->get_num_nodes(); it.next())
159 typename GT::Node * tgt = it.get_tgt_node();
163 typename GT::Arc * arc = it.get_current_arc();
167 ARC_BITS(arc).set_bit(Depth_First,
true);
172 if (call_counter > 1)
178 state = Cut_Nodes_Computed;
183 void paint_subgraph(
typename GT::Node * p)
185 I(not is_a_cut_node <GT> (p));
187 if (is_node_painted <GT> (p))
190 paint_node <GT> (p, curr_color);
194 typename GT::Arc * arc = it.get_current_arc();
195 if (is_arc_painted <GT> (arc))
198 typename GT::Node * tgt = it.get_tgt_node();
199 if (is_a_cut_node <GT> (tgt))
202 paint_arc<GT>(arc, curr_color);
208 void paint_from_cut_node(
typename GT::Node * p)
210 I(is_a_cut_node <GT> (p));
215 typename GT::Arc * arc = it.get_current_arc();
217 I(not is_arc_painted <GT> (arc));
219 typename GT::Node * tgt_node = it.get_tgt_node();
220 if (is_a_cut_node <GT> (tgt_node))
227 paint_arc <GT> (arc, Cross_Arc);
228 if (is_node_painted <GT> (tgt_node))
233 paint_subgraph(tgt_node);
237 I(not is_arc_painted <GT> (arc));
241 typename GT::Node * create_and_map_node(
typename GT::Node * gp,
245 I(get_color<GT>(gp) == color);
248 unique_ptr<typename GT::Node> tp_auto(
new typename GT::Node(gp));
249 sg.insert_node(tp_auto.get());
250 GT::map_nodes(gp, tp_auto.get());
251 NODE_BITS(gp).set_bit(Build_Subtree,
true);
253 return tp_auto.release();
256 void map_subgraph(GT & sg,
typename GT::Node * gsrc,
const long & color)
258 I(get_color <GT> (gsrc) == color);
260 typename GT::Node * tsrc = mapped_node<GT>(gsrc);
265 typename GT::Arc * garc = i.get_current_arc();
266 if (get_color<GT>(garc) != color or
IS_ARC_VISITED(garc, Build_Subtree))
269 ARC_BITS(garc).set_bit(Build_Subtree,
true);
271 typename GT::Node * gtgt = i.get_tgt_node();
273 I(get_color <GT> (gtgt) == color);
275 typename GT::Node * ttgt = NULL;
277 ttgt = mapped_node<GT> (gtgt);
279 ttgt = create_and_map_node(gtgt, color, sg);
281 typename GT::Arc * tarc = sg.insert_arc(tsrc, ttgt, garc->get_info());
282 GT::map_arcs(garc, tarc);
284 map_subgraph(sg, gtgt, color);
298 : sa(__sa), gptr(&g), state(Init)
312 cut_nodes(gptr->get_first_node(), list);
319 cut_nodes(start, list);
344 if (state != Cut_Nodes_Computed)
345 throw std::logic_error(
"Cut nodos has not been computed or the class is"
348 gptr->reset_counter_nodes();
349 gptr->reset_counter_arcs();
354 i.has_curr(); i.next())
355 paint_from_cut_node(i.get_curr());
375 if (state != Painted)
376 throw std::logic_error(
"Graph is not painted");
380 typename GT::Node * first = NULL;
382 for (
typename GT::Node_Iterator it(*gptr); it.has_current(); it.next())
383 if (get_color <GT> (it.get_current_node()) == color)
384 first = it.get_current_node();
387 throw std::domain_error(
"Color does not exist in the graph");
390 create_and_map_node(first, color, sg);
393 map_subgraph (sg, first, color);
423 if (state != Painted)
424 throw std::logic_error(
"Graph is not painted");
430 it.has_curr(); it.next())
432 typename GT::Node * gp = it.get_current();
434 I(is_a_cut_node <GT> (gp));
436 unique_ptr<typename GT::Node> tp_auto(
new typename GT::Node(gp));
437 cut_graph.insert_node(tp_auto.get());
438 GT::map_nodes(gp, tp_auto.release());
445 typename GT::Arc * garc = it.get_current_arc();
446 if (is_a_cross_arc <GT> (garc))
448 cross_arc_list.
append(garc);
452 if (not is_an_cut_arc <GT> (garc))
455 typename GT::Node * src = mapped_node<GT>(gptr->get_src_node(garc));
456 typename GT::Node * tgt = mapped_node<GT>(gptr->get_tgt_node(garc));
458 I(src != NULL and tgt != NULL);
460 typename GT::Arc * arc =
461 cut_graph.insert_arc(src, tgt, garc->get_info());
462 GT::map_arcs(garc, arc);
492 if (state < Cut_Nodes_Computed)
493 throw std::logic_error(
"Cut nodes have not been computed");
495 if (state == Cut_Nodes_Computed)
498 const long & num_colors = curr_color;
506 for (
int i = 0; i < num_colors; ++i)
510 for (
typename GT::Node_Iterator it(*gptr); it.has_curr(); it.next())
512 typename GT::Node * p = it.get_curr();
516 if (is_a_cut_node <GT> (p))
519 const long color = get_color<GT>(p);
521 GT & sg = *blocks.
access(color - 1);
523 create_and_map_node(p, color, sg);
525 map_subgraph(sg, p, color);
534 # endif // TPL_CUT_NODES_H
long paint_subgraphs()
Definition: tpl_cut_nodes.H:342
void reserve(const size_t l, const size_t r)
Definition: tpl_dynArray.H:960
Definition: tpl_graph.H:751
Definition: tpl_graph.H:1389
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:242
void map_subgraph(GT &sg, const long &color)
Definition: tpl_cut_nodes.H:373
void operator()(DynDlist< typename GT::Node * > &list)
Definition: tpl_cut_nodes.H:310
void clear_graph(GT &g)
Definition: tpl_graph.H:2486
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:275
void empty()
Vacía todos los elementos de la lista.
Definition: tpl_dynDlist.H:45
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
Definition: tpl_cut_nodes.H:68
void map_cut_graph(GT &cut_graph, DynDlist< typename GT::Arc * > &cross_arc_list)
Definition: tpl_cut_nodes.H:420
#define NODE_BITS(p)
Definition: aleph-graph.H:221
Compute_Cut_Nodes(GT &g, SA &&__sa=SA())
Definition: tpl_cut_nodes.H:297
void compute_blocks(DynDlist< GT > &block_list, GT &cut_graph, DynDlist< typename GT::Arc * > &cross_arc_list)
Definition: tpl_cut_nodes.H:488
#define ARC_BITS(p)
Definition: aleph-graph.H:266
Definition: tpl_dynArray.H:70
void cut_nodes(typename GT::Node *start, DynDlist< typename GT::Node * > &list)
Definition: tpl_cut_nodes.H:138
T & access(const size_t i)
Definition: tpl_dynArray.H:793
Definition: tpl_graph.H:694
T & append(const T &item)
Definition: tpl_dynDlist.H:106