110 template <AlephGraph
GT,
116 <<
"edge_connectivity() does not work on digraphs";
122 typename GT::Node *source_node =
nullptr;
123 long min_degree = std::numeric_limits<long>::max();
126 auto p = it.get_curr();
131 if (degree < min_degree)
154 auto p = it.get_curr();
157 if (p == source_node)
163 auto a = it.get_curr();
170 long min_k = min_degree;
177 auto node = it.get_curr();
185 const auto sink = it.get_curr();
188 net.
insert_arc(super_source, source, super_cap);
191 if (
const typename Net::Flow_Type flow = Max_Flow<Net>()(net); flow < min_k)
209 template <AlephGraph
GT,
263 template <AlephGraph
GT,
277 <<
"compute_min_cut() does not work on digraphs";
283 typename GT::Node *source_node =
nullptr;
284 long min_degree = std::numeric_limits<long>::max();
287 auto p = it.get_curr();
292 if (degree < min_degree)
304 auto p = it.get_curr();
315 if (source_node !=
nullptr)
320 auto p = it.get_curr();
321 if (p != source_node)
328 auto arc = it.get_curr();
330 if (other != source_node)
344 auto p = it.get_curr();
348 net_node_map.
insert(q, p);
349 if (p == source_node)
355 auto a = it.get_curr();
360 net_arc_map.
insert(arc, a);
364 net_arc_map.
insert(arc, a);
369 long min_k = std::numeric_limits<long>::max();
375 if (
auto node = it.get_curr(); node != source)
381 auto sink = it.get_curr();
384 net.
insert_arc(super_source, source, super_cap);
397 it.has_curr(); it.next_ne())
398 if (
auto node = it.get_curr(); net_node_map.
contains(node))
402 it.has_curr(); it.next_ne())
403 if (
auto node = it.get_curr(); net_node_map.
contains(node))
408 if (
auto arc = it.get_curr(); net_arc_map.
contains(arc))
409 cuts_filtered.
append(arc);
413 if (
auto arc = it.get_curr(); net_arc_map.
contains(arc))
414 cutt_filtered.
append(arc);
417 tmp_vs.
swap(vs_filtered);
418 tmp_vt.
swap(vt_filtered);
419 tmp_cuts.
swap(cuts_filtered);
420 tmp_cutt.
swap(cutt_filtered);
429 it.has_curr(); it.next_ne())
433 it.has_curr(); it.next_ne())
434 r.insert(net_node_map.
find(it.get_curr()));
439 typename Net::Arc *arc = it.get_curr();
454 template <AlephGraph
GT,
471 return compute_min_cut<GT, Max_Flow, SA>(g,
l,
r, cut,
sa);
503 template <AlephGraph
GT,
509 <<
"vertex_connectivity() does not work on digraphs";
515 typename GT::Node *source_node =
nullptr;
516 long min_degree = std::numeric_limits<long>::max();
519 auto p = it.get_curr();
524 if (degree < min_degree)
546 auto p = it.get_curr();
552 auto a = it.get_curr();
559 long min_k = min_degree;
563 auto source =
k.get_curr();
566 to_source_list.
append(it.get_curr());
576 auto sink = j.get_curr();
577 if (search_arc<Net>(net, source, sink) !=
nullptr)
583 from_sink_arcs.
append(it.get_curr());
586 it(from_sink_arcs); it.
has_curr(); it.next_ne())
596 auto p = it.get_curr();
597 if (p == source or p == sink)
610 auto a = it.get_curr();
620 auto arc = map.
find(nsrc);
628 auto arc = map.
find(ntgt);
635 const auto flow = Max_Flow<Net>()(aux_net);
640 while (not from_sink_arcs.
is_empty())
646 while (not to_source_list.
is_empty())
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Functor wrapper for compute_min_cut().
Compute_Min_Cut(SA __sa=SA())
Keeps sa, the filter of the arcs.
long operator()(GT &g, DynSetTree< typename GT::Node * > &l, DynSetTree< typename GT::Node * > &r, DynDlist< typename GT::Arc * > &cut)
Compute a minimum edge cut for g.
RAII guard that clears graph cookies on destruction.
Stateful depth-first traversal functor.
bool has_curr() const noexcept
Return true the iterator has an current arc.
bool has_curr() const noexcept
Return true if the iterator has current item.
constexpr bool is_empty() const noexcept
Return true if this (as header node) is empty.
Dynamic doubly linked list with O(1) size and bidirectional access.
T & append(const T &item)
Append a copied item at the end of the list.
void empty() noexcept
@brief Empties the container.
T get()
See remove_first().
Iterator on the items of list.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
T & insert(const T &item)
void empty() noexcept
empty the list
DynList & swap(DynList &l) noexcept
Dynamic map implemented with a treap.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
bool contains(const Key &key) const noexcept(nothrow_search)
Same as has().
Data & find(const Key &key)
Find the value associated with key.
Dynamic set backed by balanced binary search trees with automatic memory management.
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).
Functor wrapper for edge_connectivity().
long operator()(GT &g)
Compute edge connectivity of g.
void next()
Advances the iterator to the next filtered element.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
bool has_curr() const noexcept
Filtered iterator on the nodes of a graph.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
bool is_digraph() const noexcept
Return true if the graph this is directed.
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
RAII guards for graph node/arc cookies.
#define ARC_COOKIE(p)
Return the arc cookie
long vertex_connectivity(GT &g, SA sa=SA())
Compute vertex connectivity of an undirected graph.
long edge_connectivity(GT &g, SA sa=SA())
Compute edge connectivity (arc connectivity) of an undirected graph.
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#define NODE_COOKIE(p)
Return the node cookie
long compute_min_cut(GT &g, DynSetTree< typename GT::Node * > &l, DynSetTree< typename GT::Node * > &r, DynDlist< typename GT::Arc * > &cut, SA sa=SA())
Compute a minimum edge cut of an undirected graph.
Net_Graph< Net_Node< string >, Net_Arc< Empty_Class, FlowType > > Net
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Filtered iterator on all the arcs of a graph.
Default filter for filtered iterators on arcs.
Functor wrapper for heap_preflow_maximum_flow().
Functor wrapper for min_cut().
Arc of a flow network implemented with adjacency lists.
Flow network implemented with adjacency lists.
Node * insert_node(const Node_Type &node_info)
Insert a new node by copying node_info.
Arc * connect_arc(Arc *arc)
Connect a previously disconnected arc.
virtual void disconnect_arc(Arc *arc)
Disconnect arc arc from the graph without deleting it.
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.
void remove_node(Node *p) override
Remove node p and all its arcs from the network.
typename Arc::Flow_Type Flow_Type
Capacity/flow numeric type.
void reset()
Reset all arc flows to zero.
Filtered iterator of adjacent arcs of a node.
Functor wrapper for random_preflow_maximum_flow().
Dynamic set implementations based on balanced binary search trees.
Network flow graph structures.