1 # ifndef TPL_SPANNING_TREE_H
2 # define TPL_SPANNING_TREE_H
25 template <
class GT,
class SA = Dft_Show_Arc<GT> >
32 bool build_tree(
typename GT::Node * gnode,
typename GT::Arc * garc,
33 typename GT::Node * tnode)
35 NODE_BITS(gnode).set_bit(Spanning_Tree,
true);
36 ARC_BITS(garc).set_bit(Spanning_Tree,
true);
38 typename GT::Node * tree_tgt_node = tptr->insert_node(gnode->get_info());
39 GT::map_nodes(gnode, tree_tgt_node);
41 typename GT::Arc * tarc =
42 tptr->insert_arc(tnode, tree_tgt_node, garc->get_info());
43 GT::map_arcs(garc, tarc);
45 tnode = tree_tgt_node;
46 if (tptr->get_num_nodes() == gptr->get_num_nodes())
49 I(tptr->get_num_nodes() > tptr->get_num_arcs());
52 i.has_curr() and tptr->get_num_nodes() < gptr->get_num_nodes();
55 typename GT::Arc * arc = i.get_current_arc();
59 typename GT::Node * arc_tgt_node = i.get_tgt_node();
63 if (build_tree(arc_tgt_node, arc, tnode))
70 bool build_tree(GT & g,
typename GT::Node * gnode, GT & tree)
80 NODE_BITS(gnode).set_bit(Spanning_Tree,
true);
82 typename GT::Node * tnode = tree.insert_node(gnode->get_info());
83 GT::map_nodes(gnode, tnode);
86 i.has_curr() and tptr->get_num_nodes() < gptr->get_num_nodes();
89 typename GT::Arc * arc = i.get_current_arc();
93 typename GT::Node * arc_tgt_node = i.get_tgt_node();
97 if (build_tree(arc_tgt_node, arc, tnode))
132 typename GT::Node * start = g.get_first_node();
133 if (not build_tree(g, start, tree))
163 typename GT::Node *
operator () (GT & g,
typename GT::Node * gnode, GT & tree)
165 this->build_tree(g, gnode, tree);
194 template <
class GT,
class SA = Dft_Show_Arc<GT> >
199 void build_tree(GT & g,
typename GT::Node * gp, GT & tree)
201 g.reset_bit_nodes(Spanning_Tree);
202 g.reset_bit_arcs(Spanning_Tree);
206 unique_ptr<typename GT::Node> tp_auto(
new typename GT::Node(gp));
207 tree.insert_node(tp_auto.get());
208 GT::map_nodes(gp, tp_auto.release());
212 q.
put(i.get_current_arc());
214 NODE_BITS(gp).set_bit(Spanning_Tree,
true);
216 while (not q.is_empty())
218 typename GT::Arc * garc = q.get();
219 ARC_BITS(garc).set_bit(Spanning_Tree,
true);
220 typename GT::Node * gsrc = g.get_src_node(garc);
221 typename GT::Node * gtgt = g.get_tgt_node(garc);
228 std::swap(gsrc, gtgt);
230 typename GT::Node * tsrc = mapped_node<GT>(gsrc);
231 NODE_BITS(gtgt).set_bit(Spanning_Tree,
true);
234 unique_ptr<typename GT::Node> ttgt_auto(
new typename GT::Node(gtgt));
235 tree.insert_node(ttgt_auto.get());
236 typename GT::Node * ttgt = ttgt_auto.release();
237 GT::map_nodes(gtgt, ttgt);
240 typename GT::Arc * tarc = tree.insert_arc(tsrc, ttgt, garc->get_info());
241 GT::map_arcs(garc, tarc);
242 if (tree.get_num_nodes() == g.get_num_nodes())
248 typename GT::Arc * current_arc = i.get_current_arc();
288 find_breadth_first_spanning_tree <GT, SA> (g, gnode, tree);
322 const bool with_map =
false)
const
331 # endif // TPL_SPANNING_TREE_H
void operator()(GT &g, typename GT::Node *gnode, GT &tree)
Definition: tpl_spanning_tree.H:286
GT::Node * operator()(GT &g, GT &tree)
Definition: tpl_spanning_tree.H:130
#define NODE_COOKIE(p)
Definition: aleph-graph.H:248
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:242
Definition: tpl_dynListQueue.H:22
void operator()(GT &g, GT &tree, DynArray< typename GT::Node > *pred, DynArray< typename GT::Arc > *arcs, const bool with_map=false) const
Definition: tpl_spanning_tree.H:319
void clear_graph(GT &g)
Definition: tpl_graph.H:2486
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:275
void build_spanning_tree(GT &g, GT &tree, DynArray< typename GT::Arc > *arcs, const bool with_map=false)
Definition: tpl_graph_utils.H:1536
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
Definition: tpl_spanning_tree.H:26
#define NODE_BITS(p)
Definition: aleph-graph.H:221
#define ARC_BITS(p)
Definition: aleph-graph.H:266
Definition: tpl_dynArray.H:70
Definition: tpl_spanning_tree.H:302
Definition: tpl_spanning_tree.H:195
Definition: tpl_graph.H:694
T & put(const T &data)
Definition: tpl_dynListQueue.H:86