27 # ifndef TPL_CUT_NODES_H 28 # define TPL_CUT_NODES_H 30 # include <tpl_graph_utils.H> 93 template <
class GT,
class SA = Dft_Show_Arc<GT> >
102 enum State { Init, Cut_Nodes_Computed, Painted } state;
104 void cut_nodes(
typename GT::Node * p,
typename GT::Arc * a)
107 low <GT> (p) = df <GT> (p) = curr_df++;
110 bool p_is_cut_node =
false;
113 auto arc = i.get_curr_ne();
117 auto tgt = i.get_tgt_node();
121 low<GT>(p) = std::min(df<GT>(tgt), low<GT>(p));
128 ARC_BITS(arc).set_bit(Depth_First,
true);
131 low<GT>(p) = std::min(low<GT>(tgt), low<GT>(p));
132 if (low<GT>(tgt) >= df<GT>(p) and df<GT>(tgt) != 0)
133 p_is_cut_node =
true;
167 gptr->for_each_node([] (
auto p)
175 NODE_BITS(start).set_bit(Depth_First,
true);
176 df <GT> (start) = curr_df++;
178 int call_counter = 0;
182 it.has_curr() and curr_df < gptr->get_num_nodes(); it.next_ne())
184 auto tgt = it.get_tgt_node();
188 auto arc = it.get_curr_ne();
192 ARC_BITS(arc).set_bit(Depth_First,
true);
197 if (call_counter > 1)
203 state = Cut_Nodes_Computed;
208 void paint_subgraph(
typename GT::Node * p)
210 assert(not is_a_cut_node <GT> (p));
212 if (is_node_painted <GT> (p))
215 paint_node <GT> (p, curr_color);
219 auto arc = it.get_curr_ne();
220 if (is_arc_painted <GT> (arc))
223 auto tgt = it.get_tgt_node();
224 if (is_a_cut_node <GT> (tgt))
227 paint_arc<GT>(arc, curr_color);
232 void paint_from_cut_node(
typename GT::Node * p)
234 assert(is_a_cut_node <GT> (p));
239 auto arc = it.get_curr_ne();
241 assert(not is_arc_painted <GT> (arc));
243 auto tgt_node = it.get_tgt_node();
244 if (is_a_cut_node <GT> (tgt_node))
251 paint_arc <GT> (arc, Cross_Arc);
252 if (is_node_painted <GT> (tgt_node))
257 paint_subgraph(tgt_node);
261 assert(not is_arc_painted <GT> (arc));
265 typename GT::Node * create_and_map_node(
typename GT::Node * gp,
269 assert(get_color<GT>(gp) == color);
272 unique_ptr<typename GT::Node> tp_auto(
new typename GT::Node(gp));
273 sg.insert_node(tp_auto.get());
275 NODE_BITS(gp).set_bit(Build_Subtree,
true);
277 return tp_auto.release();
280 void map_subgraph(GT & sg,
typename GT::Node * gsrc,
const long & color)
282 assert(get_color <GT> (gsrc) == color);
284 auto tsrc = mapped_node<GT>(gsrc);
289 auto garc = i.get_curr_ne();
290 if (get_color<GT>(garc) != color or
IS_ARC_VISITED(garc, Build_Subtree))
293 ARC_BITS(garc).set_bit(Build_Subtree,
true);
295 auto gtgt = i.get_tgt_node();
297 assert(get_color <GT> (gtgt) == color);
299 typename GT::Node * ttgt =
nullptr;
301 ttgt = mapped_node<GT> (gtgt);
303 ttgt = create_and_map_node(gtgt, color, sg);
305 auto tarc = sg.insert_arc(tsrc, ttgt, garc->get_info());
308 map_subgraph(sg, gtgt, color);
322 : sa(__sa), gptr(&const_cast<GT&>(g)), state(Init)
330 cut_nodes(gptr->get_first_node(), list);
337 cut_nodes(start, list);
362 if (state != Cut_Nodes_Computed)
363 throw std::logic_error(
"Cut nodos has not been computed or the class is" 366 gptr->reset_counter_nodes();
367 gptr->reset_counter_arcs();
373 paint_from_cut_node(i.get_curr_ne());
393 if (state != Painted)
394 throw std::logic_error(
"Graph is not painted");
398 typename GT::Node * first =
nullptr;
400 for (
typename GT::Node_Iterator it(*gptr); it.has_curr(); it.next_ne())
401 if (get_color <GT> (it.get_curr_ne()) == color)
402 first = it.get_curr_ne();
404 if (first ==
nullptr)
405 throw std::domain_error(
"Color does not exist in the graph");
408 create_and_map_node(first, color, sg);
411 map_subgraph (sg, first, color);
441 if (state != Painted)
442 throw std::logic_error(
"Graph is not painted");
450 auto gp = it.get_curr_ne();
452 assert(is_a_cut_node <GT> (gp));
454 unique_ptr<typename GT::Node> tp_auto(
new typename GT::Node(gp));
455 cut_graph.insert_node(tp_auto.get());
463 auto garc = it.get_curr_ne();
464 if (is_a_cross_arc <GT> (garc))
466 cross_arc_list.
append(garc);
470 if (not is_an_cut_arc <GT> (garc))
473 typename GT::Node * src = mapped_node<GT>(gptr->get_src_node(garc));
474 typename GT::Node * tgt = mapped_node<GT>(gptr->get_tgt_node(garc));
476 assert(src !=
nullptr and tgt !=
nullptr);
478 typename GT::Arc * arc =
479 cut_graph.insert_arc(src, tgt, garc->get_info());
510 if (state < Cut_Nodes_Computed)
511 throw std::logic_error(
"Cut nodes have not been computed");
513 if (state == Cut_Nodes_Computed)
516 const long & num_colors = curr_color;
524 for (
int i = 0; i < num_colors; ++i)
528 for (
typename GT::Node_Iterator it(*gptr); it.has_curr(); it.next_ne())
530 auto p = it.get_curr_ne();
534 if (is_a_cut_node <GT> (p))
537 const long color = get_color<GT>(p);
539 GT & sg = *blocks.
access(color - 1);
541 create_and_map_node(p, color, sg);
543 map_subgraph(sg, p, color);
552 # endif // TPL_CUT_NODES_H long paint_subgraphs()
Definition: tpl_cut_nodes.H:360
void reserve(const size_t l, const size_t r)
Definition: tpl_dynArray.H:998
void clear_graph(GT &g) noexcept
Definition: tpl_graph.H:3463
Definition: tpl_graph.H:1225
bool has_curr() const noexcept
Return true if the iterator has current item.
Definition: dlink.H:658
Definition: tpl_dynDlist.H:51
T & access(const size_t i) const noexcept
Definition: tpl_dynArray.H:874
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:327
void map_subgraph(GT &sg, const long &color)
Definition: tpl_cut_nodes.H:391
void map_cut_graph(GT &cut_graph, DynDlist< typename GT::Arc *> &cross_arc_list)
Definition: tpl_cut_nodes.H:438
void cut_nodes(typename GT::Node *start, DynDlist< typename GT::Node *> &list)
Definition: tpl_cut_nodes.H:159
void operator()(DynDlist< typename GT::Node *> &list)
Definition: tpl_cut_nodes.H:328
#define NODE_COUNTER(p)
Definition: aleph-graph.H:311
Compute_Cut_Nodes(const GT &g, SA __sa=SA())
Definition: tpl_cut_nodes.H:321
void map_arcs(typename GTS::Arc *p, typename GTT::Arc *q) noexcept
Definition: tpl_graph.H:3445
Definition: tpl_dynDlist.H:413
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:360
void map_nodes(typename GTS::Node *p, typename GTT::Node *q) noexcept
Definition: tpl_graph.H:3419
Definition: tpl_cut_nodes.H:94
#define NODE_BITS(p)
Definition: aleph-graph.H:305
void empty() noexcept
Empty the list.
Definition: tpl_dynDlist.H:90
#define ARC_BITS(p)
Definition: aleph-graph.H:351
Definition: tpl_dynArray.H:159
void compute_blocks(DynDlist< GT > &block_list, GT &cut_graph, DynDlist< typename GT::Arc *> &cross_arc_list)
Definition: tpl_cut_nodes.H:506
Definition: tpl_graph.H:1177
T & append(const T &item)
Definition: tpl_dynDlist.H:149