4 # include <tpl_agraph.H>
5 # include <tpl_graph_utils.H>
10 using namespace Aleph;
15 typename GT::Node * tree_node;
18 Prim_Info() : tree_node(NULL), heap_node(NULL) { }
21 # define PRIMINFO(p) static_cast<Prim_Info<GT>*>(NODE_COOKIE(p))
22 # define TREENODE(p) (PRIMINFO(p)->tree_node)
23 # define HEAPNODE(p) (PRIMINFO(p)->heap_node)
25 template <
class GT,
class Distance>
28 typedef typename ArcHeap<GT, Distance, Prim_Heap_Info>::Node Node;
30 Node *& operator () (
typename GT::Node * p)
32 return (Node*&) HEAPNODE(p);
36 template <
class GT,
class Distance>
39 typedef typename ArcHeap<GT, Distance, Simple_Prim_Heap>::Node Node;
41 Node *& operator () (
typename GT::Node * p)
54 void operator () (GT & g,
typename GT::Node * p)
56 g.reset_bit(p, Aleph::Prim);
58 TREENODE(p) = tree.insert_node(p->get_info());
65 void operator () (GT &,
typename GT::Node * p)
68 GT::map_nodes(p, TREENODE(p));
142 : dist(__dist), sa(__sa)
148 : dist(__dist), sa(__sa)
155 void paint_min_spanning_tree(GT & g,
typename GT::Node * first)
158 throw std::domain_error(
"g is a digraph");
163 NODE_BITS(first).set_bit(Aleph::Prim,
true);
165 Simple_Heap heap(dist, Acc_Simple_Heap());
168 typename GT::Arc * arc = it.get_current_arc();
169 heap.put_arc(arc, it.get_tgt_node());
172 const size_t V1 = g.get_num_nodes() - 1;
175 while (count < V1 and not heap.is_empty())
177 typename GT::Arc * min_arc = heap.get_min_arc();
181 ARC_BITS(min_arc).set_bit(Aleph::Prim,
true);
183 typename GT::Node * src = g.get_src_node(min_arc);
184 typename GT::Node * tgt = g.get_tgt_node(min_arc);
189 typename GT::Node * tgt_node =
192 NODE_BITS(tgt_node).set_bit(Aleph::Prim,
true);
197 typename GT::Arc * arc = it.get_current_arc();
201 typename GT::Node * tgt = it.get_tgt_node();
205 heap.put_arc(arc, tgt);
209 ARC_BITS(min_arc).set_bit(Aleph::Prim,
true);
213 void min_spanning_tree(GT & g,
typename GT::Node * first, GT & tree)
216 throw std::domain_error(
"g is a digraph");
223 NODE_BITS(first).set_bit(Aleph::Prim,
true);
225 Heap heap(dist, Acc_Heap()) ;
229 typename GT::Arc * arc = it.get_current_arc();
230 heap.put_arc(arc, it.get_tgt_node());
233 const size_t V1 = g.get_num_nodes() - 1;
235 while (tree.get_num_arcs() < V1 and not heap.is_empty())
237 typename GT::Arc * min_arc = heap.get_min_arc();
241 ARC_BITS(min_arc).set_bit(Aleph::Prim,
true);
243 typename GT::Node * src = g.get_src_node(min_arc);
244 typename GT::Node * tgt = g.get_tgt_node(min_arc);
249 typename GT::Node * tgt_node =
252 NODE_BITS(tgt_node).set_bit(Aleph::Prim,
true);
257 typename GT::Arc * arc = it.get_current_arc();
261 typename GT::Node * tgt = it.get_tgt_node();
265 heap.put_arc(arc, tgt);
269 typename GT::Arc * tree_arc =
270 tree.insert_arc(TREENODE(src), TREENODE(tgt), min_arc->get_info());
271 GT::map_arcs(min_arc, tree_arc);
293 min_spanning_tree(g, g.get_first_node(), tree);
311 min_spanning_tree(g, start, tree);
317 paint_min_spanning_tree(g, g.get_first_node());
320 void operator () (GT & g,
typename GT::Node * start)
322 paint_min_spanning_tree(g, start);
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Definition: ahAlgo.H:127
#define NODE_COOKIE(p)
Definition: aleph-graph.H:248
Definition: tpl_graph.H:1389
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:242
Prim_Min_Spanning_Tree(Distance &&__dist=Distance(), SA &&__sa=SA())
Definition: Prim.H:140
void clear_graph(GT &g)
Definition: tpl_graph.H:2486
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:275
Definition: tpl_graph.H:1186
Definition: tpl_graph.H:634
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
#define NODE_BITS(p)
Definition: aleph-graph.H:221
Definition: tpl_graph_utils.H:2291
#define ARC_BITS(p)
Definition: aleph-graph.H:266
void operator()(GT &g, GT &tree)
Definition: Prim.H:291