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);
412 it.has_curr(); it.next_ne())
422 it.has_curr(); it.next_ne())
464 <<
"network has no source nodes (it has cycles)";
468 it.has_curr(); it.next_ne())
469 sources.
append(it.get_curr());
499 <<
"network has no sink nodes (it has cycles)";
503 it.has_curr(); it.next_ne())
533 catch (
const std::bad_alloc &)
577 template <
typename...
Args>
609 const typename Arc::Arc_Type & arc_info =
Arc_Type())
624 template <
typename...
Args>
669 requires (
not std::is_same_v<Arc_Type, Flow_Type>
and
670 not std::is_arithmetic_v<Arc_Type>)
672 return insert_arc(src_node, tgt_node, 0, 0, arc_info);
720 using Pair = std::pair<typename Net_Graph::Arc *, typename Net_Graph::Arc *>;
721 zip(this->
arcs(), net.
arcs()).for_each([](
const Pair & p)
724 auto asrc = p.second;
745 :
Infinity(std::numeric_limits<typename Arc::Flow_Type>::max()),
796 it.get_curr()->flow = 0;
816 this->
arcs().all([](
Arc *a) {
return a->check_arc(); })
and
824 <<
"network has no source or sink nodes";
851 return s <<
"Path is Empty";
859 s <<
"(" << a->cap <<
"," << a->flow <<
")"
873 using Parc = std::tuple<typename Net::Arc *, bool>;
883 using SemiPath = std::tuple<bool, typename Net::Flow_Type, DynList<Parc<Net>>>;
891 std::cout <<
"Semi path is Empty";
902 std::cout << s->get_info() <<
"(" << a->flow <<
"," << a->cap <<
")"
903 << t->get_info() <<
" " << (
get<1>(
pa) ?
"Normal" :
"Reduced")
920 using Tuple = std::tuple<typename Net::Node *, typename Net::Arc *>;
926 Tuple t = it.get_tuple_ne();
937 auto t = it.get_tuple_ne();
972 auto p = it.get_curr();
1005 auto p = it.get_curr();
1012 assert(arc->check_arc());
1023 template <
class Net,
template <
typename T>
class Q>
1039 for (Itor it(start); it.has_curr(); it.next_ne())
1041 auto a = it.get_curr();
1051 while (
not q.is_empty())
1071 for (Itor it(curr); it.has_curr(); it.next_ne())
1073 auto a = it.get_curr();
1110 while (curr != start)
1132 auto m = std::numeric_limits<typename Net::Flow_Type>::max();
1142 auto arc = it.get_curr();
1143 if ((arc->src_node == s
and arc->tgt_node == t)
or
1144 (arc->src_node == t
and arc->tgt_node == s))
1159 bool normal = a->tgt_node == t;
1160 auto slack = normal ? a->cap - a->flow : a->flow;
1162 semi_path.insert(std::make_tuple(a, normal));
1166 return std::make_tuple(
true,
m, std::move(
semi_path));
1224 template <
class Net>
1229 template <
class Net>
1240 template <
class Net,
template <
typename T>
class Q>
1251 template <
class Net>
1260 template <
class Net>
1276 template <
class Net,
template <
typename T>
class Q>
1285 template <
class Net>
1295 template <
class Net>
1312 template <
class Net,
template <
typename T>
class Q>
1322 template <
class Net>
1332 template <
class Net>
1342 template <
class Net>
1360 template <
class Net>
1383 template <
class Net>
1387 template <
class Net>
1391 template <
class Net>
1405 auto arc =
rnet.insert_arc(src, tgt);
1406 auto dup =
rnet.insert_arc(tgt, src);
1410 arc->flow = a->flow;
1413 dup->cap = arc->cap;
1414 dup->flow = arc->cap - arc->flow;
1419 template <
class Rnet>
1422 Res_F(
typename Rnet::Node *)
noexcept {}
1427 return a->cap > a->flow;
1435 template <
class Net>
1447 auto p = it.get_curr();
1448 auto q =
rnet.insert_node();
1460 return std::make_tuple(std::move(
rnet),
1466 template <
class Rnet>
1470 for (
typename Rnet::Arc_Iterator it(
rnet); it.has_curr(); it.next_ne())
1472 auto arc = it.get_curr();
1473 auto img = arc->img;
1476 img->flow = arc->flow;
1487 template <
class Net,
1492 <<
"Network is not single source and single sink";
1521 template <
class Net>
1532 template <
class Net>
1549 template <
class Net>
1560 template <
class Net>
1571 template <
class Net>
1579 template <
class Rnet>
1583 return p->in_flow != p->out_flow;
1588 template <
class Net>
1594 template <
class Net>
1610 template <
class Q_Type>
1622 template <
class Q_Type>
1634 template <
class Q_Type>
1658 template <
class Net,
class Q_Type>
1663 <<
"Network is not single source and single sink";
1671 constexpr auto Max = std::numeric_limits<long>::max();
1675 for (Itor it(source); it.has_curr(); it.next_ne())
1678 arc->flow = arc->cap;
1683 while (
not q.is_empty())
1689 for (Itor it(src); it.has_curr()
and excess > 0; it.next_ne())
1691 auto arc = it.get_curr();
1712 if (tgt != source
and tgt != sink)
1734 template <
class Rnet>
1739 exec(sink, [&
rnet](
typename Rnet::Node *p,
typename Rnet::Arc *a)
1755 template <
class Net>
1768 template <
class Net>
1781 template <
class Net>
1797 template <
class Net>
1810 template <
class Net>
1827 template <
class Net>
1840 template <
class Net>
1862 template <
class Net,
template <
class>
class Maxflow>
1886 if (
auto p = it.get_curr(); p->state() ==
Unprocessed)
1892 auto arc = it.get_curr();
1901 if (arc->flow == arc->cap)
1915 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.
Filtered iterator on directed graphs.
GT::Arc * get_curr() const
Return the current arc.
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.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
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
Checks if a key exists in the set.
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
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.
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
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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.
and
Check uniqueness with explicit hash + equality functors.
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.
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.
@ Tuple
Tuple type such as (Int, Bool).
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.
Net_Arc_Info(const Arc_Info &info, Flow_Type __cap, Flow_Type __flow)
Construct from base info, capacity and flow.
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.
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.
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.
Arc * insert_arc(Node *src_node, Node *tgt_node, const Arc_Type &arc_info=Arc_Type())
Insert an arc with zero capacity and flow.
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.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
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.