6 # include <tpl_dynArray.H>
7 # include <tpl_sort_utils.H>
8 # include <tpl_dynMapTree.H>
9 # include <tpl_dynDlist.H>
10 # include <tpl_treapRk.H>
11 # include <aleph-graph.H>
12 # include <filter_iterator.H>
15 using namespace Aleph;
28 template <
typename __Graph_Node,
typename __Graph_Arc>
31 template <
typename __Graph_Node,
typename __Graph_Arc>
37 template <
typename MT,
typename Entry_Info,
typename Copy>
77 template <
typename __Node_Info = Empty_Class>
84 typedef __Node_Info Node_Info;
114 Graph_Node(
const Node_Info & info) : node_info(info), num_arcs(0)
178 template <
typename __Arc_Info = Empty_Class>
183 typedef __Arc_Info Arc_Info;
191 : src_node(NULL), tgt_node(NULL), src_arc_node(NULL), tgt_arc_node(NULL)
198 src_node(NULL), tgt_node(NULL), src_arc_node(NULL), tgt_arc_node(NULL)
203 Graph_Arc(
void * src,
void * tgt,
const Arc_Info & data)
205 src_node(src), tgt_node(tgt), src_arc_node(NULL), tgt_arc_node(NULL)
211 : src_node(src), tgt_node(tgt), src_arc_node(NULL), tgt_arc_node(NULL)
222 Arc_Node(
void * __arc) : arc(__arc) {}
253 template <
typename __Graph_Node = Graph_Node<
int>,
254 typename __Graph_Arc = Graph_Arc<
int>>
262 static Node * dlink_to_node(
Dlink * p) {
return (Node*) p; }
264 static Arc * dlink_to_arc(
Dlink * p) {
return (Arc*) p; }
268 static Arc * void_to_arc(
Arc_Node * arc_node)
270 return (Arc*) arc_node->arc;
280 Cmp_Arc(Cmp && __cmp = Cmp()) : cmp(__cmp) { }
282 Cmp_Arc(Cmp & __cmp) : cmp(__cmp) { }
284 bool operator () (
Dlink * d1,
Dlink * d2)
const
286 Arc * arc1 = dlink_to_arc(d1);
287 Arc * arc2 = dlink_to_arc(d2);
288 return cmp(arc1, arc2);
324 inline virtual Node *
insert_node(
const Node_Type & node_info);
328 inline virtual Node *
insert_node(Node_Type && node_info = Node_Type());
382 const typename Arc::Arc_Type & arc_info);
386 typename Arc::Arc_Type && arc_info);
388 inline virtual Arc *
insert_arc(Node * src_node, Node * tgt_node);
457 template <
class Compare>
inline
458 void sort_arcs(Compare && cmp = Compare());
460 template <
class Compare>
inline
463 GRAPH_SEARCH_METHODS;
569 Arc_Node * get_current_arc_node()
const
612 GRAPH_ITERATIVE_METHODS;
614 List_Graph() : cookie(NULL), num_nodes(0), num_arcs(0), digraph(false)
622 node_list.swap(&g.node_list);
623 arc_list.swap(&g.arc_list);
636 bool operator () (
typename GT::Arc * )
const
643 template <
class GT,
class SA1,
class SA2>
648 typename GT::Node * s;
652 Double_SA(SA1 && __sa1 = SA1(), SA2 && __sa2 = SA2())
653 : sa1(__sa1) , sa2(__sa2)
659 : sa1(__sa1) , sa2(__sa2)
664 Double_SA(SA1 & __sa1, SA2 && __sa2 = SA2())
665 : sa1(__sa1) , sa2(__sa2)
671 : sa1(__sa1) , sa2(__sa2)
676 bool operator () (
typename GT::Arc * a)
678 return sa1(a) and sa2(a);
693 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
696 typename GT::Node_Arc_Iterator,
700 typename GT::Node_Arc_Iterator,
705 <
typename GT::Node*,
typename GT::Node_Arc_Iterator, Show_Arc>
Itor;
721 :
Itor(p, std::move(sa))
750 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
772 :
Itor(g, std::move(sa))
796 bool operator () (
typename GT::Node *)
const
813 template <
class GT,
class Show_Node = Dft_Show_Node<GT>>
835 :
Itor (g, std::move(sn))
852 template <
class GT,
class SN = Dft_Show_Node<GT>>
853 void for_each_node(GT & g,
854 std::function<
void(
typename GT::Node*)> operation,
858 operation(it.get_curr());
861 template <
class GT,
class SN = Dft_Show_Node<GT>>
862 void for_each_node(GT & g,
863 std::function<
void(
typename GT::Node*)> operation,
866 for_each_node<GT, SN>(g, operation, sn);
869 template <
class GT,
class SA = Dft_Show_Arc<GT>>
870 void for_each_arc(GT & g,
871 std::function<
void(
typename GT::Arc*)> operation,
875 operation(it.get_curr());
878 template <
class GT,
class SA = Dft_Show_Arc<GT>>
879 void for_each_arc(GT & g,
880 std::function<
void(
typename GT::Arc*)> operation,
883 for_each_arc<GT, SA>(g, operation, sa);
886 template <
class GT,
class SA = Dft_Show_Arc<GT>>
887 void for_each_arc(GT&,
888 typename GT::Node * p,
889 std::function<
void(
typename GT::Arc*)> operation,
893 operation(it.get_curr());
896 template <
class GT,
class SA = Dft_Show_Arc<GT>>
897 void for_each_arc(GT& g,
898 typename GT::Node * p,
899 std::function<
void(
typename GT::Arc*)> operation,
902 for_each_arc<GT, SA>(g, p, operation, sa);
905 template <
class GT,
class SN = Dft_Show_Node<GT>>
906 bool forall_node(GT & g,
907 std::function<
bool(
typename GT::Node*)> operation,
911 if (not operation(it.get_curr()))
916 template <
class GT,
class SN = Dft_Show_Node<GT>>
917 bool forall_node(GT & g,
918 std::function<
bool(
typename GT::Node*)> operation,
921 return forall_node<GT, SN>(g, operation, sn);
924 template <
class GT,
class SA = Dft_Show_Arc<GT>>
925 bool forall_arc(GT & g,
926 std::function<
bool(
typename GT::Arc*)> operation,
930 if (not operation(it.get_curr()))
935 template <
class GT,
class SA = Dft_Show_Arc<GT>>
936 bool forall_arc(GT & g,
937 std::function<
bool(
typename GT::Arc*)> operation,
940 return forall_arc<GT, SA>(g, operation, sa);
943 template <
class GT,
class SA = Dft_Show_Arc<GT>>
944 bool forall_arc(
typename GT::Node * p,
945 std::function<
bool(
typename GT::Arc*)> operation,
949 if (not operation(it.get_curr()))
954 template <
class GT,
class SA = Dft_Show_Arc<GT>>
955 bool forall_arc(
typename GT::Node * p,
956 std::function<
bool(
typename GT::Arc*)> operation,
959 return forall_arc<GT, SA>(p, operation, sa);
964 template <
typename>
class Container =
DynDlist,
965 typename T =
typename GT::Node_Type>
966 Container<T> map_nodes(GT & g,
967 std::function<T(
typename GT::Node *)> operation,
970 Container<T> ret_val;
971 for_each_node<GT, SN>(g, [&ret_val, &operation] (
typename GT::Node * p)
973 ret_val.append(operation(p));
979 typename T =
typename GT::Node_Type,
980 template <
typename>
class Container =
DynDlist,
982 Container<T> map_nodes(GT & g,
983 std::function<T(
typename GT::Node *)> operation,
986 return map_nodes<GT, SN, Container, T>(g, operation, sn);
991 template <
typename>
class Container =
DynDlist,
992 typename T =
typename GT::Arc_Type>
993 Container<T> map_arcs(GT & g,
994 std::function<T(
typename GT::Arc *)> operation,
997 Container<T> ret_val;
998 for_each_arc<GT, SA>(g, [&ret_val, &operation] (
typename GT::Arc * p)
1000 ret_val.append(operation(p));
1006 typename T =
typename GT::Arc_Type,
1007 template <
typename>
class Container =
DynDlist,
1009 Container<T> map_arcs(GT & g,
1010 std::function<T(
typename GT::Arc *)> operation,
1013 return map_arcs<GT, SA, Container, T>(g, operation, sa);
1018 template <
typename>
class Container =
DynDlist,
1019 typename T =
typename GT::Arc_Type>
1020 Container<T> map_node_arcs(GT & g,
1021 typename GT::Node * p,
1022 std::function<T(
typename GT::Arc *)> operation,
1025 Container<T> ret_val;
1026 for_each_arc<GT, SA>(g, p, [&ret_val, &operation] (
typename GT::Arc * p)
1028 ret_val.append(operation(p));
1034 typename T =
typename GT::Arc_Type,
1035 template <
typename>
class Container =
DynDlist,
1037 Container<T> map_node_arcs(GT & g,
1038 typename GT::Node * p,
1039 std::function<T(
typename GT::Arc *)> operation,
1042 return map_node_arcs<GT, SA, Container, T>(g, p, operation, sa);
1045 template <
class GT,
typename T,
class SN = Dft_Show_Node<GT>>
1046 T foldl_nodes(GT & g,
const T & init,
1047 std::function<T(
const T&,
typename GT::Node*)> operation,
1051 for_each_node<GT, SN>(g, [&ret_val, &operation] (
typename GT::Node * p)
1053 ret_val = operation(ret_val, p);
1058 template <
class GT,
typename T,
class SN = Dft_Show_Node<GT>>
1059 T foldl_nodes(GT & g,
const T & init,
1060 std::function<T(
const T&,
typename GT::Node*)> operation,
1063 return foldl_nodes<GT, T, SN>(g, init, operation, sn);
1066 template <
class GT,
typename T,
class SA = Dft_Show_Arc<GT>>
1067 T foldl_arcs(GT & g,
const T & init,
1068 std::function<T(
const T&,
typename GT::Arc*)> operation,
1072 for_each_arc<GT, SA>(g, [&ret_val, &operation] (
typename GT::Arc* a)
1074 ret_val = operation(ret_val, a);
1079 template <
class GT,
typename T,
class SA = Dft_Show_Arc<GT>>
1080 T foldl_arcs(GT & g,
const T & init,
1081 std::function<T(
const T&,
typename GT::Arc*)> operation,
1084 return foldl_arcs<GT, T, SA>(g, init, operation, sa);
1087 template <
class GT,
typename T,
class SA = Dft_Show_Arc<GT>>
1088 T foldl_arcs(GT & g,
typename GT::Node * p,
1090 std::function<T(
const T&,
typename GT::Arc*)> operation,
1094 for_each_arc<GT, SA>(g, p, [&ret_val, &operation] (
typename GT::Arc* a)
1096 ret_val = operation(ret_val, a);
1101 template <
class GT,
typename T,
class SA = Dft_Show_Arc<GT>>
1102 T foldl_arcs(GT & g,
typename GT::Node * p,
1104 std::function<T(
const T&,
typename GT::Arc*)> operation,
1107 return foldl_arcs<GT, T, SA>(g, p, init, operation, sa);
1126 template <
typename __Graph_Node = Graph_Node<
int>,
1127 typename __Graph_Arc = Graph_Arc<
int>>
1134 typedef __Graph_Node Node;
1136 typedef __Graph_Arc Arc;
1140 this->digraph =
true;
1145 this->digraph =
true;
1151 this->digraph =
true;
1160 copy_graph(*
this, const_cast<List_Digraph&>(g));
1185 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1188 typename GT::Out_Iterator,
1194 <
typename GT::Node*,
typename GT::Out_Iterator, Show_Arc>
Itor;
1232 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1235 typename GT::In_Iterator,
1241 <
typename GT::Node*,
typename GT::In_Iterator, Show_Arc>
Itor;
1313 template <
class GT,
class SA>
typename GT::Arc *
1314 search_arc(GT & g,
typename GT::Node * src_node,
1315 typename GT::Node * tgt_node);
1319 typename GT::Node * mapped_node(
typename GT::Node * p)
1326 typename GT::Arc * mapped_arc(
typename GT::Arc * a)
1333 template <
class GTSRC,
class GTTGT>
1334 typename GTTGT::Node * mapped_node(
typename GTSRC::Node * p)
1340 template <
class GTSRC,
class GTTGT>
1341 typename GTTGT::Arc * mapped_arc(
typename GTSRC::Arc * a)
1343 return (
typename GTTGT::Arc *)
ARC_COOKIE(a);
1365 void copy_graph(GT & gtgt, GT & gsrc,
const bool cookie_map =
false);
1372 template <
class GT>
inline void clear_graph(GT & g);
1388 template <
class GT,
class Operation,
class SN = Dft_Show_Node<GT>>
1408 op (g, it.get_curr());
1420 void operator () (GT & g,
void * ptr, Operation op = Operation())
const
1423 op (g, it.get_curr(), ptr);
1441 template <
class GT,
class Operation,
1462 op (g, it.get_curr());
1473 void operator () (GT & g,
void * ptr, Operation op = Operation())
const
1476 op (g, itor.get_curr(), ptr);
1486 Operation op = Operation())
const
1489 op (g, it.get_current_arc());
1502 void * ptr, Operation op = Operation())
const
1505 op (g, it.get_current_arc(), ptr);
1540 typedef typename GT::Node Node;
1541 typedef typename GT::Arc Arc;
1547 Path_Desc(Node * _node = NULL, Arc * _arc = NULL)
1548 : node(_node), arc(_arc) {}
1549 bool operator == (
const Path_Desc & r)
const {
return arc == r.arc; }
1559 void *& get_cookie() {
return cookie; }
1569 Path(GT & _g,
void * __cookie = NULL) : g(&_g), cookie(__cookie) {}
1580 void init(Node * start_node) {
list.append(Path_Desc(start_node)); }
1590 Path(GT & _g, Node * start_node,
void * __cookie = NULL)
1591 : g(&_g), cookie(__cookie) {
init(start_node); }
1608 if (start_node == NULL)
1622 while (not
list.is_empty())
1623 list.remove_first();
1673 if (
list.is_empty())
1674 throw std::domain_error(
"path is empty");
1676 Path_Desc & last_path_desc =
list.get_last();
1679 throw std::domain_error(
"Graph has not been specified");
1681 last_path_desc.arc = arc;
1682 list.append(Path_Desc(g->get_connected_node(arc, last_path_desc.node)));
1714 if (
list.is_empty())
1721 throw std::domain_error(
"Graph has not been specified");
1727 throw std::domain_error(
"There is no an arc connecting to the node");
1760 if (
list.is_empty())
1761 throw std::domain_error(
"path is empty");
1764 throw std::domain_error(
"Graph has not been specified");
1766 Path_Desc & first_path_desc =
list.get_first();
1768 Path_Desc item(g->get_connected_node(arc, first_path_desc.node), arc);
1802 if (
list.is_empty())
1809 throw std::domain_error(
"Graph has not been specified");
1812 Arc * arc =
search_arc(*g, node, first_node);
1814 throw std::domain_error(
"There is no arc connecting node");
1831 if (
list.is_unitarian())
1832 throw std::domain_error(
"Path with only a node (without any arc");
1837 return it.get_current().arc;
1847 list.get_last().arc = NULL;
1853 list.remove_first();
1859 std::swap(g, path.g);
1878 Path_Desc & get_curr_path_desc()
const
1894 throw std::overflow_error(
"Path iterator is in last node of path");
1896 return this->get_curr_path_desc().arc;
1923 template <
class Operation>
1927 op (it.get_current_node());
1930 template <
class Operation>
1933 for_each_node<Operation>(op);
1942 template <
class Operation>
1946 op (it.get_current_arc());
1949 template <
class Operation>
1952 for_each_arc<Operation>(op);
1959 if (it.get_current_node() == node)
1968 if (it.get_current_arc() == arc)
1973 template <
template <
typename>
class Container =
DynList>
1974 Container<Node*> nodes()
const
1976 Container<Node*> ret_val;
1985 template <
template <
typename>
class Container =
DynList>
1986 Container<Arc*> arcs()
const
1988 Container<Arc*> ret_val;
1997 bool operator == (
const Path & p)
const
1999 return eq(this->
list, p.list);
2002 bool operator != (
const Path & p)
const
2004 return not eq(this->
list, p.list);
2008 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
2010 typename GT::Node * end_node,
Path<GT> & path);
2012 template <
class GT,
class SA>
inline
2013 bool __find_path_depth_first(GT& g,
typename GT::Node * curr_node,
2014 typename GT::Arc * curr_arc,
2015 typename GT::Node * end_node,
Path<GT> & curr_path)
2017 if (curr_node == end_node)
2019 curr_path.
append(curr_arc);
2026 curr_path.
append(curr_arc);
2027 NODE_BITS(curr_node).set_bit(Find_Path,
true);
2032 typename GT::Arc * next_arc = i.get_current_arc();
2036 ARC_BITS(next_arc).set_bit(Find_Path,
true);
2037 typename GT::Node * next_node = i.get_tgt_node();
2038 if (__find_path_depth_first<GT, SA> (g, next_node, next_arc,
2039 end_node, curr_path))
2081 template <
class GT,
class SA>
inline
2083 typename GT::Node * end_node,
Path<GT> & path)
2086 throw std::invalid_argument(
"Path does not belong to graph");
2089 path.
init(start_node);
2090 g.reset_bit_nodes(Find_Path);
2091 g.reset_bit_arcs(Find_Path);
2092 NODE_BITS(start_node).set_bit(Find_Path,
true);
2097 typename GT::Arc * arc = i.get_current_arc();
2098 ARC_BITS(arc).set_bit(Find_Path,
true);
2099 typename GT::Node * next_node = i.get_tgt_node();
2103 if (__find_path_depth_first<GT, SA>(g, next_node, arc, end_node, path))
2110 template <
class GTS,
class GTT>
2111 void map_nodes(
typename GTS::Node * p,
typename GTT::Node * q)
2113 I(p != NULL and q != NULL);
2126 template <
class GTS,
class GTT>
2127 void map_arcs(
typename GTS::Arc * p,
typename GTT::Arc * q)
2129 I(p != NULL and q != NULL);
2149 template <
typename Node,
typename Arc>
2153 throw std::range_error(
"Graph has not nodes");
2155 return dlink_to_node(const_cast<Dlink&>(node_list).get_next());
2158 template <
typename Node,
typename Arc>
2161 if (get_num_arcs() == 0)
2162 throw std::range_error(
"Graph has not arcs");
2164 return dlink_to_arc(const_cast<Dlink&>(arc_list).get_next());
2167 template <
typename Node,
typename Arc>
2170 if (get_num_arcs(node) == 0)
2171 throw std::range_error(
"node has not arcs");
2173 void * arc = dlink_to_arc_node(node->arc_list.get_next())->arc;
2174 return reinterpret_cast <Arc *> (arc);
2176 template <
typename Node,
typename Arc>
2178 :
Dlink::Iterator(&_g.node_list)
2183 template <
typename Node,
typename Arc>
2189 template <
typename Node,
typename Arc>
2191 :
Dlink::Iterator(&_g.arc_list)
2196 template <
typename Node,
typename Arc>
2202 template <
typename Node,
typename Arc>
2205 return static_cast<Arc*
>(get_current_arc_node()->arc);
2208 template <
typename Node,
typename Arc>
2211 return static_cast<Node*
>(get_current_arc()->get_connected_node(src_node));
2214 template <
typename Node,
typename Arc>
2222 template <
typename Node,
typename Arc> Node *
2228 template <
typename Node,
typename Arc> Node *
2232 (
new Node (std::move(node_info)) );
2235 template <
typename Node,
typename Arc> Arc *
2239 unique_ptr<Arc> arc (
new Arc );
2240 arc->src_node = src_node;
2241 arc->tgt_node = tgt_node;
2244 unique_ptr<Arc_Node> src_arc_node (
new Arc_Node (arc.get()));
2249 if (src_node == tgt_node)
2250 arc->tgt_arc_node = src_arc_node.get();
2253 unique_ptr<Arc_Node> tgt_arc_node(
new Arc_Node(arc.get()));
2256 arc->tgt_arc_node = tgt_arc_node.get();
2257 tgt_node->arc_list.append(tgt_arc_node.get());
2258 tgt_node->num_arcs++;
2259 tgt_arc_node.release();
2264 arc->src_arc_node = src_arc_node.get();
2265 src_node->arc_list.append(src_arc_node.get());
2266 src_node->num_arcs++;
2268 arc_list.
append(arc.get());
2270 src_arc_node.release();
2272 return arc.release();
2276 template <
typename Node,
typename Arc>
2279 Node * src_node = get_src_node(arc);
2280 Node * tgt_node = get_tgt_node(arc);
2281 Arc_Node * src_arc_node = arc->src_arc_node;
2282 Arc_Node * tgt_arc_node = arc->tgt_arc_node;
2286 if (src_node != tgt_node)
2288 tgt_node->arc_list.
append(tgt_arc_node);
2289 tgt_node->num_arcs++;
2293 src_node->arc_list.append(src_arc_node);
2294 src_node->num_arcs++;
2301 template <
typename Node,
typename Arc> Arc *
2303 const typename Arc::Arc_Type & arc_info)
2306 arc->get_info() = arc_info;
2311 template <
typename Node,
typename Arc> Arc *
2313 typename Arc::Arc_Type && arc_info)
2316 arc->get_info() = std::move(arc_info);
2322 template <
typename Node,
typename Arc>
2325 Node * src_node = get_src_node(arc);
2326 Arc_Node * src_arc_node = arc->src_arc_node;
2328 src_arc_node->
del();
2329 src_node->num_arcs--;
2330 delete src_arc_node;
2334 Node * tgt_node = get_tgt_node(arc);
2335 if (src_node != tgt_node)
2337 Arc_Node * tgt_arc_node = arc->tgt_arc_node;
2338 tgt_arc_node->
del();
2339 tgt_node->num_arcs--;
2340 delete tgt_arc_node;
2350 template <
typename Node,
typename Arc>
2353 Node * src_node = get_src_node(arc);
2354 Arc_Node * src_arc_node = arc->src_arc_node;
2355 src_arc_node->
del();
2356 src_node->num_arcs--;
2360 Node * tgt_node = get_tgt_node(arc);
2361 if (src_node != tgt_node)
2363 Arc_Node * tgt_arc_node = arc->tgt_arc_node;
2364 tgt_arc_node->
del();
2365 tgt_node->num_arcs--;
2374 template <
typename Node,
typename Arc>
2379 while (not node->arc_list.is_empty())
2382 dlink_to_arc_node(node->arc_list.get_next());
2383 Arc * arc = void_to_arc(arc_node);
2389 Arc * arc = it.get_current();
2390 if (get_src_node(arc) == node or get_tgt_node(arc) == node)
2405 template <
typename Node,
typename Arc>
2412 template <
typename Node,
typename Arc>
2419 template <
typename Node,
typename Arc>
2429 template <
typename Node,
typename Arc>
2437 template <
typename Node,
typename Arc>
2443 template <
typename Node,
typename Arc>
2444 template <
class Compare>
2447 mergesort<Dlink, Cmp_Arc<Compare>>(arc_list, Cmp_Arc<Compare>(cmp));
2450 template <
typename Node,
typename Arc>
2451 template <
class Compare>
2454 Cmp_Arc<Compare> comp(cmp);
2455 mergesort<Dlink, Cmp_Arc<Compare>>(arc_list, comp);
2460 template <
class GT,
class SA>
2462 typename GT::Node * src,
typename GT::Node * tgt)
2464 I(src != NULL and tgt != NULL);
2467 if (not g.is_digraph() and tgt->num_arcs < src->num_arcs)
2468 std::swap(tgt, src);
2471 if (itor.get_tgt_node() == tgt)
2472 return itor.get_current_arc();
2479 typename GT::Arc *
search_arc(GT & g,
typename GT::Node * src_node,
2480 typename GT::Node * tgt_node)
2482 return search_arc<GT, Dft_Show_Arc<GT>>(g, src_node, tgt_node);
2488 for (
typename GT::Arc_Iterator it(g); it.has_current(); )
2490 typename GT::Arc * arc = it.get_current();
2495 for (
typename GT::Node_Iterator it(g); it.has_current(); )
2497 typename GT::Node * p = it.get_current();
2507 IG(not gtgt.is_digraph() and gsrc.is_digraph(),
2508 gtgt.is_digraph() != gsrc.is_digraph());
2516 for (
typename GT::Node_Iterator it(gsrc); it.has_curr(); it.next())
2518 typename GT::Node * src_node = it.get_current_node();
2519 unique_ptr<typename GT::Node>
2520 tgt_node(
new typename GT::Node(src_node));
2521 map.
insert(src_node, tgt_node.get());
2523 typename GT::Node * tgt = tgt_node.release();
2524 gtgt.insert_node(tgt);
2527 GT::map_nodes(src_node, tgt);
2530 I(gtgt.get_num_nodes() == gsrc.get_num_nodes());
2534 for (
typename GT::Arc_Iterator it(gsrc); it.has_current(); it.next())
2536 typename GT::Arc * src_arc = it.get_current_arc();
2539 typename GT::Node * src_node = map(gsrc.get_src_node(src_arc));
2540 typename GT::Node * tgt_node = map(gsrc.get_tgt_node(src_arc));
2541 typename GT::Arc * tgt_arc = gtgt.insert_arc(src_node, tgt_node);
2542 tgt_arc->get_info() = src_arc->get_info();
2544 GT::map_arcs(src_arc, tgt_arc);
2547 I(gtgt.get_num_arcs() == gsrc.get_num_arcs());
2556 template <
class GTT,
class GTS>
2559 void operator () (
typename GTT::Node * tgt,
typename GTS::Node * src)
2561 tgt->get_info() = src->get_info();
2566 template <
class GTT,
class GTS>
2569 void operator () (
typename GTT::Arc * tgt,
typename GTS::Arc * src)
2571 tgt->get_info() = src->get_info();
2579 template <
class GTT,
class GTS,
2584 IG(not gtgt.is_digraph() and gsrc.is_digraph(),
2585 gtgt.is_digraph() != gsrc.is_digraph());
2593 for (
typename GTS::Node_Iterator it(gsrc); it.has_current(); it.next())
2595 typename GTS::Node * src_node = it.get_current_node();
2596 unique_ptr<typename GTT::Node> tgt_node(
new typename GTT::Node);
2597 Copy_Node () (tgt_node.get(), src_node);
2598 map.
insert(src_node, tgt_node.get());
2600 typename GTT::Node * tgt = tgt_node.release();
2601 gtgt.insert_node(tgt);
2604 map_nodes<GTS, GTT>(src_node, tgt);
2607 I(gtgt.get_num_nodes() == gsrc.get_num_nodes());
2611 for (
typename GTS::Arc_Iterator it(gsrc); it.has_current(); it.next())
2613 typename GTS::Arc * src_arc = it.get_current_arc();
2616 typename GTT::Node * src_node = map[gsrc.get_src_node(src_arc)];
2617 typename GTT::Node * tgt_node = map[gsrc.get_tgt_node(src_arc)];
2618 typename GTT::Arc * tgt_arc = gtgt.insert_arc(src_node, tgt_node);
2619 Copy_Arc () (tgt_arc, src_arc);
2621 map_arcs<GTS, GTT>(src_arc, tgt_arc);
2624 I(gtgt.get_num_arcs() == gsrc.get_num_arcs());
2670 : sn(__sn), sa(__sa)
2677 : sn(__sn), sa(__sa)
2684 : sn(__sn), sa(__sa)
2691 void copy(GT & gtgt, GT & gsrc,
const bool cookie_map)
2693 IG(not gtgt.is_digraph() and gsrc.is_digraph(),
2694 gtgt.is_digraph() != gsrc.is_digraph());
2704 typename GT::Node * src_node = it.get_curr();
2705 unique_ptr<typename GT::Node>
2706 tgt_node(
new typename GT::Node(src_node));
2707 map.
insert(src_node, tgt_node.get());
2709 typename GT::Node * tgt = tgt_node.release();
2710 gtgt.insert_node(tgt);
2713 GT::map_nodes(src_node, tgt);
2720 typename GT::Arc * src_arc = it.get_curr();
2723 typename GT::Node * src_node = map[gsrc.get_src_node(src_arc)];
2724 typename GT::Node * tgt_node = map[gsrc.get_tgt_node(src_arc)];
2725 typename GT::Arc * tgt_arc =
2726 gtgt.insert_arc(src_node, tgt_node, src_arc->get_info());
2729 GT::map_arcs(src_arc, tgt_arc);
2753 void operator () (GT & gtgt, GT & gsrc,
const bool cookie_map =
true)
2755 copy(gtgt, gsrc, cookie_map);
Definition: tpl_graph.H:2657
Node * get_tgt_node() const
Retorna el nodo destino del arco actual (sólo cuenta si es digrafo)
Definition: tpl_graph.H:609
Copy_Graph(SA &__sa, SN &__sn)
Definition: tpl_graph.H:2669
Node_Arc_Iterator(Node *src)
Instancia un iterador sobre el nodo _src_node.
Definition: tpl_graph.H:551
void inter_copy_graph(GTT >gt, GTS &gsrc, const bool cookie_map=false)
Definition: tpl_graph.H:2582
Node * get_curr() const
Definition: tpl_graph.H:1903
Definition: tpl_graph.H:29
virtual void remove_node(Node *node)
Definition: tpl_graph.H:2375
Node * get_current()
Definition: tpl_graph.H:522
const size_t & size() const
Retorna la longitud del camino en nodos.
Definition: tpl_graph.H:1614
Node_Iterator(GT &g, Show_Node &sn)
Definition: tpl_graph.H:845
Node * get_current_node() const
Definition: tpl_graph.H:1887
void insert(Node *node)
Definition: tpl_graph.H:1800
Node * get_first_node() const
Definition: tpl_graph.H:2150
virtual void remove_arc(Arc *arc)
Definition: tpl_graph.H:2323
void sort_arcs(Compare &&cmp=Compare())
Definition: tpl_graph.H:2445
#define NODE_COOKIE(p)
Definition: aleph-graph.H:248
virtual ~List_Graph()
Definition: tpl_graph.H:2438
Definition: tpl_dynMapTree.H:260
Path()
Constructor vacío.
Definition: tpl_graph.H:1572
Node * Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_graph.H:545
Out_Iterator(typename GT::Node *p, Show_Arc &&sa=Show_Arc())
Definition: tpl_graph.H:1203
Definition: tpl_graph.H:38
Definition: tpl_graph.H:21
bool is_cycle() const
Retorna true si el camino conforma un ciclo.
Definition: tpl_graph.H:1841
Definition: tpl_graph.H:217
bool is_empty() const
Retorna true si el camino está vacío.
Definition: tpl_graph.H:1617
size_type size()
Retorna la cantidad de elementos que tiene la lista.
Definition: List.H:340
Definition: tpl_dynDlist.H:26
Node * Item_Type
Tipo de elemento que retorna get_current()
Definition: tpl_graph.H:509
Definition: tpl_graph.H:751
Definition: tpl_graph.H:2567
Definition: tpl_graph.H:1389
Iterador sobre enlaces.
Definition: dlink.H:437
Node * get_curr()
Definition: tpl_graph.H:525
Path(const Path &path)
Constructor copia de camino; todos los nodos y arcos se copian.
Definition: tpl_graph.H:1630
void insert(Arc *arc)
Definition: tpl_graph.H:1758
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:242
void swap(list &c)
Definition: List.H:486
Arc * get_current_arc() const
Retorna un puntero al arco actual.
Node * get_first_node() const
Retorna el primer nodo del camino.
Definition: tpl_graph.H:1820
In_Iterator(typename GT::Node *p, Show_Arc &&sa=Show_Arc())
Definition: tpl_graph.H:1250
Itor::Set_Type Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_graph.H:825
List_Graph Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_graph.H:512
Itor::Item_Type Item_Type
Tipo de elemento que retorna get_current()
Definition: tpl_graph.H:822
Copy_Graph(SA &__sa, SN &&__sn=SN())
Definition: tpl_graph.H:2683
#define ARC_COOKIE(p)
Definition: aleph-graph.H:281
Copy_Graph(SA &&__sa=SA(), SN &&__sn=SN())
Definition: tpl_graph.H:2676
Definition: tpl_graph.H:794
Node_Arc_Iterator()
Instancia un iterador vacío (inválido).
Definition: tpl_graph.H:548
bool inside_graph(GT &gr) const
retorna true si el camino this refiere al grafo gr
Definition: tpl_graph.H:1562
Arc_Iterator(GT &g, Show_Arc &sa)
Definition: tpl_graph.H:782
Itor::Item_Type Item_Type
Tipo de elemento que retorna get_current()
Definition: tpl_graph.H:708
void clear_graph(GT &g)
Definition: tpl_graph.H:2486
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:275
It::Item_Type Item_Type
Tipo de elemento que retorna get_current()
Definition: filter_iterator.H:93
Itor::Set_Type Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_graph.H:762
Definition: tpl_graph.H:1186
Out_Iterator(typename GT::Node *p, Show_Arc &sa)
Definition: tpl_graph.H:1214
Definition: tpl_graph.H:26
Node_Arc_Iterator(typename GT::Node *p, Show_Arc &sa)
Definition: tpl_graph.H:731
bool find_path_depth_first(GT &g, typename GT::Node *start_node, typename GT::Node *end_node, Path< GT > &path)
Definition: tpl_graph.H:2082
Node_Arc_Iterator(typename GT::Node *p, Show_Arc &&sa=Show_Arc())
Definition: tpl_graph.H:720
Arc * get_last_arc()
Retorna el último arco del camino.
Definition: tpl_graph.H:1829
List_Graph & operator=(const List_Graph &g)
Definition: tpl_graph.H:2421
void remove_first_node()
Elimina el primer nodo del camino.
Definition: tpl_graph.H:1851
bool has_current() const
Retorna true si iterador aún tiene elemento actual.
Definition: dlink.H:554
void swap(Path &path)
Intercambias los contenidos del camino this con el de path.
Definition: tpl_graph.H:1857
GT::Arc_Type Arc_Type
El tipo de atributo que contienen los arcos del camino.
Definition: tpl_graph.H:1533
void remove_last_node()
Elimina el último nodo del camino.
Definition: tpl_graph.H:1844
Arc * get_current_arc() const
Definition: tpl_graph.H:1891
Node * get_src_node() const
Retorna el nodo origen del arco actual (sólo cuenta si es digrafo)
Definition: tpl_graph.H:606
Definition: tpl_graph.H:582
Graph_Node()
Definition: tpl_graph.H:97
Definition: tpl_graph.H:634
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
Graph_Node(const Node_Info &info)
Definition: tpl_graph.H:114
bool contains_node(Node *node) const
Retorna true si nodo pertenece al camino; false de lo contrario.
Definition: tpl_graph.H:1956
In_Iterator(typename GT::Node *p, Show_Arc &sa)
Definition: tpl_graph.H:1261
void for_each_node(Operation &op) const
Definition: tpl_graph.H:1924
Arc * get_current_arc() const
Retorna el arco actual.
Arc * Item_Type
Tipo de elemento que retorna get_current()
Definition: tpl_graph.H:587
Node * get_last_node() const
Retorna el último nodo del camino.
Definition: tpl_graph.H:1823
Arc * get_curr() const
Definition: tpl_graph.H:603
Definition: tpl_graph.H:504
bool contains_arc(Arc *arc) const
Retorna true si nodo pertenece al camino; false de lo contrario.
Definition: tpl_graph.H:1965
virtual Arc * insert_arc(Node *src_node, Node *tgt_node, const typename Arc::Arc_Type &arc_info)
Definition: tpl_graph.H:2302
Path(GT &_g, Node *start_node, void *__cookie=NULL)
Definition: tpl_graph.H:1590
bool has_current_arc() const
Definition: tpl_graph.H:1908
#define NODE_BITS(p)
Definition: aleph-graph.H:221
Definition: tpl_graph.H:1233
Path & operator=(const Path &path)
Asignación de camino; limpia this y copia todos los nodos y arcos de path.
Definition: tpl_graph.H:1633
Iterator(const Path &path)
Instancia un iterador sobre el camino path.
Definition: tpl_graph.H:1873
Definition: tpl_graph.H:535
Arc * get_curr() const
Definition: tpl_graph.H:564
Definition: tpl_graph.H:644
Arc * get_current() const
Retorna un puntero al arco actual.
Definition: tpl_graph.H:600
void init(Node *start_node)
Definition: tpl_graph.H:1580
void clear_path()
Limpia el camino (se eliminan todos sus nodos y arcos).
Definition: tpl_graph.H:1620
GT::Node_Type Node_Type
El tipo de atributo que contienen los nodos del camino.
Definition: tpl_graph.H:1531
virtual Arc * connect_arc(Arc *arc)
Definition: tpl_graph.H:2277
Definition: tpl_graph.H:19
Definition: tpl_graph.H:814
void operator()(GT &g, Operation op=Operation()) const
Definition: tpl_graph.H:1459
Arc * get_first_arc() const
Definition: tpl_graph.H:2159
#define ARC_BITS(p)
Definition: aleph-graph.H:266
void copy_graph(GT >gt, GT &gsrc, const bool cookie_map=false)
Definition: tpl_graph.H:2505
Arc_Iterator(GT &g, Show_Arc &&sa=Show_Arc())
Definition: tpl_graph.H:771
Arc * Item_Type
El tipo de dato que retorna get_current().
Definition: tpl_graph.H:542
T & get_current() const
Retorna el elemento actual del iterador.
Definition: tpl_dynDlist.H:427
Graph_Node(Graph_Node *node)
Definition: tpl_graph.H:134
Arc * get_first_arc()
Retorna el primer arco del camino.
Definition: tpl_graph.H:1826
GT::Arc * search_arc(GT &g, typename GT::Node *src_node, typename GT::Node *tgt_node)
Definition: tpl_graph.H:2461
Definition: tpl_graph.H:32
GT & get_graph() const
Obtiene una referencia al grafo sobre el cual se encuentra el camino.
Definition: tpl_graph.H:1557
Node_Iterator(GT &g, Show_Node &&sn=Show_Node())
Definition: tpl_graph.H:834
Definition: filter_iterator.H:42
void append(Dlink *node)
Definition: dlink.H:166
virtual void disconnect_arc(Arc *arc)
Definition: tpl_graph.H:2351
Arc * get_current() const
Definition: tpl_graph.H:561
iterator insert(const iterator &pos, const T &value)
Definition: List.H:525
Dlink * get_current() const
Retorna dirección de nodo actual.
Definition: dlink.H:564
Path(GT &_g, void *__cookie=NULL)
Definition: tpl_graph.H:1569
void append(Arc *arc)
Definition: tpl_graph.H:1671
Definition: tpl_graph.H:694
Itor::Item_Type Item_Type
Tipo de elemento que retorna get_current()
Definition: tpl_graph.H:759
List_Graph Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_graph.H:590
Node * get_tgt_node() const
Retorna el nodo destino del arco actual.
Key * insert(const Key &key, const Type &data)
Definition: tpl_dynMapTree.H:74
Definition: tpl_graph.H:35
Node * get_current() const
Definition: tpl_graph.H:1900
Definition: tpl_graph.H:1868
Iterator()
Constructor por omisión.
Definition: dlink.H:492
void clear()
Definition: tpl_graph.H:1627
Node * get_current_node()
retorna el nodo actual.
Itor::Set_Type Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_graph.H:711
void del()
Elimina this de su contexto en una lista.
Definition: dlink.H:278
void for_each_arc(Operation &op) const
Definition: tpl_graph.H:1943
void set_graph(GT &__g, Node *start_node=NULL)
Definition: tpl_graph.H:1604
void append(Node *node)
Definition: tpl_graph.H:1712
Definition: tpl_graph.H:2557
bool has_current_node() const
Retorna true si el iterador tiene nodo actual; false de lo contrario.
Definition: tpl_graph.H:1914
Definition: tpl_graph.H:1443
void operator()(GT &g, Operation op=Operation()) const
Definition: tpl_graph.H:1405
virtual Node * insert_node(Node *node)
Definition: tpl_graph.H:2215
bool is_in_last() const
Retorna true si iterador está sobre último elemento.
Definition: dlink.H:581