27 # ifndef TPL_SPANNING_TREE_H 28 # define TPL_SPANNING_TREE_H 30 # include <tpl_graph.H> 53 template <
class GT,
class SA = Dft_Show_Arc<GT> >
60 bool build_tree(
typename GT::Node * gnode,
typename GT::Arc * garc,
61 typename GT::Node * tnode)
63 NODE_BITS(gnode).set_bit(Spanning_Tree,
true);
64 ARC_BITS(garc).set_bit(Spanning_Tree,
true);
66 auto tree_tgt_node = tptr->insert_node(gnode->get_info());
69 auto tarc = tptr->insert_arc(tnode, tree_tgt_node, garc->get_info());
72 tnode = tree_tgt_node;
73 if (tptr->get_num_nodes() == gptr->get_num_nodes())
76 assert(tptr->get_num_nodes() > tptr->get_num_arcs());
79 i.has_curr() and tptr->get_num_nodes() < gptr->get_num_nodes();
82 auto arc = i.get_current_arc_ne();
86 auto arc_tgt_node = i.get_tgt_node();
90 if (build_tree(arc_tgt_node, arc, tnode))
97 bool build_tree(GT & g,
typename GT::Node * gnode, GT & tree)
107 NODE_BITS(gnode).set_bit(Spanning_Tree,
true);
109 auto tnode = tree.insert_node(gnode->get_info());
113 i.has_curr() and tptr->get_num_nodes() < gptr->get_num_nodes();
116 auto arc = i.get_current_arc_ne();
120 auto arc_tgt_node = i.get_tgt_node();
124 if (build_tree(arc_tgt_node, arc, tnode))
157 auto start = g.get_first_node();
158 if (not build_tree(g, start, tree))
188 typename GT::Node *
operator () (GT & g,
typename GT::Node * gnode, GT & tree)
190 this->build_tree(g, gnode, tree);
219 template <
class GT,
class SA = Dft_Show_Arc<GT> >
224 void build_tree(GT & g,
typename GT::Node * gp, GT & tree)
226 g.reset_bit_nodes(Spanning_Tree);
227 g.reset_bit_arcs(Spanning_Tree);
231 unique_ptr<typename GT::Node> tp_auto(
new typename GT::Node(gp));
232 tree.insert_node(tp_auto.get());
237 q.
put(i.get_current_arc_ne());
239 NODE_BITS(gp).set_bit(Spanning_Tree,
true);
241 while (not q.is_empty())
244 ARC_BITS(garc).set_bit(Spanning_Tree,
true);
245 auto gsrc = g.get_src_node(garc);
246 auto gtgt = g.get_tgt_node(garc);
253 std::swap(gsrc, gtgt);
255 auto tsrc = mapped_node<GT>(gsrc);
256 NODE_BITS(gtgt).set_bit(Spanning_Tree,
true);
259 unique_ptr<typename GT::Node> ttgt_auto(
new typename GT::Node(gtgt));
260 tree.insert_node(ttgt_auto.get());
261 auto ttgt = ttgt_auto.release();
265 auto tarc = tree.insert_arc(tsrc, ttgt, garc->get_info());
267 if (tree.get_num_nodes() == g.get_num_nodes())
273 auto current_arc = i.get_current_arc_ne();
313 find_breadth_first_spanning_tree <GT, SA> (g, gnode, tree);
353 # endif // TPL_SPANNING_TREE_H void clear_graph(GT &g) noexcept
Definition: tpl_graph.H:3463
GT::Node * operator()(GT &g, GT &tree)
Definition: tpl_spanning_tree.H:155
#define NODE_COOKIE(p)
Definition: aleph-graph.H:333
GT build_spanning_tree(const DynArray< typename GT::Arc *> &arcs)
Definition: tpl_graph_utils.H:1115
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:327
Definition: tpl_dynListQueue.H:50
void map_arcs(typename GTS::Arc *p, typename GTT::Arc *q) noexcept
Definition: tpl_graph.H:3445
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:360
DynList< typename GT::Arc * > arcs(typename GT::Node *p, SA sa=SA())
Definition: tpl_graph.H:1893
void map_nodes(typename GTS::Node *p, typename GTT::Node *q) noexcept
Definition: tpl_graph.H:3419
Definition: tpl_spanning_tree.H:54
#define NODE_BITS(p)
Definition: aleph-graph.H:305
#define ARC_BITS(p)
Definition: aleph-graph.H:351
Definition: tpl_dynArray.H:159
Definition: tpl_spanning_tree.H:327
Definition: tpl_spanning_tree.H:220
Definition: tpl_graph.H:1177
T & put(const T &data)
The type of element.
Definition: tpl_dynListQueue.H:125