1 # ifndef TPL_GRAPH_UTILS_H
2 # define TPL_GRAPH_UTILS_H
6 # include <tpl_agraph.H>
7 # include <tpl_dynListQueue.H>
13 template <
class GT,
class SA>
inline static bool
14 __depth_first_traversal(GT & g,
typename GT::Node * node,
15 typename GT::Arc * arc,
16 bool (*visit)(GT & g,
typename GT::Node *,
65 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline size_t
67 bool (*visit)(GT & g,
typename GT::Node *,
71 g.reset_bit_nodes(Depth_First);
72 g.reset_bit_arcs(Depth_First);
75 __depth_first_traversal<GT,SA>(g, start_node, NULL, visit, counter, sa);
114 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
116 bool (*visit)(GT &,
typename GT::Node *,
120 return depth_first_traversal <GT, SA> (g, g.get_first_node(), visit, sa);
130 bool operator () (GT &,
typename GT::Node *,
typename GT::Arc *)
204 bool __dft(
typename GT::Node * node,
typename GT::Arc * arc = NULL)
209 NODE_BITS(node).set_bit(Depth_First,
true);
212 if ((*op)(*g_ptr, node, arc))
215 if (count == g_ptr->get_num_nodes())
221 typename GT::Arc * arc = it.get_current_arc();
225 ARC_BITS(arc).set_bit(Depth_First,
true);
226 if (__dft (it.get_tgt_node(), arc))
233 size_t dft(GT & g,
typename GT::Node * start_node, Operation & __op)
238 g_ptr->reset_bit_nodes(Depth_First);
239 g_ptr->reset_bit_arcs(Depth_First);
274 return dft(g, g.get_first_node(), op);
279 return dft(g, g.get_first_node(), op);
290 Operation && op = Operation())
292 return dft(g, sn, op);
295 size_t operator () (GT & g,
typename GT::Node * sn, Operation & op)
297 return dft(g, sn, op);
302 template <
class GT,
class SA>
inline static bool
303 __depth_first_traversal(GT & g,
typename GT::Node * node,
304 typename GT::Arc * arc,
305 bool (*visit)(GT & g,
typename GT::Node *,
313 NODE_BITS(node).set_bit(Depth_First,
true);
317 if ((*visit)(g, node, arc))
320 if (count == g.get_num_nodes())
326 typename GT::Arc * arc = it.get_current_arc();
330 ARC_BITS(arc).set_bit(Depth_First,
true);
331 if (__depth_first_traversal<GT, SA>(g, it.get_tgt_node(), arc,
379 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline size_t
381 bool (*visit)(GT &,
typename GT::Node *,
382 typename GT::Arc *) )
384 g.reset_bit_nodes(Breadth_First);
385 g.reset_bit_arcs(Breadth_First);
390 q.
put(it.get_current_arc());
392 NODE_BITS(start).set_bit(Breadth_First,
true);
393 size_t node_counter = 1;
396 if ((*visit)(g, start, NULL))
400 while (not q.is_empty() and node_counter < g.get_num_nodes())
402 typename GT::Arc * arc = q.
get();
403 ARC_BITS(arc).set_bit(Breadth_First,
true);
405 typename GT::Node * src = g.get_src_node(arc);
406 typename GT::Node * tgt = g.get_tgt_node(arc);
411 typename GT::Node * visit_node =
415 if ((*visit)(g, visit_node, arc))
418 NODE_BITS(visit_node).set_bit(Breadth_First,
true);
424 typename GT::Arc * curr_arc = it.get_current_arc();
483 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline size_t
485 bool (*visit)(GT &,
typename GT::Node *,
489 return breadth_first_traversal<GT, SA>(g, g.get_first_node(), visit);
532 size_t bft(GT & g,
typename GT::Node * start, Operation & op)
534 g.reset_bit_nodes(Breadth_First);
535 g.reset_bit_arcs(Breadth_First);
540 q.
put(it.get_current_arc());
542 NODE_BITS(start).set_bit(Breadth_First,
true);
545 if (op (g, start, NULL))
549 while (not q.is_empty() and count < g.get_num_nodes())
551 typename GT::Arc * arc = q.
get();
552 ARC_BITS(arc).set_bit(Breadth_First,
true);
554 typename GT::Node * src = g.get_src_node(arc);
555 typename GT::Node * tgt = g.get_tgt_node(arc);
561 typename GT::Node * curr =
564 if (op (g, curr, arc))
567 NODE_BITS(curr).set_bit(Breadth_First,
true);
573 typename GT::Arc * curr_arc = it.get_current_arc();
607 return bft (g, g.get_first_node(), op);
612 return bft (g, g.get_first_node(), op);
625 Operation && op = Operation())
627 return bft(g, p, op);
630 size_t operator () (GT & g,
typename GT::Node * p, Operation & op)
632 return bft(g, p, op);
637 template <
class GT>
inline static
639 typename GT::Node * node,
typename GT::Arc * arc,
642 unique_ptr<Path<GT>> path_auto;
643 if (path_ptr == NULL)
644 path_auto = unique_ptr<Path<GT>>(
new Path<GT>(g, node));
646 path_auto = unique_ptr<Path<GT>>(
new Path<GT>(*path_ptr));
648 path_auto->append(arc);
649 q.put(path_auto.get());
684 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
686 typename GT::Node * end,
Path<GT> & path)
689 throw std::invalid_argument(
"Path does not belong to graph");
699 q.
put(i.get_current_arc());
701 NODE_BITS(start).set_bit(Find_Path,
true);
703 bool path_found =
false;
705 while (not q.is_empty())
707 typename GT::Arc * arc = q.
get();
708 typename GT::Node * src = g.get_src_node(arc);
709 typename GT::Node * tgt = g.get_tgt_node(arc);
717 ARC_BITS(arc).set_bit(Find_Path,
true);
729 typename GT::Arc * a = i.get_current_arc();
747 typename GT::Node * p = end;
783 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
787 throw std::domain_error(
"test_connectivity() does not work on digraphs");
789 if (g.get_num_arcs() < g.get_num_nodes() - 1)
792 return depth_first_traversal<GT, SA>(g, NULL) == g.get_num_nodes();
796 template <
class GT,
class SA>
inline static
797 bool __test_cycle(GT & g,
typename GT::Node * src_node,
798 typename GT::Node * curr_node);
816 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
819 g.reset_bit_nodes(Test_Cycle);
820 g.reset_bit_arcs(Test_Cycle);
825 typename GT::Arc * arc = it.get_current_arc();
829 ARC_BITS(arc).set_bit(Test_Cycle,
true);
831 if (__test_cycle<GT,SA>(g, src_node, it.get_tgt_node()))
840 template <
class GT,
class SA>
inline static
841 bool __test_cycle(GT & g,
typename GT::Node * src_node,
842 typename GT::Node * curr_node)
844 if (src_node == curr_node)
850 NODE_BITS(curr_node).set_bit(Test_Cycle,
true);
855 typename GT::Arc * arc = it.get_current_arc();
859 ARC_BITS(arc).set_bit(Test_Cycle,
true);
861 if (__test_cycle<GT,SA>(g, src_node, it.get_tgt_node()))
869 template <
class GT,
class SA>
inline static
870 bool __is_graph_acyclique(GT & g,
typename GT::Node * curr_node)
875 NODE_BITS(curr_node).set_bit(Is_Acyclique,
true);
879 typename GT::Arc * arc = i.get_current_arc();
883 ARC_BITS(arc).set_bit(Is_Acyclique,
true);
885 if (not __is_graph_acyclique<GT,SA>(g, i.get_tgt_node()))
927 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
931 throw std::domain_error(
"is_graph_acyclique() does not work for digraps");
933 if (g.get_num_arcs() >= g.get_num_nodes())
936 g.reset_bit_arcs(Is_Acyclique);
937 g.reset_bit_nodes(Is_Acyclique);
939 return __is_graph_acyclique<GT,SA>(g, start_node);
965 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
969 throw std::domain_error(
"is_graph_acyclique() does not work for digraps");
971 if (g.get_num_arcs() >= g.get_num_nodes())
974 g.reset_bit_arcs(Is_Acyclique);
975 g.reset_bit_nodes(Is_Acyclique);
979 typename GT::Node * current_node = it.get_current_node();
983 if (not __is_graph_acyclique<GT,SA>(g, current_node))
1024 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1027 return not is_graph_acyclique<GT,SA>(g);
1031 template <
class GT,
class SA>
inline static
1032 bool __test_for_path(GT & g,
typename GT::Node * curr_node,
1033 typename GT::Node * end_node);
1064 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
1066 typename GT::Node * end_node)
1068 if (not g.is_digraph() and g.get_num_arcs() >= g.get_num_nodes())
1071 g.reset_bit_nodes(Test_Path);
1072 g.reset_bit_arcs(Test_Path);
1077 typename GT::Arc * arc = i.get_current_arc();
1078 ARC_BITS(arc).set_bit(Test_Path,
true);
1079 if (__test_for_path<GT, SA>(g, i.get_tgt_node(), end_node))
1088 template <
class GT,
class SA>
inline static
1089 bool __test_for_path(GT & g,
typename GT::Node * curr_node,
1090 typename GT::Node * end_node)
1092 if (curr_node == end_node)
1098 NODE_BITS(curr_node).set_bit(Test_Path,
true);
1103 typename GT::Arc * arc = i.get_current_arc();
1107 ARC_BITS(arc).set_bit(Test_Path,
true);
1108 if (__test_for_path<GT, SA>(g, i.get_tgt_node(), end_node))
1117 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
1120 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
1122 typename GT::Node * g_src,
size_t & node_count);
1163 template <
class GT,
class SA>
inline
1169 for (
typename GT::Node_Iterator i(g);
1170 count < g.get_num_nodes() and i.has_current(); i.next())
1172 typename GT::Node * curr = i.get_current_node();
1180 build_subgraph <GT, SA> (g, subgraph, curr,
count);
1214 template <
class GT,
class SA>
inline
1216 typename GT::Node * g_src,
size_t & node_count)
1221 NODE_BITS(g_src).set_bit(Build_Subtree,
true);
1224 typename GT::Node * sg_src = mapped_node <GT> (g_src);
1227 sg_src = sg.insert_node(g_src->get_info());
1228 GT::map_nodes(g_src, sg_src);
1232 node_count < g.get_num_nodes() and i.has_current(); i.
next())
1234 typename GT::Arc * arc = i.get_current_arc();
1238 ARC_BITS(arc).set_bit(Build_Subtree,
true);
1239 typename GT::Node * g_tgt = i.get_tgt_node();
1240 typename GT::Node * sg_tgt = mapped_node <GT> (g_tgt);
1243 sg_tgt = sg.insert_node(g_tgt->get_info());
1244 GT::map_nodes(g_tgt, sg_tgt);
1248 typename GT::Arc * sg_arc =
1249 sg.insert_arc(sg_src, sg_tgt, arc->get_info());
1250 GT::map_arcs(arc, sg_arc);
1252 build_subgraph<GT,SA>(g, sg, g_tgt, node_count);
1257 template <
class GT,
class SA>
inline static
1258 bool __find_depth_first_spanning_tree(GT & g,
1259 typename GT::Node * gnode,
1260 typename GT::Arc * garc,
1262 typename GT::Node * tnode);
1305 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
1314 NODE_BITS(gnode).set_bit(Spanning_Tree,
true);
1316 typename GT::Node * tnode = tree.insert_node(gnode->get_info());
1317 GT::map_nodes(gnode, tnode);
1321 typename GT::Arc * arc = i.get_current_arc();
1325 typename GT::Node * arc_tgt_node = i.get_tgt_node();
1329 if (__find_depth_first_spanning_tree<GT,SA>(g, arc_tgt_node,
1370 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
1373 typename GT::Node * start_node = g.get_first_node();
1374 find_depth_first_spanning_tree<GT,SA>(g, start_node, tree);
1378 template <
class GT,
class SA>
inline static
1379 bool __find_depth_first_spanning_tree(GT & g,
typename GT::Node * gnode,
1380 typename GT::Arc * garc,
1381 GT & tree,
typename GT::Node * tnode)
1383 NODE_BITS(gnode).set_bit(Spanning_Tree,
true);
1384 ARC_BITS(garc).set_bit(Spanning_Tree,
true);
1386 typename GT::Node * tree_tgt_node = tree.insert_node(gnode->get_info());
1387 GT::map_nodes(gnode, tree_tgt_node);
1389 typename GT::Arc * tarc =
1390 tree.insert_arc(tnode, tree_tgt_node, garc->get_info());
1391 GT::map_arcs(garc, tarc);
1393 tnode = tree_tgt_node;
1394 if (tree.get_num_nodes() == g.get_num_nodes())
1397 I(tree.get_num_nodes() > tree.get_num_arcs());
1401 typename GT::Arc * arc = i.get_current_arc();
1405 typename GT::Node * arc_tgt_node = i.get_tgt_node();
1409 if (__find_depth_first_spanning_tree<GT,SA>(g, arc_tgt_node,
1456 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline
1459 g.reset_bit_nodes(Spanning_Tree);
1460 g.reset_bit_arcs(Spanning_Tree);
1462 unique_ptr<typename GT::Node> tp_auto(
new typename GT::Node(gp));
1463 tree.insert_node(tp_auto.get());
1464 GT::map_nodes(gp, tp_auto.release());
1468 q.
put(i.get_current_arc());
1470 NODE_BITS(gp).set_bit(Spanning_Tree,
true);
1472 while (not q.is_empty())
1474 typename GT::Arc * garc = q.get();
1475 ARC_BITS(garc).set_bit(Spanning_Tree,
true);
1476 typename GT::Node * gsrc = g.get_src_node(garc);
1477 typename GT::Node * gtgt = g.get_tgt_node(garc);
1484 std::swap(gsrc, gtgt);
1486 typename GT::Node * tsrc = mapped_node<GT>(gsrc);
1487 NODE_BITS(gtgt).set_bit(Spanning_Tree,
true);
1490 unique_ptr<typename GT::Node> ttgt_auto(
new typename GT::Node(gtgt));
1491 tree.insert_node(ttgt_auto.get());
1492 typename GT::Node * ttgt = ttgt_auto.release();
1493 GT::map_nodes(gtgt, ttgt);
1496 typename GT::Arc * tarc = tree.insert_arc(tsrc, ttgt, garc->get_info());
1497 GT::map_arcs(garc, tarc);
1498 if (tree.get_num_nodes() == g.get_num_nodes())
1504 typename GT::Arc * current_arc = i.get_current_arc();
1537 const bool with_map =
false)
1540 for (
int i = 0; i < g.get_num_nodes(); ++i)
1542 typename GT::Arc * garc = arcs[i];
1546 typename GT::Node * gsrc = g.get_src_node(garc);
1547 typename GT::Node * tsrc = NULL;
1549 tsrc = mapped_node <GT> (gsrc);
1552 NODE_BITS(gsrc).set_bit(Spanning_Tree,
true);
1553 tsrc = tree.insert_node(gsrc->get_info());
1556 typename GT::Node * gtgt = g.get_tgt_node(garc);
1557 typename GT::Node * ttgt = NULL;
1559 ttgt = mapped_node <GT> (gtgt);
1562 NODE_BITS(gtgt).set_bit(Spanning_Tree,
true);
1563 ttgt = tree.insert_node(gtgt->get_info());
1566 typename GT::Arc * tarc = tree.insert_arc(tsrc, ttgt, garc->get_info());
1570 GT::map_nodes(gsrc, tsrc);
1571 GT::map_nodes(gtgt, ttgt);
1572 GT::map_arcs(garc, tarc);
1577 template <
class GT>
inline static
1578 long & df(
typename GT::Node * p)
1583 template <
class GT>
inline static
1584 long & low(
typename GT::Node * p)
1592 void operator () (GT & g,
typename GT::Node * node)
1594 g.reset_counter(node);
1595 low <GT> (node) = -1;
1599 template <
class GT,
class SA>
inline static
1601 typename GT::Node * p,
typename GT::Arc * a,
1637 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1643 long current_df = 0;
1644 NODE_BITS(start).set_bit(Depth_First,
true);
1645 df <GT> (start) = current_df++;
1646 int call_counter = 0;
1650 i.has_current() and current_df < g.get_num_nodes(); i.
next())
1652 typename GT::Node * tgt = i.get_tgt_node();
1656 typename GT::Arc * arc = i.get_current_arc();
1660 ARC_BITS(arc).set_bit(Depth_First,
true);
1661 __compute_cut_nodes <GT, SA> (g, list, tgt, arc, current_df);
1665 if (call_counter > 1)
1672 template <
class GT,
class SA>
inline static
1674 typename GT::Node * p,
typename GT::Arc * a,
1677 NODE_BITS(p).set_bit(Depth_First,
true);
1678 low <GT> (p) = df <GT> (p) = curr_df++;
1681 bool p_is_cut_node =
false;
1684 typename GT::Arc * arc = i.get_current_arc();
1688 typename GT::Node * tgt = i.get_tgt_node();
1692 if (df<GT>(tgt) < low<GT>(p))
1693 low<GT>(p) = df<GT>(tgt);
1701 ARC_BITS(arc).set_bit(Depth_First,
true);
1703 __compute_cut_nodes<GT, SA>(g, list, tgt, arc, curr_df);
1705 if (low<GT>(tgt) < low<GT>(p))
1706 low<GT>(p) = low<GT>(tgt);
1708 if (low<GT>(tgt) >= df<GT>(p) and df<GT>(tgt) != 0)
1709 p_is_cut_node =
true;
1720 const long Cross_Arc = -1;
1722 template <
class GT>
inline static
1723 bool is_a_cross_arc(
typename GT::Arc * a)
1728 template <
class GT>
inline static
1729 bool is_a_cut_node(
typename GT::Node * p)
1734 template <
class GT>
inline static
1735 bool is_an_cut_arc(
typename GT::Arc * a)
1739 template <
class GT>
inline static
1740 bool is_node_painted(
typename GT::Node * p)
1745 template <
class GT>
inline static
1746 bool is_arc_painted(
typename GT::Arc * arc)
1751 template <
class GT>
inline static
1752 void paint_node(
typename GT::Node * p,
const long & color)
1757 template <
class GT>
inline static
1758 void paint_arc(
typename GT::Arc * a,
const long & color)
1763 template <
class GT>
inline static
1764 const long & get_color(
typename GT::Node * p)
1769 template <
class GT>
inline static
1770 const long & get_color(
typename GT::Arc * a)
1775 template <
class GT,
class SA>
inline static
1776 void __paint_subgraph(GT & g,
1777 typename GT::Node * p,
1778 typename GT::Arc * a,
1779 const long & current_color);
1781 template <
class GT,
class SA>
inline static
1782 void __paint_subgraph(GT & g,
typename GT::Node * p,
const long & current_color)
1784 I(not is_a_cut_node <GT> (p));
1786 if (is_node_painted <GT> (p))
1789 paint_node <GT> (p, current_color);
1793 typename GT::Arc * arc = it.get_current_arc();
1794 if (is_arc_painted <GT> (arc))
1797 typename GT::Node * tgt = it.get_tgt_node();
1798 if (is_a_cut_node <GT> (tgt))
1801 paint_arc <GT> (arc, current_color);
1803 __paint_subgraph <GT, SA> (g, tgt, current_color);
1807 template <
class GT,
class SA>
inline static
1808 void __paint_from_cut_node(GT & g,
typename GT::Node * p,
long & current_color)
1810 I(is_a_cut_node <GT> (p));
1815 typename GT::Arc * arc = it.get_current_arc();
1817 I(not is_arc_painted <GT> (arc));
1819 typename GT::Node * tgt_node = it.get_tgt_node();
1820 if (is_a_cut_node <GT> (tgt_node))
1827 paint_arc <GT> (arc, Cross_Arc);
1828 if (is_node_painted <GT> (tgt_node))
1833 __paint_subgraph <GT, SA> (g, tgt_node, current_color);
1837 I(not is_arc_painted <GT> (arc));
1890 template <
class GT,
class SA = Dft_Show_Arc<GT>>
inline long
1893 g.reset_counter_nodes();
1894 g.reset_counter_arcs();
1895 long current_color = 1;
1899 i(cut_node_list); i.has_current(); i.next())
1900 __paint_from_cut_node<GT,SA>(g, i.get_current(), current_color);
1902 return current_color;
1907 template <
class GT,
class SA>
inline static
1908 void __map_subgraph(GT & g, GT & sg,
typename GT::Node * gsrc,
1911 I(get_color <GT> (gsrc) == color);
1913 typename GT::Node * tsrc = mapped_node<GT>(gsrc);
1918 typename GT::Arc * garc = i.get_current_arc();
1919 if (get_color<GT>(garc) != color or
IS_ARC_VISITED(garc, Build_Subtree))
1922 ARC_BITS(garc).set_bit(Build_Subtree,
true);
1924 typename GT::Node * gtgt = i.get_tgt_node();
1926 I(get_color <GT> (gtgt) == color);
1928 typename GT::Node * ttgt = NULL;
1930 ttgt = mapped_node<GT> (gtgt);
1933 unique_ptr<typename GT::Node> ttgt_auto(
new typename GT::Node(gtgt));
1934 sg.insert_node(ttgt_auto.get());
1935 GT::map_nodes(gtgt, ttgt_auto.get());
1936 NODE_BITS(gtgt).set_bit(Build_Subtree,
true);
1937 ttgt = ttgt_auto.release();
1940 typename GT::Arc * tarc = sg.insert_arc(tsrc, ttgt, garc->get_info());
1941 GT::map_arcs(garc, tarc);
1943 __map_subgraph<GT, SA> (g, sg, gtgt, color);
1980 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1984 typename GT::Node * first = NULL;
1985 for (
typename GT::Node_Iterator it(g); it.has_current(); it.next())
1986 if (get_color <GT> (it.get_current_node()) == color)
1987 first = it.get_current_node();
1990 throw std::domain_error(
"Color does not exist in the graph");
1993 unique_ptr<typename GT::Node> auto_tsrc(
new typename GT::Node(first));
1994 sg.insert_node(auto_tsrc.get());
1995 GT::map_nodes(first, auto_tsrc.release());
1996 NODE_BITS(first).set_bit(Build_Subtree,
true);
2000 __map_subgraph <GT, SA> (g, sg, first, color);
2049 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2058 it(cut_node_list); it.has_curr(); it.next())
2060 typename GT::Node * gp = it.get_current();
2062 I (is_a_cut_node <GT> (gp));
2064 unique_ptr<typename GT::Node> tp_auto(
new typename GT::Node(gp));
2065 cut_graph.insert_node(tp_auto.get());
2066 GT::map_nodes(gp, tp_auto.release());
2073 typename GT::Arc * garc = it.get_current_arc();
2074 if (is_a_cross_arc <GT> (garc))
2076 cross_arc_list.
append(garc);
2080 if (not is_an_cut_arc <GT> (garc))
2083 typename GT::Node * src = mapped_node<GT>(g.get_src_node(garc));
2084 typename GT::Node * tgt = mapped_node<GT>(g.get_tgt_node(garc));
2086 I(src != NULL and tgt != NULL);
2088 typename GT::Arc * arc = cut_graph.insert_arc(src, tgt, garc->get_info());
2089 GT::map_arcs(garc, arc);
2101 template <
class GT,
class Distance>
2118 bool operator () (
typename GT::Arc * a1,
typename GT::Arc * a2)
2120 return dist(a1) < dist(a2);
2145 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2146 bool is_reachable(GT & g,
typename GT::Node * src,
typename GT::Node * tgt)
2148 if (not g.is_digraph())
2149 throw std::domain_error(
"g is not a digraph");
2151 return test_for_path <GT, SA> (g, src, tgt);
2169 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2183 typename GT::Node * tgt)
const
2185 return is_reachable<GT, SA> (g, src, tgt);
2206 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2209 if (not g.is_digraph())
2210 throw std::domain_error(
"g is not a digraph");
2212 if (not gi.is_digraph())
2213 throw std::domain_error(
"gi is not a digraph");
2221 typename GT::Arc * arc = it.get_current();
2224 typename GT::Node * ssrc = g.get_src_node(arc);
2225 typename GT::Node * rsrc = mapped_node<GT> (ssrc);
2228 unique_ptr<typename GT::Node> rsrc_auto(
new typename GT::Node(ssrc));
2229 gi.insert_node(rsrc_auto.get());
2230 GT::map_nodes(ssrc, rsrc_auto.get());
2231 rsrc = rsrc_auto.release();
2235 typename GT::Node * stgt = g.get_tgt_node(arc);
2236 typename GT::Node * rtgt = mapped_node<GT> (stgt);
2239 unique_ptr<typename GT::Node> rtgt_auto(
new typename GT::Node(stgt));
2240 gi.insert_node(rtgt_auto.get());
2241 GT::map_nodes(stgt, rtgt_auto.get());
2242 rtgt = rtgt_auto.release();
2245 typename GT::Arc * ai = gi.insert_arc(rtgt, rsrc, arc->get_info());
2246 GT::map_arcs(arc, ai);
2249 I(g.get_num_arcs() == gi.get_num_arcs() and
2250 g.get_num_nodes() == gi.get_num_nodes());
2258 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2279 invert_digraph <GT, SA> (g, gi, sa);
2295 typedef typename GT::Arc_Type Distance_Type;
2297 static const Distance_Type Zero_Distance = 0;
2299 static const Distance_Type Max_Distance;
2301 Distance_Type & operator () (
typename GT::Arc * a)
const
2303 return a->get_info();
2309 std::numeric_limits<typename Dft_Dist<GT>::Distance_Type>::max();
2312 template <
class GT,
class Distance = Dft_Dist<GT>>
2313 typename Distance::Distance_Type
2314 get_min_path(
typename GT::Node * s,
typename GT::Node * end,
2317 typename Distance::Distance_Type dist = 0;
2321 typename GT::Node * p = end;
2353 Plus && __plus = Plus(),
2355 : dist(__dist),
plus(__plus), sa(__sa)
2360 Total_Cost(Distance & __dist, Plus & __plus, SA & __sa)
2361 : dist(__dist),
plus(__plus), sa(__sa)
2371 typename Distance::Distance_Type sum = Distance::Zero_Distance;
2375 sum =
plus(sum, dist(it.get_current_arc()));
2393 # endif // TPL_GRAPH_UTILS_H
size_t depth_first_traversal(GT &g, bool(*visit)(GT &, typename GT::Node *, typename GT::Arc *), SA sa=SA())
Definition: tpl_graph_utils.H:115
Definition: tpl_graph_utils.H:195
bool has_cycle(GT &g)
Definition: tpl_graph_utils.H:1025
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Definition: ahAlgo.H:127
#define ARC_COUNTER(p)
Definition: aleph-graph.H:254
#define NODE_COOKIE(p)
Definition: aleph-graph.H:248
bool operator()(GT &g, typename GT::Node *src, typename GT::Node *tgt) const
Definition: tpl_graph_utils.H:2182
Definition: tpl_dynDlist.H:26
Definition: tpl_graph.H:751
Definition: tpl_graph.H:1389
size_t operator()(GT &g, Operation &&op=Operation())
Definition: tpl_graph_utils.H:272
void insert(Arc *arc)
Definition: tpl_graph.H:1758
void map_cut_graph(GT &g, DynDlist< typename GT::Node * > &cut_node_list, GT &cut_graph, DynDlist< typename GT::Arc * > &cross_arc_list)
Definition: tpl_graph_utils.H:2050
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:242
bool test_for_path(GT &g, typename GT::Node *start_node, typename GT::Node *end_node)
Definition: tpl_graph_utils.H:1065
Distance::Distance_Type operator()(GT &g)
Definition: tpl_graph_utils.H:2383
Breadth_First_Traversal(SA &&__sa=SA())
Definition: tpl_graph_utils.H:593
Definition: tpl_graph_utils.H:2102
Definition: tpl_dynListQueue.H:22
Depth_First_Traversal(SA &__sa)
Definition: tpl_graph_utils.H:260
#define NODE_COUNTER(p)
Definition: aleph-graph.H:226
bool is_reachable(GT &g, typename GT::Node *src, typename GT::Node *tgt)
Definition: tpl_graph_utils.H:2146
bool inside_graph(GT &gr) const
retorna true si el camino this refiere al grafo gr
Definition: tpl_graph.H:1562
void clear_graph(GT &g)
Definition: tpl_graph.H:2486
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:275
void build_subgraph(GT &g, GT &sg, typename GT::Node *g_src, size_t &node_count)
Definition: tpl_graph_utils.H:1215
void build_spanning_tree(GT &g, GT &tree, DynArray< typename GT::Arc > *arcs, const bool with_map=false)
Definition: tpl_graph_utils.H:1536
Definition: tpl_graph.H:26
void find_depth_first_spanning_tree(GT &g, GT &tree)
Definition: tpl_graph_utils.H:1371
Definition: tpl_graph_utils.H:527
bool is_graph_acyclique(GT &g)
Definition: tpl_graph_utils.H:966
Definition: tpl_graph.H:634
void compute_cut_nodes(GT &g, typename GT::Node *start, DynDlist< typename GT::Node * > &list)
Definition: tpl_graph_utils.H:1638
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
size_t breadth_first_traversal(GT &g, bool(*visit)(GT &, typename GT::Node *, typename GT::Arc *))
Definition: tpl_graph_utils.H:484
Depth_First_Traversal(SA &&__sa=SA())
Definition: tpl_graph_utils.H:252
Definition: tpl_graph_utils.H:2170
#define NODE_BITS(p)
Definition: aleph-graph.H:221
void inconnected_components(GT &g, DynDlist< GT > &list)
Definition: tpl_graph_utils.H:1164
Definition: tpl_graph_utils.H:128
void operator()(GT &g, GT &gi) const
Definition: tpl_graph_utils.H:2277
Definition: tpl_graph_utils.H:2291
Definition: tpl_graph_utils.H:2259
bool test_connectivity(GT &g)
Definition: tpl_graph_utils.H:784
T & get_last()
Retorna una referencia al último elemento de la lista.
Definition: tpl_dynDlist.H:202
void clear_path()
Limpia el camino (se eliminan todos sus nodos y arcos).
Definition: tpl_graph.H:1620
Definition: tpl_graph.H:814
#define ARC_BITS(p)
Definition: aleph-graph.H:266
Definition: tpl_dynArray.H:70
Arc * get_first_arc()
Retorna el primer arco del camino.
Definition: tpl_graph.H:1826
long paint_subgraphs(GT &g, const DynDlist< typename GT::Node * > &cut_node_list)
Definition: tpl_graph_utils.H:1891
bool find_path_breadth_first(GT &g, typename GT::Node *start, typename GT::Node *end, Path< GT > &path)
Definition: tpl_graph_utils.H:685
Definition: tpl_graph_utils.H:2344
Definition: ahFunction.H:54
size_t operator()(GT &g, Operation &&op=Operation())
Definition: tpl_graph_utils.H:605
T get()
Definition: tpl_dynListQueue.H:107
Distance::Distance_Type total_cost(GT &g)
Invoca al cálculo del coste total.
Definition: tpl_graph_utils.H:2369
Definition: tpl_graph.H:694
void find_breadth_first_spanning_tree(GT &g, typename GT::Node *gp, GT &tree)
Definition: tpl_graph_utils.H:1457
void invert_digraph(GT &g, GT &gi, SA &&sa=SA())
Definition: tpl_graph_utils.H:2207
void map_subgraph(GT &g, GT &sg, const long &color)
Definition: tpl_graph_utils.H:1981
bool test_for_cycle(GT &g, typename GT::Node *src_node)
Definition: tpl_graph_utils.H:817
Definition: tpl_graph_utils.H:1590
T & put(const T &data)
Definition: tpl_dynListQueue.H:86
T & append(const T &item)
Definition: tpl_dynDlist.H:106