56# include <type_traits>
82 template <
typename Arc_Info,
typename Flow_Type>
113 template <
typename Arc_Info,
typename F_Type =
double>
153 *
static_cast<Base *
>(
this) = arc;
166 assert(a->src_node == src
or a->tgt_node == src);
167 return a->tgt_node == src;
197 return a->cap - a->flow > 0;
214 return static_cast<typename Net::Node *
>(a->src_node ==
p ? a->tgt_node : a->src_node);
223 template <
class Net,
class Show_Arc = Dft_Show_Arc<Net>>
243 template <
typename Node_Info = Empty_Class>
258 template <
class NodeT = Net_Node<Empty_Class>,
259 class ArcT = Net_Arc<Empty_Class,
double>>
319 sum += it.get_curr()->cap;
328 sum += it.get_curr()->cap;
349 sum += it.get_curr()->flow;
358 sum += it.get_curr()->flow;
390 const auto eps = std::max(std::abs(out_flow), std::abs(in_flow)) * 1e-9;
391 const auto nearly_zero = [eps](
auto x) {
return std::abs(x) <= eps; };
392 const auto nearly_equal = [eps](
auto a,
auto b) {
return std::abs(a - b) <= eps; };
400 return nearly_equal(out_flow, in_flow);
464 <<
"network has no source nodes (it has cycles)";
499 <<
"network has no sink nodes (it has cycles)";
533 catch (
const std::bad_alloc &)
577 template <
typename...
Args>
609 const typename Arc::Arc_Type & arc_info =
Arc_Type())
624 template <
typename...
Args>
668 typename = std::enable_if_t<!std::is_same<T, Flow_Type>::value &&
669 !std::is_arithmetic_v<T>>>
673 return insert_arc(src_node, tgt_node, 0, 0, arc_info);
721 using Pair = std::pair<typename Net_Graph::Arc *, typename Net_Graph::Arc *>;
722 zip(this->
arcs(), net.
arcs()).for_each([](
const Pair & p)
725 auto asrc = p.second;
746 :
Infinity(std::numeric_limits<typename Arc::Flow_Type>::max()),
797 it.get_curr()->flow = 0;
825 <<
"network has no source or sink nodes";
852 return s <<
"Path is Empty";
860 s <<
"(" << a->cap <<
"," << a->flow <<
")"
874 using Parc = std::tuple<typename Net::Arc *, bool>;
884 using SemiPath = std::tuple<bool, typename Net::Flow_Type, DynList<Parc<Net>>>;
892 std::cout <<
"Semi path is Empty";
903 std::cout << s->get_info() <<
"(" << a->flow <<
"," << a->cap <<
")"
904 << t->get_info() <<
" " << (
get<1>(
pa) ?
"Normal" :
"Reduced")
921 using Tuple = std::tuple<typename Net::Node *, typename Net::Arc *>;
927 Tuple t = it.get_tuple_ne();
938 auto t = it.get_tuple_ne();
973 auto p = it.get_curr();
1006 auto p = it.get_curr();
1013 assert(arc->check_arc());
1024 template <
class Net,
template <
typename T>
class Q>
1040 for (Itor it(start); it.has_curr(); it.next_ne())
1042 auto a = it.get_curr();
1072 for (Itor it(curr); it.has_curr(); it.next_ne())
1074 auto a = it.get_curr();
1111 while (curr != start)
1133 auto m = std::numeric_limits<typename Net::Flow_Type>::max();
1143 auto arc = it.get_curr();
1144 if ((arc->src_node == s
and arc->tgt_node == t)
or
1145 (arc->src_node == t
and arc->tgt_node == s))
1160 bool normal = a->tgt_node == t;
1162 m = std::min(m,
slack);
1167 return std::make_tuple(
true, m, std::move(
semi_path));
1225 template <
class Net>
1230 template <
class Net>
1241 template <
class Net,
template <
typename T>
class Q>
1252 template <
class Net>
1261 template <
class Net>
1277 template <
class Net,
template <
typename T>
class Q>
1286 template <
class Net>
1296 template <
class Net>
1313 template <
class Net,
template <
typename T>
class Q>
1323 template <
class Net>
1333 template <
class Net>
1343 template <
class Net>
1361 template <
class Net>
1384 template <
class Net>
1388 template <
class Net>
1392 template <
class Net>
1406 auto arc =
rnet.insert_arc(src, tgt);
1407 auto dup =
rnet.insert_arc(tgt, src);
1411 arc->flow = a->flow;
1414 dup->cap = arc->cap;
1415 dup->flow = arc->cap - arc->flow;
1420 template <
class Rnet>
1423 Res_F(
typename Rnet::Node *)
noexcept {}
1428 return a->cap > a->flow;
1436 template <
class Net>
1448 auto p = it.get_curr();
1449 auto q =
rnet.insert_node();
1461 return std::make_tuple(std::move(
rnet),
1467 template <
class Rnet>
1471 for (
typename Rnet::Arc_Iterator it(
rnet); it.has_curr(); it.next_ne())
1473 auto arc = it.get_curr();
1474 auto img = arc->img;
1477 img->flow = arc->flow;
1488 template <
class Net,
1493 <<
"Network is not single source and single sink";
1522 template <
class Net>
1533 template <
class Net>
1550 template <
class Net>
1561 template <
class Net>
1572 template <
class Net>
1580 template <
class Rnet>
1584 return p->in_flow != p->out_flow;
1589 template <
class Net>
1595 template <
class Net>
1611 template <
class Q_Type>
1623 template <
class Q_Type>
1635 template <
class Q_Type>
1659 template <
class Net,
class Q_Type>
1664 <<
"Network is not single source and single sink";
1672 constexpr auto Max = std::numeric_limits<long>::max();
1676 for (Itor it(source); it.has_curr(); it.next_ne())
1678 auto arc = it.get_curr();
1679 arc->flow = arc->cap;
1690 for (Itor it(src); it.has_curr()
and excess > 0; it.next_ne())
1692 auto arc = it.get_curr();
1713 if (tgt != source
and tgt != sink)
1735 template <
class Rnet>
1740 exec(sink, [&
rnet](
typename Rnet::Node *p,
typename Rnet::Arc *a)
1756 template <
class Net>
1769 template <
class Net>
1782 template <
class Net>
1798 template <
class Net>
1811 template <
class Net>
1828 template <
class Net>
1841 template <
class Net>
1863 template <
class Net,
template <
class>
class Maxflow>
1887 if (
auto p = it.get_curr(); p->state() ==
Unprocessed)
1893 auto arc = it.get_curr();
1902 if (arc->flow == arc->cap)
1916 template <
class Net,
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
WeightedDigraph::Node Node
virtual void remove_arc(Arc *a)
virtual Node * insert_node(Node *p)
Arc * disconnect_arc(Arc *arc)
Dlink & get_arc_dlink() noexcept
Returns reference to internal arc Dlink for sorting operations.
virtual void remove_node(Node *p)
Arc * insert_arc(Node *src, Node *tgt, void *a)
Arc * connect_arc(Arc *arc)
Dlink & get_node_dlink() noexcept
Returns reference to internal node Dlink for sorting operations.
bool has_curr() const noexcept
Return true the iterator has current node.
Filtered iterator on directed graphs.
bool has_curr() const noexcept
Return true the iterator has an current arc.
Generic directed graph (digraph) wrapper template.
typename BaseGraph::Node Node
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
Dynamic heap of elements of type T ordered by a comparison functor.
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
Dynamic queue of elements of generic type T based on single linked list.
Iterator on the items of list.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
Dynamic set backed by balanced binary search trees with automatic memory management.
const Key & get_item() const
Returns any element of the set.
const size_t & size() const
Returns the cardinality of the set.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
void swap(DynSetTree &dset) noexcept(noexcept(tree.swap(dset.tree)) and noexcept(std::swap(num_nodes, dset.num_nodes)) and noexcept(std::swap(arena_allocator, dset.arena_allocator)))
Exchange all elements of this set with dset in constant time (and extremely fast).
size_t remove(const Key &key)
Removes a key from the dynamic set.
bool contains(const Key &key) const
bool is_empty() const
returns true if the set is empty
Generic filter iterator wrapper.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
Augmenting-path search over a directed network.
Path< Net > operator()(typename Net::Node *start, typename Net::Node *end, typename Net::Flow_Type min_slack=0)
Find a concrete Path with at least min_slack.
Find_Aumenting_Path(const Net &__g)
Construct a finder for net.
Net::Flow_Type semi_path(typename Net::Node *start, typename Net::Node *end, DynList< Parc< Net > > &semi_path, const typename Net::Flow_Type &min_slack=0)
Fill semi_path and return the slack value.
Path< Net > find(typename Net::Node *start, typename Net::Node *end, const typename Net::Flow_Type &min_slack=typename Net::Flow_Type{0})
Build a Path from start to end with minimum slack.
SemiPath< Net > find_dec_path(typename Net::Flow_Type min_slack=0.0)
Find a decrementing semi-path with at least min_slack.
SemiPath< Net > find_aum_path(typename Net::Flow_Type min_slack=0.0)
Find an augmenting semi-path with at least min_slack.
SemiPath< Net > find_path(typename Net::Node *start, typename Net::Node *end, typename Net::Flow_Type min_slack=typename Net::Flow_Type{0})
Build a SemiPath from start to end with minimum slack.
Net::Node * search(typename Net::Node *start, typename Net::Node *end, typename Net::Flow_Type min_slack)
bool has_curr() const noexcept
Return true if iterator has current item.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
Filtered iterator on the nodes of a graph.
Iterator on nodes and arcs of a path.
Node * get_current_node_ne() const noexcept
Node * get_current_node() const
Return the current node of a path.
Arc * get_current_arc_ne() const noexcept
bool has_current_arc() const noexcept
Return true if iterator has current arc.
bool is_empty() const noexcept
Return true if the path is empty.
const GT & get_graph() const noexcept
Get a constant reference to the graph.
bool all(Operation &operation) const
Check if all the elements of container satisfy a condition.
void reset_arcs() const
Reset all the arcs of graph (the control bits, the state, the counter and the cookie)
Container< Arc * > arcs() const
Return a container with all the arcs of the graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
std::tuple< Arc *, Node * > ArcPair
Pair of arc and node (topologically related)
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
void common_swap(GT &g) noexcept
size_t out_degree(Node *p) const noexcept
Compute the output degree of a node.
constexpr size_t vsize() const noexcept
void reset_nodes() const
Reset all the nodes of graph (the control bits, the state, the counter and the cookie)
size_t in_degree(Node *p) const noexcept
Compute the input degree of a node.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Container< Node * > nodes() const
Return a container with all the nodes of the graph.
Traverse a graph depth-first or breadth-first and execute a visit function.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Graph traversal algorithms (DFS, BFS).
const unsigned char Processed
The node or arc has already been processed.
const unsigned char Processing
The node are being processed; probably it is inside a queue, stack or heap.
#define NODE_COUNTER(p)
Get the counter of a node.
#define NODE_COOKIE(p)
Return the node cookie
const unsigned char Unprocessed
The node have not bees processed.
#define NODE_BITS(p)
Get the control bits of a node.
void copy_graph(GT >gt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
Net_Graph< Net_Node< string >, Net_Arc< Empty_Class, FlowType > > Net
Main namespace for Aleph-w library functions.
SemiPath< Net > find_aumenting_semi_path_dfs(const Net &net, const typename Net::Flow_Type &slack)
Find an augmenting semi-path using DFS.
static void remove_from_active_queue(Q_Type &q, typename Q_Type::Item_Type &p)
Remove a node from the active queue and clear its queue mark.
Net::Flow_Type remaining_flow(typename Net::Node *src, typename Net::Arc *a) noexcept
Return the remaining flow of a as seen from src.
void decrease_flow(Net &net, const DynList< Parc< Net > > &semi_path, const typename Net::Flow_Type slack)
Decrease flow along a semi-path by a given slack.
Net::Flow_Type edmonds_karp_maximum_flow(Net &net)
Maximize flow using the Edmonds-Karp algorithm.
Net::Flow_Type generic_preflow_vertex_push_maximum_flow(Net &net)
Generic preflow-push maximum flow (vertex-oriented).
bool is_residual(typename Net::Node *src, typename Net::Arc *a) noexcept
Return true if arc a is residual with respect to src.
Net::Flow_Type random_preflow_maximum_flow(Net &net)
Preflow-push maximum flow using a random active-node queue.
Path< Net > find_aumenting_path_dfs(const Net &net, const typename Net::Flow_Type &min_slack)
Find an augmenting path using DFS.
SemiPath< Net > find_decrementing_path(const Net &net, const typename Net::Flow_Type &slack)
Find a decrementing semi-path using DFS or BFS based on Q.
Net::Flow_Type heap_preflow_maximum_flow(Net &net)
Preflow-push maximum flow using a height-ordered heap.
SemiPath< Net > find_aumenting_semi_path_bfs(const Net &net, const typename Net::Flow_Type &slack)
Find an augmenting semi-path using BFS.
DynList< std::pair< typename Container1::Item_Type, typename Container2::Item_Type > > zip(const Container1 &a, const Container2 &b)
Zip two containers into a list of pairs.
static Q_Type::Item_Type get_from_active_queue(Q_Type &q)
Dequeue an active node and clear its queue mark.
Net::Flow_Type increase_flow(Net &net, const Path< Net > &path)
Increase flow along an augmenting path.
std::decay_t< typename HeadC::Item_Type > T
SemiPath< Net > find_decrementing_path_dfs(const Net &net, const typename Net::Flow_Type &slack)
Find a decrementing semi-path using DFS.
void create_residual_arc(const Net &net, PP_Res_Net< Net > &rnet, typename Net::Arc *a)
Create residual arcs for a in the residual network.
std::tuple< PP_Res_Net< Net >, typename PP_Res_Net< Net >::Node *, typename PP_Res_Net< Net >::Node * > preflow_create_residual_net(Net &net)
Build the residual network for preflow-push algorithms.
Path< Net > find_aumenting_path_bfs(const Net &net, const typename Net::Flow_Type &min_slack)
Find an augmenting path using BFS.
static long & node_height(typename Net::Node *p)
Access the height label stored in NODE_COUNTER.
std::tuple< bool, typename Net::Flow_Type, DynList< Parc< Net > > > SemiPath
Semi-path tuple:
SemiPath< Net > find_aumenting_semi_path(const Net &net, const typename Net::Flow_Type &slack)
Find an augmenting semi-path using DFS or BFS based on Q.
Net::Flow_Type fifo_preflow_maximum_flow(Net &net)
Preflow-push maximum flow using a FIFO queue of active nodes.
Path< Net > find_aumenting_path(const Net &net, const typename Net::Flow_Type &min_slack)
Find an augmenting path using DFS or BFS based on Q.
static bool is_node_active(const Net &net, typename Net::Node *p)
Return true if p has excess flow in net.
Net::Flow_Type ford_fulkerson_maximum_flow(Net &net)
Maximize flow using the Ford-Fulkerson algorithm.
static void init_height_in_nodes(Net &net)
Initialize node heights with BFS distance to the sink.
SemiPath< Net > find_decrementing_path_bfs(const Net &net, const typename Net::Flow_Type &slack)
Find a decrementing semi-path using BFS.
void update_flow(const Rnet &rnet)
Propagate residual arc flows back to their original arcs.
static void put_in_active_queue(Q_Type &q, typename Q_Type::Item_Type &p)
Enqueue an active node if it is not already enqueued.
Net::Flow_Type aumenting_path_maximum_flow(Net &net)
Maximize flow using repeated augmenting-path searches.
Net::Flow_Type min_cut(Net &net, DynSetTree< typename Net::Node * > &vs, DynSetTree< typename Net::Node * > &vt, DynList< typename Net::Arc * > &cuts, DynList< typename Net::Arc * > &cutt)
Compute max flow and the corresponding minimum cut.
std::tuple< typename Net::Arc *, bool > Parc
Arc entry for a semi-path.
DynList< T > maps(const C &c, Op op)
Classic map operation.
void print(const DynList< Parc< Net > > &sp)
Print a semi-path to stdout.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Filtered iterator on all the arcs of a graph.
Iterator over arcs of a graph.
Compare nodes by height (higher first).
bool operator()(typename Net::Node *n1, typename Net::Node *n2) const
Functor wrapper for edmonds_karp_maximum_flow().
Net::Flow_Type operator()(Net &net) const
Invoke edmonds_karp_maximum_flow().
Empty placeholder class with no data members.
Functor wrapper for fifo_preflow_maximum_flow().
Net::Flow_Type operator()(Net &net) const
Invoke fifo_preflow_maximum_flow().
Functor wrapper for ford_fulkerson_maximum_flow().
Net::Flow_Type operator()(Net &net) const
Invoke ford_fulkerson_maximum_flow().
Functor wrapper for heap_preflow_maximum_flow().
Net::Flow_Type operator()(Net &net) const
Invoke heap_preflow_maximum_flow().
Functor wrapper for min_cut().
Net::Flow_Type operator()(Net &net, DynSetTree< typename Net::Node * > &vs, DynSetTree< typename Net::Node * > &vt, DynList< typename Net::Arc * > &cuts, DynList< typename Net::Arc * > &cutt)
Invoke min_cut().
Arc info extension that stores capacity and flow values.
Flow_Type flow
Flow value.
Flow_Type cap
Capacity value.
Net_Arc_Info()=default
Default constructor.
Arc of a flow network implemented with adjacency lists.
bool check_arc() const noexcept
Return true if flow satisfies 0 <= flow <= cap.
Net_Arc()
Default constructor.
Flow_Type cap
Capacity value.
Net_Arc(const Arc_Info &info)
Construct from arc info.
Net_Arc & operator=(const Net_Arc &arc)
Copy assignment.
Flow_Type flow
Flow value.
Net_Arc(const Net_Arc &arc)
Copy constructor.
Ftype Flow_Type
Type representing flow, capacity, and cost values.
Arc filter for residual traversal in flow networks.
Net::Node * get_node(typename Net::Arc *a) const noexcept
Return the opposite endpoint of arc a with respect to p.
Net_Filt(typename Net::Node *s=nullptr) noexcept
Build a filter rooted at node s.
void set_cookie(void *__cookie) noexcept
Store an opaque cookie for compatibility with other iterators.
bool operator()(typename Net::Arc *a) const noexcept
Return true if arc a has residual capacity with respect to p.
Flow network implemented with adjacency lists.
void unmake_super_source() noexcept
Restore a super-source network to its original multi-source form.
Flow_Type get_out_flow(Node *node) const noexcept
Return total outgoing flow of node.
typename Arc::Arc_Type Arc_Type
Arc info type.
Node * insert_node(const Node_Type &node_info)
Insert a new node by copying node_info.
void set_cap(Arc *arc, const Flow_Type &cap)
Set the capacity of an arc.
const DynSetTree< Node * > & get_sink_nodes() const noexcept
Return the set of sink nodes.
Node * insert_node(Node_Type &&info)
Insert a new node by moving info.
Net_Graph & operator=(const Net_Graph &net)
Copy-assign a network. Throws bad_alloc on allocation failure.
bool check_network() const
Validate flow-conservation and capacity constraints.
bool is_connected(Node *p) const noexcept
Return true if p is connected (used for validation).
bool with_super_sink
True if the network has a super-sink.
const DynSetTree< Node * > & get_src_nodes() const noexcept
Return the set of source nodes.
typename Node::Node_Type Node_Type
Node info type.
Arc * connect_arc(Arc *arc)
Connect a previously disconnected arc.
Net_Graph()
Default constructor.
Net_Graph(const Net_Graph &net)
Copy-construct a network. Throws bad_alloc on allocation failure.
Node * emplace_node(Args &&... args)
Construct a node in-place and insert it into the network.
void unmake_super_sink() noexcept
Restore a super-sink network to its original multi-sink form.
void remove_arc(Arc *arc) override
Remove arc arc from the network.
void set_flow(Arc *arc, const Flow_Type &flow)
Set the flow of an arc. Throws if flow exceeds capacity.
Node * insert_node(Node *p)
Insert a node by copying another node.
Arc * insert_arc(Node *src_node, Node *tgt_node, const T &arc_info=Arc_Type())
Insert an arc with zero capacity and flow.
void make_super_source()
Convert a multi-source network into a single super-source network.
void make_super_sink()
Convert a multi-sink network into a single super-sink network.
size_t get_out_degree(Node *p) const noexcept
Return the out-degree of p (number of outgoing arcs).
Array_Graph< NodeT, ArcT > Base
constexpr bool is_single_source() const noexcept
Return true if the network has a single source.
Node * register_node(Node *p)
Insert p into source/sink sets with rollback on failure.
Flow_Type total_sink_in_flow() const
Return total incoming flow to all sinks.
bool is_source(Node *node) const noexcept
Return true if node is a source.
Node * get_source() const
Return an arbitrary source node.
friend std::ostream & operator<<(std::ostream &s, const Path< Net_Graph > &path)
Stream a path with arc (cap,flow) tuples.
Flow_Type get_out_cap(Node *node) const noexcept
Return total outgoing capacity of node.
Arc * insert_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap, const Flow_Type &flow, const typename Arc::Arc_Type &arc_info=Arc_Type())
Insert a capacitated arc with an initial flow.
DynSetTree< Node * > src_nodes
void disconnect_arc(Arc *arc) noexcept
Disconnect arc arc from the graph without deleting it.
bool with_super_source
True if the network has a super-source.
Arc * insert_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap)
Insert an arc with capacity cap and zero flow.
DynList< Node * > out_nodes(Node *p) const noexcept
Return nodes reachable from p through outgoing arcs.
void unmake_super_nodes()
Restore a super-source/super-sink network to its original form.
DynList< Arc * > out_arcs(Node *p) const noexcept
Return arcs outgoing from p (as a DynList).
Flow_Type total_source_out_flow() const
Return total outgoing flow from all sources.
Flow_Type get_in_cap(Node *node) const noexcept
Return total incoming capacity of node.
Flow_Type get_in_flow(Node *node) const noexcept
Return total incoming flow of node.
Node * get_sink() const
Return an arbitrary sink node.
bool is_sink(Node *node) const noexcept
Return true if node is a sink.
Flow_Type flow_value() const
Return the total flow value of the network.
typename Arc::Flow_Type Flow_Type
Capacity/flow numeric type.
void remove_node(Node *p) noexcept override
Remove node p and all its arcs from the network.
constexpr bool is_single_sink() const noexcept
Return true if the network has a single sink.
Net_Graph & operator=(Net_Graph &&other) noexcept
Move-assign a network. O(1) operation.
Arc * emplace_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap, const Flow_Type &flow, Args &&... args)
Construct arc info in-place and insert the arc.
void make_super_nodes()
Convert a multi-source/multi-sink network into super-source/super-sink.
DynSetTree< Node * > sink_nodes
DynList< Node * > in_nodes(Node *p) const noexcept
Return nodes that can reach p through incoming arcs.
Net_Graph(Net_Graph &&other) noexcept
Move-construct a network. O(1) operation.
const Flow_Type & get_cap(Arc *arc) const noexcept
Return the capacity value of an arc.
const Flow_Type & get_flow(Arc *arc) const noexcept
Return the flow value of an arc.
DynList< Arc * > in_arcs(Node *p) const noexcept
Return arcs incoming to p (as a DynList).
Node * insert_node()
Insert a new node with default info.
void reset()
Reset all arc flows to zero.
bool check_node(Node *node) const noexcept
Return true if node satisfies flow conservation constraints.
size_t get_in_degree(Node *p) const noexcept
Return the in-degree of p (number of incoming arcs).
void swap(Net_Graph &other) noexcept
Swap contents with another network. O(1) operation.
Filtered iterator of adjacent arcs of a node.
Residual node used by preflow-push algorithms.
PP_Res_Node()
Default constructor.
PP_Res_Node(const Empty_Class &info)
Constructor from node info.
PP_Res_Node(Empty_Class &&info)
Move constructor from node info.
Functor wrapper for random_preflow_maximum_flow().
Net::Flow_Type operator()(Net &net) const
Invoke random_preflow_maximum_flow().
Residual arc filter: keep arcs with residual capacity.
Res_F(typename Rnet::Node *) noexcept
bool operator()(typename Rnet::Arc *a) const
__Res_Arc(const Empty_Class &info)
Constructor from arc info.
bool is_residual() const
Return true if this is a residual arc.
__Res_Arc(Empty_Class &&info)
Move constructor from arc info
__Res_Arc()
Default constructor.
Dynamic binary heap with node-based storage.
Dynamic doubly linked list implementation.
Dynamic stack implementation based on linked lists.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.
Path finding algorithms in graphs.
Utility algorithms and operations for graphs.
Random access queue (bag) with O(1) random pop.