8 static const long No_Visited = 0;
51 unsigned int depth_first : 1;
58 unsigned int prim : 1;
60 unsigned int euler : 1;
87 throw(std::exception, std::out_of_range)
91 case Aleph::Depth_First:
return depth_first;
97 case Aleph::Kruskal:
return kruskal;
98 case Aleph::Prim:
return prim;
99 case Aleph::Dijkstra:
return dijkstra;
100 case Aleph::Euler:
return euler;
105 case Aleph::Cut:
return cut;
106 case Aleph::Min:
return min;
108 throw std::out_of_range(
"bit number out of range");
124 void set_bit(
const int & bit,
const int & value)
126 I(value == 0 or value == 1);
130 case Aleph::Depth_First: depth_first = value;
break;
132 case Aleph::Test_Cycle:
test_cycle = value;
break;
134 case Aleph::Test_Path:
test_path = value;
break;
135 case Aleph::Find_Path:
find_path = value;
break;
136 case Aleph::Kruskal:
kruskal = value;
break;
137 case Aleph::Prim:
prim = value;
break;
138 case Aleph::Dijkstra:
dijkstra = value;
break;
139 case Aleph::Euler:
euler = value;
break;
144 case Aleph::Cut:
cut = value;
break;
145 case Aleph::Min:
min = value;
break;
147 throw std::out_of_range(
"bit number out of range");
179 Bit_Fields control_bits;
183 Graph_Attr() :
counter(No_Visited), cookie(NULL) { }
186 template <
typename __Node_Info>
192 typedef __Node_Info Node_Info;
194 typedef Node_Info Item_Type;
196 typedef Node_Info Node_Type;
202 Node_Info & get_info() {
return node_info; }
204 const Node_Info & get_info()
const {
return node_info; }
213 : num_arcs(0), node_info(node.info)
221 std::swap(node_info, node.info);
225 : num_arcs(0), node_info(info)
231 : num_arcs(0), node_info(std::move(info))
237 : num_arcs(0), node_info(node->info)
243 template <
typename __Arc_Info>
246 typedef __Arc_Info Arc_Info;
248 typedef Arc_Info Item_Type;
250 typedef Arc_Info Arc_Type;
260 Arc_Info & get_info() {
return arc_info; }
262 const Arc_Info & get_info()
const {
return arc_info; }
264 void * get_connected_node(
void * node)
266 return src_node == node ? tgt_node : src_node;
281 : arc_info(std::move(info))
287 : src_node(src), tgt_node(tgt), arc_info(info)
293 : src_node(src), tgt_node(tgt), arc_info(std::move(info))
299 : src_node(src), tgt_node(tgt)
309 # define NODE_BITS(p) ((p)->attrs.control_bits)
314 # define NODE_COUNTER(p) ((p)->attrs.counter)
320 # define NODE_COLOR(p) ((p)->attrs.counter)
330 # define IS_NODE_VISITED(p, bit) (NODE_BITS(p).get_bit(bit))
336 # define NODE_COOKIE(p) ((p)->attrs.cookie)
342 # define ARC_COUNTER(p) ((p)->attrs.counter)
348 # define ARC_COLOR(p) ((p)->attrs.counter)
354 # define ARC_BITS(p) ((p)->attrs.control_bits)
363 # define IS_ARC_VISITED(p, bit) (ARC_BITS(p).get_bit(bit))
369 # define ARC_COOKIE(p) ((p)->attrs.cookie)
372 template <
class __Graph_Node,
class __Graph_Arc>
376 typedef __Graph_Node Node;
377 typedef __Graph_Arc Arc;
378 typedef typename Node::Node_Type Node_Type;
379 typedef typename Arc::Arc_Type Arc_Type;
417 num_nodes = num_arcs = 0;
424 if (digraph != g.digraph)
425 throw std::domain_error(
"source and target incompatible");
426 std::swap(num_nodes, g.num_nodes);
427 std::swap(num_arcs, g.num_arcs);
428 std::swap(digraph, g.digraph);
429 std::swap(cookie, g.cookie);
434 void *& get_cookie() {
return cookie; }
436 bool is_digraph()
const {
return digraph; }
438 const size_t & get_num_nodes()
const {
return num_nodes; }
440 const size_t & vsize()
const {
return get_num_nodes(); }
442 Node * get_src_node(Arc * arc) {
return (Node*) arc->src_node; }
444 Node * get_tgt_node(Arc * arc) {
return (Node*) arc->tgt_node; }
446 Node * get_connected_node(Arc * arc, Node * node)
448 return (Node*) arc->get_connected_node(node);
451 const size_t & get_num_arcs()
const {
return num_arcs; }
453 const size_t & esize()
const {
return get_num_arcs(); }
455 const size_t & get_num_arcs(Node * node)
const
457 return node->num_arcs;
460 Bit_Fields & get_control_bits(Node * node)
465 void reset_bit(Node * node,
const int & bit)
470 void reset_bits(Node * node) {
NODE_BITS(node).reset(); }
472 void set_bit(Node * node,
const int bit,
const int value)
477 Bit_Fields & get_control_bits(Arc * arc) {
return ARC_BITS(arc); }
479 void reset_bit(Arc * arc,
const int bit)
484 void reset_bits(Arc * arc) {
ARC_BITS(arc).reset(); }
486 void set_bit(Arc * arc,
const int bit,
const int value)
491 void *& get_cookie(Node * node) {
return NODE_COOKIE(node); }
493 void *& get_cookie(Arc * arc) {
return ARC_COOKIE(arc); }
495 long & get_counter(Node * node) {
return NODE_COUNTER(node); }
497 void reset_counter(Node * node) {
NODE_COUNTER(node) = No_Visited; }
499 void reset_node(Node * node)
501 node_bits(node).reset();
506 long & get_counter(Arc * arc) {
return ARC_COUNTER(arc); }
508 void reset_counter(Arc * arc) {
ARC_COUNTER(arc) = No_Visited; }
510 void reset_arc(Arc * arc)
517 template <
class N1,
class N2>
static
518 void map_nodes(N1 * p, N2 * q)
520 I(p != NULL and q != NULL);
533 template <
class A1,
class A2>
static
534 void map_arcs(A1 * p, A2 * q)
536 I(p != NULL and q != NULL);
549 inline virtual Node * insert_node(Node * node) = 0;
551 inline virtual Node * insert_node(
const Node_Type & node_info) = 0;
553 inline virtual Node * insert_node(Node_Type && node_info = Node_Type()) = 0;
555 inline virtual void remove_node(Node * node) = 0;
557 inline virtual Node * get_first_node() = 0;
559 inline virtual Arc * get_first_arc() = 0;
561 inline virtual Arc * get_first_arc(Node *) = 0;
563 inline virtual Arc * insert_arc(Node * src_node, Node * tgt_node,
564 const typename Arc::Arc_Type & arc_info) = 0;
567 insert_arc(Node * src_node, Node * tgt_node,
568 typename Arc::Arc_Type && arc_info) = 0;
570 inline virtual Arc * insert_arc(Node * src_node, Node * tgt_node) = 0;
572 inline virtual void remove_arc(Arc * arc) = 0;
574 inline virtual void disconnect_arc(Arc * arc) = 0;
576 inline virtual Arc * connect_arc(Arc * arc) = 0;
578 virtual ~Aleph_Graph();
582 # define GRAPH_ITERATIVE_METHODS \
583 void reset_bit_nodes(const int & bit) \
585 for (Node_Iterator itor(*this); itor.has_curr(); itor.next()) \
586 reset_bit(itor.get_current_node(), bit); \
589 void reset_bit_arcs(const int & bit) \
591 for (Arc_Iterator itor(*this); itor.has_curr(); itor.next()) \
592 reset_bit(itor.get_current_arc(), bit); \
594 void reset_bit_nodes() \
596 for (Node_Iterator itor(*this); itor.has_curr(); itor.next()) \
597 reset_bits(itor.get_current_node()); \
600 void reset_bit_arcs() \
602 for (Arc_Iterator itor(*this); itor.has_curr(); itor.next()) \
603 reset_bits(itor.get_current_arc()); \
606 Node * get_node(size_t k) \
608 int m = Base_Graph::num_nodes/2; \
609 Node_Iterator it(*this); \
612 for (int i = 0; i < k; ++i) \
617 for (int i = Base_Graph::num_nodes - 1; i > k; --i) \
621 return it.get_curr(); \
624 Node * get_arc(size_t k) \
626 int m = Base_Graph::num_arcs/2; \
627 Arc_Iterator it(*this); \
630 for (int i = 0; i < k; ++i) \
635 for (int i = Base_Graph::num_arcs - 1; i > k; --i) \
639 return it.get_curr(); \
642 void reset_counter_nodes() \
644 for (Node_Iterator itor(*this); itor.has_curr(); itor.next()) \
645 reset_counter(itor.get_current_node()); \
648 void reset_counter_arcs() \
650 for (Arc_Iterator itor(*this); itor.has_curr(); itor.next()) \
651 reset_counter(itor.get_current_arc()); \
654 void reset_cookie_nodes() \
656 for (Node_Iterator itor(*this); itor.has_curr(); itor.next()) \
657 itor.get_current_node()->cookie = NULL; \
660 void reset_cookie_arcs() \
662 for (Arc_Iterator itor(*this); itor.has_curr(); itor.next()) \
663 itor.get_current_arc()->cookie = NULL; \
665 inline void reset_nodes(); \
667 inline void reset_arcs(); \
669 typedef Node_Arc_Iterator Out_Iterator;
673 # define GRAPH_SEARCH_METHODS \
674 template <class Equal> \
675 Node * search_node(const typename Node::Node_Type & node_info) \
677 for (Node_Iterator itor(*this); itor.has_curr(); itor.next()) \
679 Node * curr_node = itor.get_current_node(); \
680 if (Equal() (curr_node->get_info(), node_info)) \
687 template <typename T, class Equal> \
688 Node * search_node(const T & data) \
690 for (Node_Iterator it(*this); it.has_curr(); it.next()) \
692 Node * p = it.get_current_node(); \
693 if (Equal () (p->get_info(), data)) \
700 Node * search_node(const typename Node::Node_Type & node_info) \
702 return search_node<Aleph::equal_to<typename Node::Node_Type>>(node_info); \
705 template <class Equal> \
706 Node * search_node(void * ptr) \
708 for (Node_Iterator itor(*this); itor.has_curr(); itor.next()) \
710 Node * curr_node = itor.get_current_node(); \
711 if (Equal () (curr_node, ptr)) \
718 template <typename T, class Equal> \
719 Arc * search_Arc(const T & data) \
721 for (Arc_Iterator it(*this); it.has_curr(); it.next()) \
723 Arc * a = it.get_current_arc(); \
724 if (Equal () (a->get_info(), data)) \
731 template <class Equal> \
732 Arc * search_arc(const typename Arc::Arc_Type & arc_info) \
734 for (Arc_Iterator it(*this); it.has_curr(); it.next()) \
736 Arc * curr_arc = it.get_current_arc(); \
737 if (Equal () (curr_arc->get_info(), arc_info)) \
744 Arc * search_arc(const typename Arc::Arc_Type & arc_info) \
746 return search_arc<Aleph::equal_to<Arc_Type> >(arc_info); \
749 template <class Equal> \
750 Arc * search_arc(void * ptr) \
752 for (Arc_Iterator itor(*this); itor.has_curr(); itor.next()) \
754 Arc * curr_arc = itor.get_current_node(); \
755 if (Equal () (curr_arc, ptr)) \
763 # define GRAPH_INSERTION_METHODS \
764 virtual Node * insert_node(const Node_Type & node_info) \
766 return insert_node(new Node (node_info)); \
769 virtual Node * insert_node(Node_Type && node_info = Node_Type()) \
771 return insert_node(new Node(std::move(node_info))); \
775 insert_arc(Node * src, Node * tgt, const Arc_Type & arc_info)\
777 return insert_arc(src, tgt, new Arc(arc_info) ); \
781 insert_arc(Node * src, Node * tgt, Arc_Type && arc_info = Arc_Type()) \
783 return insert_arc(src, tgt, new Arc(std::move(arc_info))); \
787 #define GRAPH_METHODS_IMPLS(Name) \
788 template <typename Node, typename Arc> \
789 void Name<Node, Arc>::reset_nodes() \
791 Operate_On_Nodes <Name, Aleph_Graph<Node, Arc>::Reset_Node> () (*this); \
794 template <typename Node, typename Arc> \
795 void Name<Node, Arc>::reset_arcs() \
797 Operate_On_Arcs <Name, Aleph_Graph<Node, Arc>::Reset_Arc> () (*this); \
#define ARC_COUNTER(p)
Definition: tpl_aleph_graph.H:342
Definition: tpl_aleph_graph.H:391
#define NODE_COOKIE(p)
Definition: tpl_aleph_graph.H:336
Bit_Fields()
pertenece a un camino mÃnimo
Definition: tpl_aleph_graph.H:69
unsigned int is_acyclique
Bit de verificación de ciclo.
Definition: aleph-graph.H:54
unsigned int min
nodo o arco de corte
Definition: aleph-graph.H:66
bool get_bit(const int &bit) const
Definition: tpl_aleph_graph.H:86
unsigned int breadth_first
Bit de búsqueda en profundidad.
Definition: aleph-graph.H:52
Definition: aleph-graph.H:177
unsigned int convert_tree
Bit de subgrafo.
Definition: aleph-graph.H:64
unsigned int cut
Conversión a Tree_Node.
Definition: aleph-graph.H:65
unsigned int kruskal
Bit de búsqueda de camino.
Definition: aleph-graph.H:57
unsigned int test_path
Bit de prueba de aciclicidad.
Definition: aleph-graph.H:55
Definition: tpl_aleph_graph.H:401
#define ARC_COOKIE(p)
Definition: tpl_aleph_graph.H:369
#define NODE_COUNTER(p)
Definition: tpl_aleph_graph.H:314
unsigned int test_cycle
Bit de búsqueda en amplitud.
Definition: aleph-graph.H:53
unsigned int find_path
Bit de prueba de existencia de camino.
Definition: aleph-graph.H:56
void set_bit(const int &bit, const int &value)
Definition: tpl_aleph_graph.H:124
unsigned int prim
Bit de algoritmo de Kruskal.
Definition: aleph-graph.H:58
unsigned int build_subtree
Bit de árbol abarcador.
Definition: aleph-graph.H:63
Definition: tpl_aleph_graph.H:373
unsigned int spanning_tree
Bit para flujos máximos.
Definition: aleph-graph.H:62
#define NODE_BITS(p)
Definition: tpl_aleph_graph.H:309
void reset()
Reinicia todos los bits a cero.
Definition: tpl_aleph_graph.H:155
long counter
bits de control del arco
Definition: aleph-graph.H:180
Definition: tpl_aleph_graph.H:244
#define ARC_BITS(p)
Definition: tpl_aleph_graph.H:354
unsigned int maximum_flow
Bit de camino euleriano.
Definition: aleph-graph.H:61
unsigned int euler
Bit de algoritmo de Dijkstra.
Definition: aleph-graph.H:60
Definition: tpl_aleph_graph.H:187
void reset(const int &bit)
Reinicia bit a cero.
Definition: tpl_aleph_graph.H:152
unsigned int dijkstra
Bit de algoritmo de Prim.
Definition: aleph-graph.H:59