1 # ifndef TPL_NETGRAPH_H
2 # define TPL_NETGRAPH_H
5 # include <tpl_dynDlist.H>
6 # include <tpl_dynListStack.H>
7 # include <tpl_dynBinHeap.H>
8 # include <tpl_dynSetTree.H>
9 # include <tpl_random_queue.H>
11 # include <tpl_graph_utils.H>
12 # include <tpl_find_path.H>
45 using namespace Aleph;
65 template <
typename Arc_Info,
typename F_Type =
double>
108 this->get_info() = arc.get_info();
140 template <
typename Node_Info,
typename F_Type =
double>
203 template <
class NodeT = Net_Node<Empty_Class,
double>,
204 class ArcT = Net_Arc<Empty_Class,
double> >
261 return node->in_degree != 0 or node->num_arcs != 0;
272 return node->out_flow == 0 and node->in_flow >= 0;
275 return node->in_flow == 0 and node->out_flow >= 0;
281 Arc * arc = it.get_current();
282 if (arc->is_residual)
285 if (not arc->check_arc())
288 sum_out_cap += arc->
cap;
289 sum_out_flow += arc->flow;
292 if (sum_out_cap != node->out_cap or sum_out_flow != node->out_flow)
298 return node->out_flow == node->in_flow;
321 if (src_nodes.
size() == 1)
324 if (src_nodes.
size() == 0)
325 throw std::domain_error(
"network has not source node (it has cicles)");
329 it != src_nodes.
end(); ++it)
349 I(src_nodes.
size() == 1);
352 with_super_source =
false;
360 if (sink_nodes.
size() == 1)
363 if (sink_nodes.
size() == 0)
364 throw std::domain_error(
"network has not sink node (it has cicles)");
368 it != sink_nodes.
end(); ++it)
388 I(sink_nodes.
size() == 1);
391 with_super_sink =
false;
403 catch (std::bad_alloc)
436 Node * p = Digraph::insert_node(node_info);
448 Digraph::remove_node(p);
454 Digraph::remove_node(p);
476 Digraph::insert_node(p);
488 Digraph::remove_node(p);
494 Digraph::remove_node(p);
518 const typename Arc::Arc_Type & arc_info,
521 Arc * arc = Digraph::insert_arc(src_node, tgt_node, arc_info);
523 src_nodes.
erase(tgt_node);
524 sink_nodes.
erase(src_node);
529 if (not arc->check_arc())
530 throw std::overflow_error(
"flow is greater than capacity");
532 tgt_node->in_degree++;
533 src_node->out_cap += cap;
534 tgt_node->in_cap += cap;
535 src_node->out_flow += flow;
536 tgt_node->in_flow += flow;
560 Digraph::connect_arc(arc);
562 Node * src = this->get_src_node(arc);
563 Node * tgt = this->get_tgt_node(arc);
565 src_nodes.
erase(tgt);
566 sink_nodes.
erase(src);
569 src->out_cap += arc->cap;
570 tgt->in_cap += arc->cap;
571 src->out_flow += arc->flow;
572 tgt->in_flow += arc->flow;
618 const typename Arc::Arc_Type & arc_info)
620 return insert_arc(src_node, tgt_node, arc_info, 0, 0);
650 Node * src = this->get_src_node(arc);
651 Node * tgt = this->get_tgt_node(arc);
653 if (--(tgt->in_degree) == 0)
656 src->out_cap -= arc->cap;
657 src->out_flow -= arc->flow;
658 tgt->in_cap -= arc->cap;
659 tgt->in_flow -= arc->flow;
661 Digraph::remove_arc(arc);
663 if (this->get_num_arcs(src) == 0)
680 Node * src = this->get_src_node(arc);
681 Node * tgt = this->get_tgt_node(arc);
682 if (--(tgt->in_degree) == 0)
685 src->out_cap -= arc->cap;
686 src->out_flow -= arc->flow;
687 tgt->in_cap -= arc->cap;
688 tgt->in_flow -= arc->flow;
690 Digraph::disconnect_arc(arc);
692 if (this->get_num_arcs(src) == 0)
699 Digraph::remove_node(p);
709 Net_Graph::Net_Graph();
717 Infinity(numeric_limits<typename
Arc::
Flow_Type>::max()),
734 throw std::out_of_range(
"capacity value is smaller than flow");
739 Node * src_node = get_src_node(arc);
740 src_node->out_cap -= old_cap;
741 src_node->out_cap += cap;
743 Node * tgt_node = get_tgt_node(arc);
744 tgt_node->in_cap -= old_cap;
745 tgt_node->in_cap += cap;
753 throw std::out_of_range(
"flow value is greater than capacity");
758 Node * src_node = get_src_node(arc);
759 src_node->out_flow -= old_flow;
760 src_node->out_flow += flow;
762 Node * tgt_node = get_tgt_node(arc);
763 tgt_node->in_flow -= old_flow;
764 tgt_node->in_flow += flow;
776 it.get_current()->flow = 0;
780 Node * p = it.get_current();
781 p->in_flow = p->out_flow = 0;
820 : Infinity(numeric_limits<typename
Arc::
Flow_Type>::max()),
824 void insert_residual_arc(
Arc * arc)
826 Arc * res_arc = Digraph::insert_arc(this->get_tgt_node(arc),
827 this->get_src_node(arc));
829 res_arc->is_residual =
true;
830 res_arc->img_arc = arc;
831 res_arc->cap = arc->cap;
832 res_arc->flow = arc->cap - arc->flow;
834 arc->img_arc = res_arc;
839 void remove_residual_arc(
Arc * arc)
843 Digraph::remove_arc(arc);
894 throw std::domain_error(
"Residual net is currently computed");
896 size_t n = this->get_num_arcs();
900 Arc * arc = it.get_current_arc();
901 if (not arc->is_residual)
903 insert_residual_arc(arc);
923 Arc * arc = it.get_current_arc();
924 if (arc->is_residual)
927 remove_residual_arc(arc);
932 residual_net =
false;
943 if (not residual_net)
944 throw std::domain_error(
"Residual net is not computed");
1001 bool operator () (
typename N::Arc * a)
const
1003 return (a->cap - a->flow) != 0;
1032 template <
class Net>
1035 if (not net.residual_net)
1036 throw std::domain_error(
"Residual net is not created");
1038 typename Net::Flow_Type slack = net.Infinity;
1043 typename Net::Arc * arc = it.get_current_arc();
1044 const typename Net::Flow_Type w = arc->cap - arc->flow;
1058 typename Net::Arc * arc = it.get_current_arc();
1059 typename Net::Arc * img = (
typename Net::Arc*) arc->img_arc;
1063 if (not arc->is_residual)
1065 net.increase_out_flow(net.get_src_node(arc), slack);
1066 net.increase_in_flow(net.get_tgt_node(arc), slack);
1070 net.decrease_in_flow(net.get_src_node(arc), slack);
1071 net.decrease_out_flow(net.get_tgt_node(arc), slack);
1074 I(arc->check_arc());
1103 template <
class Net>
1106 if (not net.residual_net)
1107 throw std::domain_error(
"Residual net has not been generated");
1109 return test_for_path<Net, Res_F<Net> >(net, net.get_source(), net.get_sink());
1145 template <
class Net,
template <
class,
class>
class Find_Path>
1146 typename Net::Flow_Type
1149 net.make_super_nodes();
1152 net.make_residual_net();
1154 catch (std::bad_alloc)
1156 net.unmake_super_nodes();
1160 typename Net::Node * source = net.get_source();
1161 typename Net::Node * sink = net.get_sink();
1167 if (not Find_Path<Net,
Res_F<Net> > () (net, source, sink, path))
1170 increase_flow <Net> (net, path);
1173 catch (std::bad_alloc)
1175 net.unmake_residual_net();
1176 net.unmake_super_nodes();
1180 const typename Net::Flow_Type ret_val = source->out_flow;
1181 if (not leave_residual)
1183 net.unmake_residual_net();
1184 net.unmake_super_nodes();
1219 template <
class Net>
typename Net::Flow_Type
1222 return aumenting_path_maximum_flow<Net, Find_Path_Depth_First>
1223 (net, leave_residual);
1231 template <
class Net>
class
1249 typename Net::Flow_Type
1285 template <
class Net>
typename Net::Flow_Type
1288 return aumenting_path_maximum_flow<Net, Find_Path_Breadth_First>
1289 (net, leave_residual);
1297 template <
class Net>
1315 typename Net::Flow_Type
1317 const bool & leave_residual =
false)
const
1323 template <
class Net>
static
1324 bool is_node_active(
typename Net::Node * p)
1326 return p->in_flow > p->out_flow;
1329 template <
class Net>
static
1330 long & node_height(
typename Net::Node * p) {
return NODE_COUNTER(p); }
1345 bool operator () (
typename N::Arc * a)
const
1347 return a->is_residual;
1351 template <
class Net>
static
1352 bool initial_height(Net & net,
typename Net::Node * p,
typename Net::Arc * a)
1354 node_height<Net>(p) = node_height<Net>(net.get_src_node(a)) + 1;
1358 template <
class Net>
static
1359 void init_height_in_nodes(Net & net)
1361 breadth_first_traversal <Net, Res_Arc<Net>>
1362 (net, net.get_sink(), &initial_height);
1365 template <
class Q_Type>
static
1366 void put_in_active_queue(Q_Type & q,
typename Q_Type::Item_Type & p)
1368 if (
NODE_BITS(p).get_bit(Aleph::Maximum_Flow))
1371 NODE_BITS(p).set_bit(Aleph::Maximum_Flow,
true);
1375 template <
class Q_Type>
static
1376 typename Q_Type::Item_Type get_from_active_queue(Q_Type & q)
1378 typename Q_Type::Item_Type p = q.get();
1380 I(
NODE_BITS(p).get_bit(Aleph::Maximum_Flow));
1382 NODE_BITS(p).set_bit(Aleph::Maximum_Flow,
false);
1388 template <
class Q_Type>
static
1389 void remove_from_active_queue(Q_Type & q,
typename Q_Type::Item_Type & p)
1391 NODE_BITS(p).set_bit(Aleph::Maximum_Flow,
false);
1429 template <
class Net,
class Q_Type>
typename Net::Flow_Type
1431 (Net & net,
const bool & leave_residual =
false)
1433 net.make_super_nodes();
1436 net.make_residual_net();
1437 net.reset_counter_nodes();
1439 catch (std::bad_alloc)
1441 net.unmake_super_nodes();
1445 init_height_in_nodes(net);
1446 typename Net::Node * source = net.get_source();
1447 typename Net::Node * sink = net.get_sink();
1455 typename Net::Arc * arc = it.get_current_arc();
1456 typename Net::Node * tgt = net.get_tgt_node(arc);
1457 arc->flow = tgt->in_flow = arc->cap - arc->flow;
1458 arc->img_arc->flow = 0;
1460 put_in_active_queue(q, tgt);
1463 source->out_flow = source->out_cap;
1465 while (not q.is_empty())
1467 typename Net::Node * src = get_from_active_queue(q);
1468 typename Net::Flow_Type excess = src->in_flow - src->out_flow;
1471 it.has_curr() and excess > 0; it.next())
1473 typename Net::Arc * arc = it.get_current_arc();
1474 typename Net::Node * tgt = net.get_tgt_node(arc);
1475 if (node_height<Net>(src) != node_height<Net>(tgt) + 1)
1478 const typename Net::Flow_Type flow_avail_in_arc =
1479 arc->cap - arc->flow;
1480 typename Net::Flow_Type flow_to_push =
1481 std::min(flow_avail_in_arc, excess);
1483 arc->flow += flow_to_push;
1484 arc->img_arc->flow -= flow_to_push;
1485 if (arc->is_residual)
1487 net.decrease_out_flow(tgt, flow_to_push);
1488 net.decrease_in_flow(src, flow_to_push);
1492 net.increase_out_flow(src, flow_to_push);
1493 net.increase_in_flow(tgt, flow_to_push);
1496 excess -= flow_to_push;
1498 if (is_node_active<Net>(tgt) and tgt != sink and tgt != source)
1499 put_in_active_queue(q, tgt);
1504 node_height<Net>(src)++;
1505 put_in_active_queue(q, src);
1509 const typename Net::Flow_Type ret_val = source->out_flow;
1511 if (not leave_residual)
1513 net.unmake_residual_net();
1514 net.unmake_super_nodes();
1521 net.unmake_residual_net();
1522 net.unmake_super_nodes();
1554 template <
class Net>
typename Net::Flow_Type
1556 (Net & net,
const bool & leave_residual =
false)
1567 template <
class Net>
1584 typename Net::Flow_Type
1586 const bool & leave_residual =
false)
const
1592 template <
class Net>
1595 bool operator () (
typename Net::Node * n1,
typename Net::Node * n2)
const
1597 return node_height<Net>(n1) > node_height<Net>(n2);
1632 template <
class Net>
typename Net::Flow_Type
1637 (net, leave_residual);
1645 template <
class Net>
1662 typename Net::Flow_Type
1664 const bool & leave_residual =
false)
const
1696 template <
class Net>
typename Net::Flow_Type
1723 typename Net::Flow_Type
1725 const bool & leave_residual =
false)
const
1732 template <
class Net>
static
1733 bool has_arcs_in_active_queue(
typename Net::Node * p)
1784 template <
class Net,
class QN_Type,
class QA_Type>
1785 typename Net::Flow_Type
1787 const bool & leave_residual =
false)
1789 net.make_super_nodes();
1792 net.make_residual_net();
1793 net.reset_counter_nodes();
1795 catch (std::bad_alloc)
1797 net.unmake_super_nodes();
1803 typename Net::Node * source = net.get_source();
1804 typename Net::Node * sink = net.get_sink();
1805 init_height_in_nodes(net);
1809 typename Net::Arc * arc = i.get_current_arc();
1810 typename Net::Node * tgt = net.get_tgt_node(arc);
1811 arc->flow = tgt->in_flow = arc->cap - arc->flow;
1812 arc->img_arc->flow = 0;
1817 typename Net::Arc * a = j.get_current_arc();
1818 if (node_height<Net>(tgt) ==
1819 node_height<Net>(net.get_tgt_node(a)) + 1)
1820 put_in_active_queue(q, a);
1822 put_in_active_queue(p, tgt);
1824 source->out_flow = source->out_cap;
1828 while (not q.is_empty())
1830 typename Net::Arc * arc = get_from_active_queue(q);
1831 typename Net::Node * src = net.get_src_node(arc);
1832 typename Net::Node * tgt = net.get_tgt_node(arc);
1833 if (node_height<Net>(src) != node_height<Net>(tgt) + 1)
1836 typename Net::Flow_Type excess = src->in_flow - src->out_flow;
1839 remove_from_active_queue(p, src);
1843 const typename Net::Flow_Type push =
1844 std::min(excess, arc->cap - arc->flow);
1846 arc->img_arc->flow -= push;
1847 if (arc->is_residual)
1849 net.decrease_out_flow(net.get_tgt_node(arc), push);
1850 net.decrease_in_flow(net.get_src_node(arc), push);
1854 net.increase_in_flow(net.get_tgt_node(arc), push);
1855 net.increase_out_flow(net.get_src_node(arc), push);
1859 if (is_node_active<Net>(tgt) and tgt != source and tgt != sink)
1862 it.has_curr(); it.next())
1864 typename Net::Arc * a = it.get_current_arc();
1865 if (node_height<Net>(tgt) ==
1866 node_height<Net>(net.get_tgt_node(a)) + 1)
1867 put_in_active_queue(q, a);
1870 put_in_active_queue(p, tgt);
1875 remove_from_active_queue(p, src);
1879 if (src != source and src != sink and
1880 not has_arcs_in_active_queue<Net>(src))
1882 remove_from_active_queue(p, src);
1883 node_height<Net>(src)++;
1884 put_in_active_queue(p, src);
1888 typename Net::Arc * a = it.get_current_arc();
1889 if ((node_height<Net>(src) ==
1890 node_height<Net>(net.get_tgt_node(a)) + 1)
1891 and (a->cap - a->flow > 0))
1892 put_in_active_queue(q, a);
1894 typename Net::Arc * i = a->img_arc;
1895 if ((i->cap - i->flow > 0) and
1896 (node_height<Net>(net.get_src_node(i)) ==
1897 node_height<Net>(src) + 1))
1898 put_in_active_queue(q, i);
1906 typename Net::Node * src = get_from_active_queue(p);
1907 node_height<Net>(src)++;
1908 put_in_active_queue(p, src);
1912 typename Net::Arc * a = it.get_current_arc();
1913 if ((node_height<Net>(src) ==
1914 node_height<Net>(net.get_tgt_node(a)) + 1)
1915 and (a->cap - a->flow > 0))
1916 put_in_active_queue(q, a);
1918 typename Net::Arc * i = a->img_arc;
1919 if ((i->cap - i->flow > 0) and
1920 (node_height<Net>(net.get_src_node(i)) ==
1921 node_height<Net>(src) + 1))
1922 put_in_active_queue(q, i);
1926 if (not leave_residual)
1928 net.unmake_residual_net();
1929 I(source->out_flow == sink->in_flow);
1930 net.unmake_super_nodes();
1933 return source->out_flow;
1953 template <
class Net>
typename Net::Flow_Type
1955 (Net & net,
const bool & leave_residual =
false)
1960 return generic_preflow_edge_maximum_flow <Net,Active,Stack>
1961 (net, leave_residual);
1985 typename Net::Flow_Type
1987 const bool & leave_residual =
false)
const
2013 template <
class Net>
typename Net::Flow_Type
2015 (Net & net,
const bool leave_residual =
false)
2019 return generic_preflow_edge_maximum_flow<Net, Active, Queue>
2020 (net, leave_residual);
2043 typename Net::Flow_Type
2045 const bool & leave_residual =
false)
const
2053 bool operator () (
typename Net::Arc * a1,
typename Net::Arc * a2)
const
2055 typename Net::Node * src1 = (
typename Net::Node *) a1->src_node;
2056 typename Net::Node * src2 = (
typename Net::Node *) a2->src_node;
2057 if (src1->counter == src2->counter)
2058 return a1->cap - a1->flow > a2->cap - a2->flow;
2060 return src1->counter > src2->counter;
2089 template <
class Net>
typename Net::Flow_Type
2091 (Net & net,
const bool & leave_residual =
false)
2095 return generic_preflow_edge_maximum_flow <Net, Active, Prio_Queue>
2096 (net, leave_residual);
2119 typename Net::Flow_Type
2121 const bool & leave_residual =
false)
const
2146 template <
class Net>
typename Net::Flow_Type
2148 (Net & net,
const bool & leave_residual =
false)
2152 return generic_preflow_edge_maximum_flow <Net, Active, Random_Queue>
2153 (net, leave_residual);
2183 typename Net::Flow_Type
2185 const bool & leave_residual =
false)
const
2192 static void * vs_ptr = NULL;
2194 template <
class Net>
static bool
2195 add_vertex_to_vs(Net &,
typename Net::Node * node,
typename Net::Arc*)
2212 bool operator () (
typename N::Node *,
typename N::Arc * a)
const
2214 return not a->is_residual;
2217 bool operator () (N&,
typename N::Arc * a)
const
2219 return not a->is_residual;
2222 bool operator () (
typename N::Arc * a)
const
2224 return not a->is_residual;
2260 template <
class Net,
template <
class>
class Maxflow>
2266 const bool leave_residual =
false)
2268 Maxflow <Net> () (net,
true);
2270 typename Net::Node * source = net.get_source();
2273 depth_first_traversal <Net, Res_F<Net>>
2274 (net, source, &add_vertex_to_vs);
2275 const size_t size_vt = net.get_num_nodes() - vs.
size();
2277 vt.
size() < size_vt; it.next())
2279 typename Net::Node * p = it.get_current();
2286 typename Net::Arc * arc = it.get_current();
2288 if (vt.
count(net.get_src_node(arc)) > 0 and
2289 vs.
count(net.get_tgt_node(arc)) > 0)
2295 if (arc->flow == arc->cap)
2296 if (vs.
count(net.get_src_node(arc)) > 0 and
2297 vt.
count(net.get_tgt_node(arc)) > 0)
2301 if (not leave_residual)
2303 net.unmake_residual_net();
2304 net.unmake_super_nodes();
2307 return source->out_flow;
2324 template <
class Net,
2348 return min_cut <Net, Maxflow> (net, vs, vt, cuts, cutt);
2367 static typename N::Flow_Type
min;
2369 typename N::Arc * operator () (
typename N::Node *,
typename N::Arc * arc)
2371 return arc->cap - arc->flow >=
min ? arc : NULL;
2374 typename N::Arc * operator () (
typename N::Arc * arc)
2376 return arc->cap - arc->flow >=
min ? arc : NULL;
2402 template <
class Net,
template <
class,
class>
class Find_Path>
2404 const typename Net::Flow_Type & min_slack)
2407 typename Net::Node * src = net.get_source();
2408 typename Net::Node * sink = net.get_sink();
2410 if (not net.residual_net)
2411 net.make_residual_net();
2413 return Find_Path<Net, Flow_Filter<Net>> () (net, src, sink, path);
2428 template <
class Net,
2446 const typename Net::Flow_Type & slack)
2448 return find_aumenting_path <Net, Find_Path> (net, path, slack);
2472 template <
class Net,
template <
class,
class>
class Find_Path>
2474 const typename Net::Flow_Type & min_slack)
2477 typename Net::Node * src = net.get_source();
2478 typename Net::Node * sink = net.get_sink();
2480 if (not net.residual_net)
2481 net.make_residual_net();
2483 return Find_Path<Net, Flow_Filter<Net> > () (net, sink, src, path);
2498 template <
class Net,
2516 const typename Net::Flow_Type & slack)
2518 return find_decrementing_path <Net, Find_Path> (net, path, slack);
2551 template <
class Net>
2553 const typename Net::Flow_Type & val)
2555 if (not net.residual_net)
2556 throw std::domain_error(
"Residual net is not created");
2561 typename Net::Arc * arc = it.get_current_arc();
2562 typename Net::Arc * img = (
typename Net::Arc *) arc->img_arc;
2563 if (arc->cap - arc->flow < val)
2564 throw std::domain_error(
"minimum slack of aumenting path es"
2565 " smaller than val");
2569 if (not arc->is_residual)
2571 net.increase_out_flow(net.get_src_node(arc), val);
2572 net.increase_in_flow(net.get_tgt_node(arc), val);
2576 net.decrease_in_flow(net.get_src_node(arc), val);
2577 net.decrease_out_flow(net.get_tgt_node(arc), val);
2612 template <
class Net>
2614 const typename Net::Flow_Type & val)
2616 if (not net.residual_net)
2617 throw std::domain_error(
"Residual net is not created");
2622 typename Net::Arc * arc = it.get_current_arc();
2623 typename Net::Arc * img = (
typename Net::Arc *) arc->img_arc;
2625 if (arc->cap - arc->flow < val)
2626 throw std::domain_error(
"minimum slack of decrementing path "
2627 " is smaller than val");
2631 if (not arc->is_residual)
2633 net.decrease_out_flow(get_src_node(arc), val);
2634 net.decrease_in_flow(net.get_tgt_node(arc), val);
2638 net.increase_out_flow(get_tgt_node(arc), val);
2639 net.increase_in_flow(net.get_src_node(arc), val);
2646 # endif // TPL_NETGRAPH_H
Node::Node_Type Node_Type
Tipo de atributo que almacena un nodo.
Definition: tpl_netgraph.H:221
Definition: tpl_netgraph.H:2051
Definition: tpl_agraph.H:554
void unmake_residual_net()
Definition: tpl_netgraph.H:919
virtual Arc * insert_arc(Node *src_node, Node *tgt_node, const typename Arc::Arc_Type &arc_info)
Definition: tpl_netgraph.H:617
Definition: tpl_netgraph.H:2161
Net::Flow_Type generic_preflow_vertex_push_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1431
virtual Arc * insert_arc(Node *src_node, Node *tgt_node, const typename Arc::Arc_Type &arc_info, const Flow_Type &cap, const Flow_Type &flow)
Definition: tpl_netgraph.H:517
Definition: tpl_netgraph.H:2361
Definition: tpl_netgraph.H:2028
Flow_Type get_out_cap(Node *node) const
Retorna la capacidad total de salida del nodo node.
Definition: tpl_netgraph.H:234
Arc * connect_arc(Arc *arc)
Definition: tpl_netgraph.H:558
Definition: tpl_netgraph.H:1298
Node * insert_node(Node *p)
Definition: tpl_netgraph.H:474
static N::Flow_Type min
Valor de flujo cota a filtrar.
Definition: tpl_netgraph.H:2367
virtual Arc * insert_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap)
Definition: tpl_netgraph.H:595
Definition: tpl_netgraph.H:66
Net::Flow_Type random_first_preflow_edge_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:2148
Net::Flow_Type ford_fulkerson_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1220
void unmake_super_sink()
Definition: tpl_netgraph.H:383
NodeT Node
Tipo de node.
Definition: tpl_netgraph.H:215
F_Type Flow_Type
Tipo que representa el flujo.
Definition: tpl_netgraph.H:146
Definition: tpl_netgraph.H:2104
Definition: tpl_dynDlist.H:26
Definition: tpl_graph.H:751
Definition: tpl_netgraph.H:2430
Node * get_sink()
Retorna un nodo sumidero de la red.
Definition: tpl_netgraph.H:422
Arc * get_residual_arc(Arc *a)
Obtiene el arco residual de a.
Definition: tpl_netgraph.H:941
Definition: tpl_netgraph.H:1568
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:2044
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:242
Definition: tpl_netgraph.H:1708
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:2120
bool is_sink(Node *node)
Retorna true si node es sumidero.
Definition: tpl_netgraph.H:254
void disconnect_arc(Arc *arc)
Definition: tpl_netgraph.H:678
Definition: tpl_find_path.H:158
Definition: tpl_dynListStack.H:20
Net_Arc * img_arc
apunta al arco reflejo
Definition: tpl_netgraph.H:85
void decrease_flow(Net &net, Path< Net > &path, const typename Net::Flow_Type &val)
Definition: tpl_netgraph.H:2613
ArcT Arc
Tipo de arco.
Definition: tpl_netgraph.H:212
Net_Graph(Digraph &digraph)
Definition: tpl_netgraph.H:706
Aleph::set< Node * > & get_sink_nodes()
Retorna el conjunto de nodos sumidero que contiene la red.
Definition: tpl_netgraph.H:312
Definition: tpl_dynListQueue.H:22
iterator begin()
Retorna un iterador posicionado al primer elemento del conjunto.
Definition: Set.H:459
Definition: tpl_netgraph.H:1341
Definition: tpl_netgraph.H:49
#define NODE_COUNTER(p)
Definition: aleph-graph.H:226
size_type erase(const T &value)
Definition: Set.H:604
Net::Flow_Type priority_first_preflow_edge_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:2091
bool is_connected(Node *node) const
Definition: tpl_netgraph.H:259
bool check_node(Node *node)
Definition: tpl_netgraph.H:266
virtual void remove_arc(Arc *arc)
Elimina de la red el arco arc.
Definition: tpl_netgraph.H:648
Net_Graph(Net_Graph &net)
Definition: tpl_netgraph.H:715
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:1663
bool is_source(Node *node)
Retorna true si node es fuente.
Definition: tpl_netgraph.H:251
void increase_flow(Net &net, Path< Net > &path, const typename Net::Flow_Type &val)
Definition: tpl_netgraph.H:2552
void make_super_sink()
Definition: tpl_netgraph.H:358
bool find_decrementing_path(Net &net, Path< Net > &path, const typename Net::Flow_Type &min_slack)
Definition: tpl_netgraph.H:2473
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:275
Flow_Type flow_value()
Definition: tpl_netgraph.H:809
void unmake_super_source()
Definition: tpl_netgraph.H:344
void make_residual_net()
Definition: tpl_netgraph.H:889
Net::Flow_Type depth_first_preflow_edge_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1955
Definition: tpl_dynBinHeap.H:26
Node * get_source()
Retorna un nodo fuente de la red.
Definition: tpl_netgraph.H:419
bool has_aumenting_path(Net &net)
Definition: tpl_netgraph.H:1104
Definition: tpl_netgraph.H:2208
Definition: tpl_graph.H:26
Definition: tpl_agraph.H:13
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:1316
bool is_residual
indica si el arco es o no residual
Definition: tpl_netgraph.H:88
virtual Arc * insert_arc(Node *src_node, Node *tgt_node)
Definition: tpl_netgraph.H:642
void set_flow(Arc *arc, const Flow_Type &flow)
Definition: tpl_netgraph.H:750
void make_super_source()
Definition: tpl_netgraph.H:319
std::pair< iterator, bool > insert(const T &value)
Definition: Set.H:488
const Flow_Type & get_flow(Arc *arc) const
retorna el valor de capacidad del arco.
Definition: tpl_netgraph.H:768
Net::Flow_Type edmonds_karp_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1286
Arc::Flow_Type Flow_Type
Tipo que representa la capacidad y el flujo.
Definition: tpl_netgraph.H:218
size_t get_in_degree(Node *node) const
Definition: tpl_netgraph.H:238
Arc::Arc_Type Arc_Type
Tipo de atributo que almacena un arco.
Definition: tpl_netgraph.H:224
Net::Flow_Type operator()(Net &net, Aleph::set< typename Net::Node * > &vs, Aleph::set< typename Net::Node * > &vt, DynDlist< typename Net::Arc * > &cuts, DynDlist< typename Net::Arc * > &cutt)
Definition: tpl_netgraph.H:2342
Flow_Type out_cap
Capacidad total de salida (suma de caps arcos salida)
Definition: tpl_netgraph.H:152
Definition: tpl_random_queue.H:23
bool find_aumenting_path(Net &net, Path< Net > &path, const typename Net::Flow_Type &min_slack)
Definition: tpl_netgraph.H:2403
const Flow_Type & get_cap(Arc *arc) const
Retorna el valor de flujo de un arco.
Definition: tpl_netgraph.H:771
bool with_super_source
true si a la red se le ha añadido un supra fuente.
Definition: tpl_netgraph.H:812
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
bool with_super_sink
true si a la red se le ha añadido un supra sumidero.
Definition: tpl_netgraph.H:815
Flow_Type get_out_flow(Node *node) const
Retorna el valor de flujo de salida del nodo.
Definition: tpl_netgraph.H:245
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:1724
Net::Flow_Type random_preflow_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1697
Net::Flow_Type min_cut(Net &net, Aleph::set< typename Net::Node * > &vs, Aleph::set< typename Net::Node * > &vt, DynDlist< typename Net::Arc * > &cuts, DynDlist< typename Net::Arc * > &cutt, const bool leave_residual=false)
Definition: tpl_netgraph.H:2261
Flow_Type get_in_flow(Node *node) const
Retorna el valor de flujo de entrada del nodo.
Definition: tpl_netgraph.H:248
Definition: tpl_netgraph.H:2500
void make_super_nodes()
Definition: tpl_netgraph.H:396
Flow_Type in_cap
Capacidad total de entrada (suma de caps arcos entrada)
Definition: tpl_netgraph.H:155
Definition: tpl_agraph.H:130
Net::Flow_Type generic_preflow_edge_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1786
Net_Node(Net_Node *net_node)
Definition: tpl_netgraph.H:179
bool has_current_arc() const
Definition: tpl_graph.H:1908
#define NODE_BITS(p)
Definition: aleph-graph.H:221
Definition: tpl_netgraph.H:2326
void set_cap(Arc *arc, const Flow_Type &cap)
Coloca valor de capacidad a un arco.
Definition: tpl_netgraph.H:731
Aleph::set< Node * > & get_src_nodes()
Retorna el conjunto de nodos fuente que contiene la red.
Definition: tpl_netgraph.H:309
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:1986
size_t get_out_degree(Node *node) const
Definition: tpl_netgraph.H:242
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:1585
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:1250
Net::Flow_Type fifo_preflow_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1556
bool operator()(Net &net, Path< Net > &path, const typename Net::Flow_Type &slack)
Definition: tpl_netgraph.H:2445
Net::Flow_Type aumenting_path_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1147
size_type count(const T &value)
Definition: Set.H:373
bool operator()(Net &net, Path< Net > &path, const typename Net::Flow_Type &slack)
Definition: tpl_netgraph.H:2515
Definition: tpl_netgraph.H:205
Definition: tpl_netgraph.H:1593
Definition: tpl_graph.H:814
Definition: tpl_netgraph.H:1231
bool check_arc() const
Definition: tpl_netgraph.H:82
size_t in_degree
Cantidad de arcos entrantes.
Definition: tpl_netgraph.H:149
Flow_Type in_flow
Valor de flujo entrante.
Definition: tpl_netgraph.H:161
Definition: tpl_netgraph.H:1969
void copy_graph(GT >gt, GT &gsrc, const bool cookie_map=false)
Definition: tpl_graph.H:2505
Definition: tpl_netgraph.H:1646
F_Type Flow_Type
Tipo que representa el flujo.
Definition: tpl_netgraph.H:71
Node * insert_node()
Definition: tpl_netgraph.H:461
bool is_there_residual_net() const
Retorna true si la red residual está creada; false de lo contrario.
Definition: tpl_netgraph.H:938
Node * insert_node(const Node_Type &node_info)
Definition: tpl_netgraph.H:434
virtual void remove_node(Node *p)
Elimina un nodo de una red de flujo junto con todos sus arcos.
Definition: tpl_netgraph.H:697
Flow_Type get_in_cap(Node *node) const
Retorna la capacidad total de entrada del nodo node.
Definition: tpl_netgraph.H:231
Net::Flow_Type operator()(Net &net, const bool &leave_residual=false) const
Definition: tpl_netgraph.H:2184
size_type size()
Retorna la cantidad de elementos que contiene el conjunto.
Definition: Set.H:275
Flow_Type cap
valor de capacidad
Definition: tpl_netgraph.H:74
void unmake_super_nodes()
Definition: tpl_netgraph.H:412
iterator end()
Retorna un iterador posicionado al último elemento del conjunto.
Definition: Set.H:465
Net_Node(const Node_Info &node_info)
Definition: tpl_netgraph.H:170
Definition: tpl_graph.H:694
Definition: tpl_dynSetTree.H:1174
bool check_network()
Definition: tpl_netgraph.H:797
bool is_empty() const
retorna true si this está vacía
Definition: dlink.H:127
Net::Flow_Type breadth_first_preflow_edge_maximum_flow(Net &net, const bool leave_residual=false)
Definition: tpl_netgraph.H:2015
T remove_first()
Definition: tpl_dynDlist.H:218
Definition: tpl_graph.H:1868
Net::Flow_Type heap_preflow_maximum_flow(Net &net, const bool &leave_residual=false)
Definition: tpl_netgraph.H:1633
T & insert(const T &item)
Definition: tpl_dynDlist.H:86
Definition: tpl_netgraph.H:141
T & append(const T &item)
Definition: tpl_dynDlist.H:106
Flow_Type flow
valor de flujo
Definition: tpl_netgraph.H:77
Flow_Type out_flow
Valor de flujo saliente.
Definition: tpl_netgraph.H:158