Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Net_Cap_Graph< NodeT, ArcT > Class Template Reference

Capacitated network with node capacity constraints. More...

#include <tpl_netcapgraph.H>

Inheritance diagram for Aleph::Net_Cap_Graph< NodeT, ArcT >:
[legend]
Collaboration diagram for Aleph::Net_Cap_Graph< NodeT, ArcT >:
[legend]

Classes

struct  Aux_Stamp
 

Public Types

using Net_Class = Net_Graph< NodeT, ArcT >
 Base network class type.
 
using Arc = ArcT
 Arc type.
 
using Node = NodeT
 Node type.
 
using Flow_Type = typename Arc::Flow_Type
 Type representing capacity and flow values.
 
using Node_Type = typename Node::Node_Type
 Type of information stored in nodes.
 
using Arc_Type = typename Arc::Arc_Type
 Type of information stored in arcs.
 
using Aux_Net = Net_Graph< Net_Node< Empty_Class >, Net_Arc< bool, Flow_Type > >
 Auxiliary network type for solving node-capacitated networks.
 
- Public Types inherited from Aleph::Net_Graph< NodeT, ArcT >
using Net = Net_Graph< NodeT, ArcT >
 
using Base = Array_Graph< NodeT, ArcT >
 
using Graph = Base
 
using Arc = ArcT
 Arc type.
 
using Node = NodeT
 Node type.
 
using Flow_Type = typename Arc::Flow_Type
 Capacity/flow numeric type.
 
using Node_Type = typename Node::Node_Type
 Node info type.
 
using Arc_Type = typename Arc::Arc_Type
 Arc info type.
 
- Public Types inherited from Aleph::Array_Graph< __Graph_Node, __Graph_Arc >
using Node = __Graph_Node
 
using Arc = __Graph_Arc
 
using Node_Type = typename Node::Node_Type
 
using Arc_Type = typename Arc::Arc_Type
 
using CommonBase = GraphCommon< Array_Graph< __Graph_Node, __Graph_Arc >, __Graph_Node, __Graph_Arc >
 
- Public Types inherited from GraphCommon< GT, Node, Arc >
using Node_Type = typename Node::Node_Type
 
using Arc_Type = typename Arc::Arc_Type
 
using ArcPair = std::tuple< Arc *, Node * >
 Pair of arc and node (topologically related)
 

Public Member Functions

Node * insert_node (Node *p) override
 
void remove_arc (Arc *arc) override
 Remove the arc arc from the network, as Net_Graph::remove_arc() does.
 
void remove_node (Node *p) override
 Remove the node p and its arcs from the network, as Net_Graph::remove_node() does.
 
void disconnect_arc (Arc *arc) override
 Disconnect the arc arc from the network without deleting it, as Net_Graph::disconnect_arc() does.
 
Node * insert_node (const Node_Type &node_info, const Flow_Type &cap=std::numeric_limits< Flow_Type >::max())
 Insert a new capacitated node into the network.
 
Node * insert_node (const Flow_Type &cap)
 Insert a new node with default info and specified capacity.
 
Node * insert_node ()
 Insert a new node with default info and unlimited capacity.
 
 Net_Cap_Graph () noexcept
 Default constructor.
 
 Net_Cap_Graph (const Net_Cap_Graph &other)
 Copy constructor.
 
 Net_Cap_Graph (Net_Cap_Graph &&other) noexcept
 Move constructor.
 
Net_Cap_Graph & operator= (const Net_Cap_Graph &other)
 Copy assignment operator.
 
void swap (Net_Cap_Graph &other) noexcept
 Swap contents with another network, with their auxiliary networks.
 
Net_Cap_Graph & operator= (Net_Cap_Graph &&other) noexcept
 Move assignment operator.
 
 ~Net_Cap_Graph ()
 Destructor.
 
Aux_Net * get_aux_net () noexcept
 Get pointer to the auxiliary network.
 
const Aux_Net * get_aux_net () const noexcept
 Get const pointer to the auxiliary network.
 
bool has_aux_net () const noexcept
 Check if auxiliary network has been computed.
 
Aux_Net * compute_aux_net ()
 Compute the equivalent arc-capacitated auxiliary network.
 
void update ()
 Update flow values from auxiliary network to this network.
 
void free_aux_net ()
 Free the auxiliary network.
 
Flow_Type get_total_flow () const
 Get the total flow value of the network.
 
bool check_node_capacities () const noexcept
 Check if all node capacity constraints are satisfied.
 
void reset_flows () noexcept
 Reset all flow values to zero.
 
- Public Member Functions inherited from Aleph::Net_Graph< NodeT, ArcT >
DynList< Arc * > out_arcs (Node *p) const noexcept
 Return arcs outgoing from p (as a DynList).
 
DynList< Node * > out_nodes (Node *p) const noexcept
 Return nodes reachable from p through outgoing arcs.
 
DynList< Arc * > in_arcs (Node *p) const noexcept
 Return arcs incoming to p (as a DynList).
 
DynList< Node * > in_nodes (Node *p) const noexcept
 Return nodes that can reach p through incoming arcs.
 
Flow_Type get_in_cap (Node *node) const noexcept
 Return total incoming capacity of node.
 
Flow_Type get_out_cap (Node *node) const noexcept
 Return total outgoing capacity of node.
 
size_t get_in_degree (Node *p) const noexcept
 Return the in-degree of p (number of incoming arcs).
 
size_t get_out_degree (Node *p) const noexcept
 Return the out-degree of p (number of outgoing arcs).
 
Flow_Type get_out_flow (Node *node) const noexcept
 Return total outgoing flow of node.
 
Flow_Type get_in_flow (Node *node) const noexcept
 Return total incoming flow of node.
 
bool is_source (Node *node) const noexcept
 Return true if node is a source.
 
bool is_sink (Node *node) const noexcept
 Return true if node is a sink.
 
constexpr bool is_single_source () const noexcept
 Return true if the network has a single source.
 
constexpr bool is_single_sink () const noexcept
 Return true if the network has a single sink.
 
bool is_connected (Node *p) const noexcept
 Return true if p is connected (used for validation).
 
bool check_node (Node *node) const noexcept
 Return true if node satisfies flow conservation constraints.
 
const DynSetTree< Node * > & get_src_nodes () const noexcept
 Return the set of source nodes.
 
const DynSetTree< Node * > & get_sink_nodes () const noexcept
 Return the set of sink nodes.
 
void make_super_source ()
 Convert a multi-source network into a single super-source network.
 
void unmake_super_source ()
 Restore a super-source network to its original multi-source form, by removing the super source that make_super_source() inserted.
 
void make_super_sink ()
 Convert a multi-sink network into a single super-sink network.
 
void unmake_super_sink ()
 Restore a super-sink network to its original multi-sink form, by removing the super sink that make_super_sink() inserted.
 
void make_super_nodes ()
 Convert a multi-source/multi-sink network into super-source/super-sink.
 
void unmake_super_nodes ()
 Restore a super-source/super-sink network to its original form.
 
Node * get_source () const
 Return an arbitrary source node.
 
Node * get_sink () const
 Return an arbitrary sink node.
 
Node * insert_node (const Node_Type &node_info)
 Insert a new node by copying node_info.
 
Node * insert_node ()
 Insert a new node with default info.
 
Node * insert_node (Node_Type &&info)
 Insert a new node by moving info.
 
template<typename... Args>
Node * emplace_node (Args &&...args)
 Construct a node in-place and insert it into the network.
 
Node * insert_node (Node *p) override
 Insert the node p, allocated by the caller.
 
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.
 
template<typename... Args>
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.
 
Arc * connect_arc (Arc *arc)
 Connect a previously disconnected arc.
 
Arc * insert_arc (Node *src_node, Node *tgt_node, const Flow_Type &cap)
 Insert an arc with capacity cap and zero flow.
 
Arc * insert_arc (Node *src_node, Node *tgt_node, const Arc_Type &arc_info=Arc_Type())
 Insert an arc with zero capacity and flow.
 
Arc * insert_arc (Node *src_node, Node *tgt_node)
 Insert an arc with zero capacity and flow, for an arc info that is arithmetic or of the type of the flow.
 
void remove_arc (Arc *arc) override
 Remove arc arc from the network.
 
void remove_node (Node *p) override
 Remove node p and all its arcs from the network.
 
 Net_Graph (const Net_Graph &net)
 Copy-construct a network. Throws bad_alloc on allocation failure.
 
void swap (Net_Graph &other) noexcept
 Swap contents with another network.
 
 Net_Graph (Net_Graph &&other) noexcept
 Move-construct a network. O(1) operation.
 
Net_Graph & operator= (Net_Graph &&other) noexcept
 Move-assign a network. O(1) operation.
 
Net_Graph & operator= (const Net_Graph &net)
 Copy-assign a network. Throws bad_alloc on allocation failure.
 
void set_cap (Arc *arc, const Flow_Type &cap)
 Set the capacity of an arc.
 
void set_flow (Arc *arc, const Flow_Type &flow)
 Set the flow of an arc. Throws if flow exceeds capacity.
 
const Flow_Type & get_flow (Arc *arc) const noexcept
 Return the flow value of an arc.
 
const Flow_Type & get_cap (Arc *arc) const noexcept
 Return the capacity value of an arc.
 
void reset ()
 Reset all arc flows to zero.
 
bool check_network () const
 Validate flow-conservation and capacity constraints.
 
Flow_Type flow_value () const
 Return the total flow value of the network: the flow out of its sources, which a valid flow also takes into its sinks, as check_network() takes them.
 
 Net_Graph ()
 Default constructor.
 
virtual Node * insert_node (Node *p)
 Inserts the node p, made with new, which the graph takes.
 
Node * insert_node (const Node_Type &node_info)
 Allocate a new node, set by copy its data content and insert it into the graph.
 
Node * insert_node (Node_Type &&node_info=Node_Type())
 Allocate a new node, set by moving its data content and insert it into the graph.
 
- Public Member Functions inherited from Aleph::Array_Graph< __Graph_Node, __Graph_Arc >
Dlink & get_node_dlink () noexcept
 Returns reference to internal node Dlink for sorting operations.
 
Dlink & get_arc_dlink () noexcept
 Returns reference to internal arc Dlink for sorting operations.
 
virtual Node * insert_node (Node *p)
 Inserts the node p, made with new, which the graph takes.
 
void compress ()
 
Arc * connect_arc (Arc *arc)
 
Arc * disconnect_arc (Arc *arc)
 
virtual void remove_arc (Arc *a)
 
virtual void remove_node (Node *p)
 
Node * get_first_node () const
 
Arc * get_first_arc () const
 
Arc * get_first_arc (Node *p) const
 
 Array_Graph ()
 
virtual ~Array_Graph () noexcept
 
void swap (Array_Graph &g) noexcept
 
 Array_Graph (const Array_Graph &g)
 Copy constructor.
 
 Array_Graph (Array_Graph &&g) noexcept
 Move constructor.
 
Array_Graph & operator= (const Array_Graph &g)
 Copy assignment.
 
Array_Graph & operator= (Array_Graph &&g) noexcept
 Move assignment.
 
Node * insert_node (const Node_Type &node_info)
 Allocate a new node, set by copy its data content and insert it into the graph.
 
Node * insert_node (Node_Type &&node_info=Node_Type())
 Allocate a new node, set by moving its data content and insert it into the graph.
 
Arc * insert_arc (Node *src, Node *tgt, const Arc_Type &arc_info)
 Create and insert a new arc linking two nodes and copying data.
 
Arc * insert_arc (Node *src, Node *tgt, Arc_Type &&arc_info=Arc_Type())
 Create and insert a new arc linking two nodes and moving the received data.
 
- Public Member Functions inherited from GraphCommon< GT, Node, Arc >
void *& get_cookie () noexcept
 Return a modifiable reference to graph's cookie.
 
void * get_cookie () const noexcept
 Return a constant reference to graph's cookie.
 
bool is_digraph () const noexcept
 Return true if the graph this is directed.
 
void set_digraph (bool val)
 Temporal indication for preventing to other algorithms that an graph must be treated as a directed graph.
 
constexpr size_t get_num_nodes () const noexcept
 Return the total of nodes of graph.
 
constexpr bool is_empty () const noexcept
 Checks if the graph is empty (has no nodes).
 
constexpr size_t vsize () const noexcept
 See get_num_nodes().
 
Node * get_node () const
 Return any node in the graph.
 
Arc * get_arc () const
 Return any arc in the graph.
 
Arc * get_arc (Node *p) const
 Return any arc adjacent to a node.
 
Node * get_src_node (Arc *arc) const noexcept
 Return the source node of arc (only for directed graphs)
 
Node * get_tgt_node (Arc *arc) const noexcept
 Return the target node of arc (only for directed graphs)
 
Node * get_connected_node (Arc *arc, Node *node) const noexcept
 Return the adjacent node to node through arc.
 
constexpr size_t get_num_arcs () const noexcept
 Return the number of arcs of the graph.
 
size_t get_num_arcs (Node *node) const noexcept
 Return the total of arcs of a node.
 
size_t degree (Node *p) const noexcept
 Return the total of arcs (or degree) of a node.
 
size_t esize () const noexcept
 Return the total of arcs of graph.
 
Bit_Fields & get_control_bits (Node *node) const noexcept
 Return a reference to control fields of node
 
void reset_bit (Node *node, int bit) const noexcept
 Reset the bit of node (to zero)
 
void reset_bits (Node *node) const noexcept
 Reset all the control bits of node
 
int get_bit (Node *node, int bit) const noexcept
 Get the control bit of node
 
void set_bit (Node *node, int bit, int value) const noexcept
 Set the control bit of node to value
 
Bit_Fields & get_control_bits (Arc *arc) const noexcept
 Return a reference to the control bits of arc
 
void reset_bit (Arc *arc, int bit) const noexcept
 Reset the bit of arc to zero.
 
void reset_bits (Arc *arc) const noexcept
 Reset all the control bits of arc
 
int get_bit (Arc *arc, int bit) const noexcept
 Get the control bit of arc
 
void set_bit (Arc *arc, int bit, int value) const noexcept
 Set the control bit of arc to value
 
void *& get_cookie (Node *node) const noexcept
 Get a modifiable reference to the cookie pointer of node
 
void *& get_cookie (Arc *arc) const noexcept
 Get a modifiable reference to the cookie pointer of arc
 
long & get_counter (Node *node) const noexcept
 Get a modifiable reference to the counter of node
 
void reset_counter (Node *node) const noexcept
 Reset the node counter to zero.
 
void reset_node_counters () const noexcept
 Reset all the node counters of graph to zero.
 
void reset_node (Node *p) const noexcept
 Reset all the control attributes of node p.
 
long & get_counter (Arc *arc) const noexcept
 Get a modifiable reference to the counter of arc
 
void reset_counter (Arc *arc) const noexcept
 Reset the acr counter to zero.
 
void reset_arc_counters () const noexcept
 Reset all the arc counters of graph to zero.
 
void reset_arc (Arc *arc) const noexcept
 Reset all the control attributes of arc.
 
void reset_nodes () const
 Reset all the nodes of graph (the control bits, the state, the counter and the cookie)
 
void reset_arcs () const
 Reset all the arcs of graph (the control bits, the state, the counter and the cookie)
 
void reset_bit_nodes (int bit) const noexcept
 Reset bit to zero for all the nodes of graph.
 
void reset_bit_arcs (int bit) const noexcept
 Reset bit to zero for all the arcs of graph.
 
void reset_bit_nodes () const noexcept
 Reset all the bits for all the nodes of graph.
 
void reset_bit_arcs () const noexcept
 Reset all the bits for all the arcs of graph.
 
void reset_counter_nodes () const noexcept
 Reset all the counters to zero for all the nodes of graph.
 
void reset_counter_arcs () const noexcept
 Reset all the counters to zero for all the arcs of graph.
 
void reset_cookie_nodes () const noexcept
 Reset all the cookies to `nullptr for all the nodes of graph.
 
void reset_cookie_arcs () const noexcept
 Reset all the cookies to `nullptr for all the arcs of graph.
 
Node * insert_node (const Node_Type &node_info)
 Allocate a new node, set by copy its data content and insert it into the graph.
 
Node * insert_node (Node_Type &&node_info=Node_Type())
 Allocate a new node, set by moving its data content and insert it into the graph.
 
template<typename... Args>
Node * emplace_node (Args &&... args)
 Insert a new node in the graph by constructing it in-place with the given args.
 
Arc * insert_arc (Node *src, Node *tgt, const Arc_Type &arc_info)
 Create and insert a new arc linking two nodes and copying data.
 
Arc * insert_arc (Node *src, Node *tgt, Arc_Type &&arc_info=Arc_Type())
 Create and insert a new arc linking two nodes and moving the received data.
 
template<typename... Args>
Arc * emplace_arc (Node *src, Node *tgt, Args &&... args)
 Insert a new arc in the graph by constructing its associated data in-place with the given args.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::node_curr<GT, Operation>::type>
bool traverse_nodes (Operation &op) const
 Conditioned traversal of all the nodes of a graph.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::node_curr<GT, Operation>::type>
bool traverse_nodes (Operation &&op=Operation()) const
 Overload of traverse_nodes(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::arc_curr<GT, Operation>::type>
bool traverse_arcs (Operation &op) const
 Conditioned traversal of all the arcs of a graph.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::arc_curr<GT, Operation>::type>
bool traverse_arcs (Operation &&op=Operation()) const
 Overload of traverse_arcs(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::node_arc_curr<GT, Operation>::type>
bool traverse_arcs (Node *p, Operation &op) const
 Conditioned traversal of all the adjacent arcs of a node.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::node_arc_curr<GT, Operation>::type>
bool traverse_arcs (Node *p, Operation &&op=Operation()) const
 Overload of traverse_arcs(Node*, Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::CallableWith<Operation &, typename Aleph::graph_dry_detail::node_curr<GT, Operation>::type>
void for_each_node (Operation &operation) const
 Unconditionally traverse all the nodes of graph and on each one perform an operation.
 
template<class Operation >
requires Aleph::CallableWith<Operation &, typename Aleph::graph_dry_detail::node_curr<GT, Operation>::type>
void for_each_node (Operation &&operation=Operation()) const
 Overload of for_each_node(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::CallableWith<Operation &, typename Aleph::graph_dry_detail::arc_curr<GT, Operation>::type>
void for_each_arc (Operation &op) const
 Unconditionally traverse all the arcs of graph and on each one perform an operation.
 
template<class Operation >
requires Aleph::CallableWith<Operation &, typename Aleph::graph_dry_detail::arc_curr<GT, Operation>::type>
void for_each_arc (Operation &&operation=Operation()) const
 Overload of for_each_arc(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::CallableWith<Operation &, typename Aleph::graph_dry_detail::node_arc_curr<GT, Operation>::type>
void for_each_arc (Node *p, Operation &op) const
 Unconditionally traverse all the arcs adjacnt to a node and on each one perform an operation.
 
template<class Operation >
requires Aleph::CallableWith<Operation &, typename Aleph::graph_dry_detail::node_arc_curr<GT, Operation>::type>
void for_each_arc (Node *p, Operation &&op=Operation()) const
 Overload of for_each_arc(Node*, Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::node_curr<GT, Operation>::type>
bool all_nodes (Operation &op) const
 Check if all the nodes of graph satisfy an boolean condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::node_curr<GT, Operation>::type>
bool all_nodes (Operation &&op=Operation()) const
 Overload of all_nodes(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::arc_curr<GT, Operation>::type>
bool all_arcs (Operation &op) const
 Check if all the arcs of graph satisfy a boolean condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::arc_curr<GT, Operation>::type>
bool all_arcs (Operation &&op=Operation()) const
 Overload of all_arcs(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::node_arc_curr<GT, Operation>::type>
bool all_arcs (Node *p, Operation &op) const
 Check if all the arcs adjacent to a node satisfy an boolean condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::graph_dry_detail::node_arc_curr<GT, Operation>::type>
bool all_arcs (Node *p, Operation &&op=Operation()) const
 Overload of all_arcs(Node*, Operation&) that accepts rvalues.
 
template<typename T = Node_Type, class Op >
requires std::is_invocable_r_v<T, Op &, Node *>
auto nodes_map (Op op) const
 Map the nodes of a graph to a specific range.
 
template<typename T = Arc_Type, class Op >
requires std::is_invocable_r_v<T, Op &, Arc *>
auto arcs_map (Op operation) const
 Map the arcs of a graph to a specific range.
 
template<typename T = Arc_Type, class Op >
requires std::is_invocable_r_v<T, Op &, Arc *>
auto arcs_map (Node *p, Op operation) const
 Map the adjacent arcs of a node to a specific range.
 
template<typename T = Node_Type, class Op >
requires std::is_invocable_r_v<T, Op &, const T &, Node *>
T foldl_nodes (const T &init, Op op) const
 Folding of nodes on a graph.
 
template<typename T = Arc_Type, class Op >
requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
T foldl_arcs (const T &init, Op op) const
 Folding of arcs on a graph.
 
template<typename T = Arc_Type, class Op >
requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
T foldl_arcs (Node *p, const T &init, Op op) const
 Folding of arcs of a node.
 
template<class Op >
requires Aleph::PredicateWith<Op &, Node *&>
auto filter_nodes (Op &op) const
 Filter the nodes satisfying a condition.
 
template<class Op >
requires Aleph::PredicateWith<Op &, Node *&>
auto filter_nodes (Op &&op) const
 Overload of filter_nodes(Op&) that accepts rvalues.
 
template<class Op >
requires Aleph::PredicateWith<Op &, Arc *&>
auto filter_arcs (Op &op) const
 Filter the arcs of graph satisfying a condition.
 
template<class Op >
requires Aleph::PredicateWith<Op &, Arc *&>
auto filter_arcs (Op &&op) const
 Overload of filter_arcs(Op&) that accepts rvalues.
 
template<class Op >
requires Aleph::PredicateWith<Op &, Arc *&>
auto filter_arcs (Node *p, Op &op) const
 Filter the arcs adjacent to a node satisfying a condition.
 
template<class Op >
requires Aleph::PredicateWith<Op &, Arc *&>
auto filter_arcs (Node *p, Op &&op) const
 Overload of filter_arcs(Node*, Op&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Node *&>
bool exists_node (Operation &op) const
 Determine if exists at least a node satisfying a condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Node *&>
bool exists_node (Operation &&op=Operation()) const
 Overload of exists_node(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
bool exists_arc (Operation &op) const
 Determine if exists at least a arc satisfying a condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
bool exists_arc (Operation &&op=Operation()) const
 Overload of exists_arc(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
bool exists_arc (Node *p, Operation &op) const
 Determine if exists at least a arc adjacent to a node satisfying a condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
bool exists_arc (Node *p, Operation &&op=Operation()) const
 Overload of exists_arc(Node*, Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Node *&>
bool none_node (Operation &op) const
 Determine if no node satisfies a condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Node *&>
bool none_node (Operation &&op) const
 Overload of none_node(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
bool none_arc (Operation &op) const
 Determine if no arc satisfies a condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
bool none_arc (Operation &&op) const
 Overload of none_arc(Operation&) that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
bool none_arc (Node *p, Operation &op) const
 Determine if no arc adjacent to a node satisfies a condition.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
bool none_arc (Node *p, Operation &&op) const
 Overload of none_arc(Node*, Operation&) that accepts rvalues.
 
template<class Operation = std::function<bool(Node*)>>
requires Aleph::PredicateWith<Operation &, Node *&>
size_t count_nodes (Operation op=[](Node *) { return true;}) const
 Count the nodes satisfying a condition.
 
template<class Operation = std::function<bool(Arc*)>>
requires Aleph::PredicateWith<Operation &, Arc *&>
size_t count_arcs (Operation op=[](Arc *) { return true;}) const
 Count the arcs satisfying a condition.
 
template<class Operation = std::function<bool(Arc*)>>
requires Aleph::PredicateWith<Operation &, Arc *&>
size_t count_arcs (Node *p, Operation op=[](Arc *) { return true;}) const
 Count arcs adjacent to a node satisfying a condition.
 
template<typename T = double, class Extract >
requires requires(T &sum, Extract &extract, Arc *a) { sum += extract(a); }
T sum_arcs (Node *p, Extract extract) const
 Sum values derived from arcs adjacent to a node.
 
template<typename T = double>
T sum_arcs (Node *p) const
 Overload of sum_arcs(Node*, Extract) using the arc info as extractor.
 
template<class Compare = std::function<bool(Arc*, Arc*)>>
requires Aleph::PredicateWith<Compare &, Arc *&, Arc *&>
Arc * min_arc (Node *p, Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
 Find the minimum arc adjacent to a node.
 
template<class Compare = std::function<bool(Arc*, Arc*)>>
requires Aleph::PredicateWith<Compare &, Arc *&, Arc *&>
Arc * max_arc (Node *p, Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
 Find the maximum arc adjacent to a node.
 
template<class Compare = std::function<bool(Arc*, Arc*)>>
requires Aleph::PredicateWith<Compare &, Arc *&, Arc *&>
Arc * min_arc (Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
 Find the minimum arc in the entire graph.
 
template<class Compare = std::function<bool(Arc*, Arc*)>>
requires Aleph::PredicateWith<Compare &, Arc *&, Arc *&>
Arc * max_arc (Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
 Find the maximum arc in the entire graph.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Node *&>
std::pair< DynList< Node * >, DynList< Node * > > partition_nodes (Operation op) const
 Partition nodes into two groups based on a predicate.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
std::pair< DynList< Arc * >, DynList< Arc * > > partition_arcs (Operation op) const
 Partition arcs into two groups based on a predicate.
 
DynList< Node * > adjacent_nodes (Node *p) const
 Get all adjacent nodes (neighbors) of a node.
 
template<class Op >
requires Aleph::PredicateWith<Op &, std::decay_t<typename Aleph::graph_dry_detail::node_curr<GT, Op>::type> &>
Node * search_node (Op &op) const
 Linear search of a node.
 
template<class Op >
requires Aleph::PredicateWith<Op &, std::decay_t<typename Aleph::graph_dry_detail::node_curr<GT, Op>::type> &>
Node * search_node (Op &&op) const
 Overload of search_node(Op&) that accepts rvalues.
 
Node * find_node (const Node_Type &info) const noexcept(noexcept(static_cast< bool >(std::declval< Node_Type & >()==std::declval< const Node_Type & >())))
 Find a node mathing a content.
 
template<class Op >
requires Aleph::PredicateWith<Op &, std::decay_t<typename Aleph::graph_dry_detail::arc_curr<GT, Op>::type> &>
Arc * search_arc (Op &op) const
 Linear search of an arc.
 
template<class Op >
requires Aleph::PredicateWith<Op &, std::decay_t<typename Aleph::graph_dry_detail::arc_curr<GT, Op>::type> &>
Arc * search_arc (Op &&op) const
 Overload of search_arc(Op&) that accepts rvalues.
 
Arc * find_arc (const Arc_Type &info) const noexcept(noexcept(static_cast< bool >(std::declval< Arc_Type & >()==std::declval< const Arc_Type & >())))
 Find an arc mathing a content.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
Arc * search_arc (Node *p, Operation &op) const
 Linear search of an arc.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, Arc *&>
Arc * search_arc (Node *p, Operation &&op=Operation()) const
 Overload of search_arc(Node*, Operation&) that accepts rvalues.
 
Arc * search_arc (Node *src, Node *tgt) const noexcept
 Search an arc linking two nodes.
 
template<template< typename > class Container = Aleph::DynList>
Container< Node * > nodes () const
 Return a container with all the nodes of the graph.
 
template<template< typename > class Container = Aleph::DynList>
Container< Arc * > arcs () const
 Return a container with all the arcs of the graph.
 
template<template< typename > class Container = Aleph::DynList>
Container< Arc * > arcs (Node *p) const
 Return a container with all the arcs adjacent to a node.
 
auto get_node_it () const noexcept
 Obtains an iterator to the nodes of graph.
 
auto get_arc_it () const noexcept
 Obtains an iterator to the arc of graph.
 
auto get_arc_it (Node *p) const noexcept
 Obtains an iterator to the adjacent arcs of a node.
 
In_Iterator get_in_it (Node *p) const
 Return an input iterator on the incoming arcs to p
 
Out_Iterator get_out_it (Node *p) const noexcept
 Return an output iterator on the incoming nodes to p
 
Arc * search_directed_arc (Node *src, Node *tgt) const noexcept
 Search a directed arc linking two nodes.
 
DynList< Node * > in_nodes (Node *p) const
 Return a list with the incoming nodes to p
 
DynList< Node * > out_nodes (Node *p) const
 Return a list with the outcoming nodes to p
 
DynList< Arc * > out_arcs (Node *p) const
 Return a list with the outcoming arcs to p`.
 
DynList< Arc * > in_arcs (Node *p) const
 Return a list with the incoming arcs to p
 
auto in_pairs (Node *p) const
 Return a list of pair incoming arcs and nodes.
 
auto out_pairs (Node *p) const
 Return a list of pair outcoming arcs and nodes.
 
size_t in_degree (Node *p) const noexcept
 Compute the input degree of a node.
 
size_t out_degree (Node *p) const noexcept
 Compute the output degree of a node.
 
template<class Itor , class Operation >
requires Aleph::PredicateWith<Operation &, decltype(std::declval<Itor &>().get_curr())>
bool traverse_arcs (Node *p, Operation &op) const
 Traverse of arcs of a node according to specific arcs iterator.
 
template<class Itor , class Operation >
requires Aleph::CallableWith<Operation &, decltype(std::declval<Itor &>().get_curr())>
void for_each_arc (Node *p, Operation &op) const
 Perform op on each arc of node p
 
template<class Op >
bool traverse_in_arcs (Node *p, Op &op) const
 Traverse the incoming arcs of node p executing the conditioned operation.
 
template<class Op >
bool traverse_in_arcs (Node *p, Op &&op=Op()) const
 Overload of traverse_in_arcs(Node*, Op&) that accepts rvalues.
 
template<class Op >
void for_each_in_arc (Node *p, Op &op) const
 Perform op on each incoming arc of node p; on a digraph, among the arcs of the graph, in \(O(E)\).
 
template<class Op >
void for_each_in_arc (Node *p, Op &&op=Op()) const
 Overload of for_each_in_arc(Node*, Op&) that accepts rvalues.
 
template<class Op >
bool all_in_arcs (Node *p, Op &op) const
 Return true if op is true for all the incoming arcs to node p
 
template<class Op >
bool all_in_arcs (Node *p, Op &&op=Op()) const
 Overload of all_in_arcs(Node*, Op&) that accepts rvalues.
 
template<class Op >
bool exists_in_arc (Node *p, Op &op) const
 Return true if it exists a incoming arc to p returning true for op
 
template<class Op >
bool exists_in_arc (Node *p, Op &&op=Op()) const
 Overload of exists_in_arc(Node*, Op&) that accepts rvalues.
 
template<class Op >
auto search_in_arc (Node *p, Op &op) const
 Search an incoming arc to a node satisfaying a condition.
 
template<class Op >
auto search_in_arc (Node *p, Op &&op=Op()) const
 Overload of search_in_arc(Node*, Op&) that accepts rvalues.
 
template<typename T , class Op >
requires std::is_invocable_r_v<T, Op &, Arc *>
auto in_arcs_map (Node *p, Op op) const
 Return a list of incoming arcs of a node mapped to items of type given by transformation op.
 
template<typename T = Arc_Type, class Op >
requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
T foldl_in_arcs (Node *p, const T &init, Op op) const
 Fold the incoming arcs of a node.
 
template<class Op >
DynList< Arc * > filter_in_arcs (Node *p, Op &op) const
 Filter the incoming arcs of a node.
 
template<class Op >
auto filter_in_arcs (Node *p, Op &&op=Op()) const
 Overload of filter_in_arcs(Node*, Op&) that accepts rvalues.
 
template<class Op >
bool traverse_out_arcs (Node *p, Op &op) const
 Traverse the outcoming arcs of node p executing the conditioned operation
 
template<class Op >
bool traverse_out_arcs (Node *p, Op &&op=Op()) const
 Overload of traverse_out_arcs(Node*, Op&) that accepts rvalues.
 
template<class Op >
void for_each_out_arc (Node *p, Op &op) const
 Perform op on each outcoming arc of node p
 
template<class Op >
void for_each_out_arc (Node *p, Op &&op=Op()) const
 Overload of for_each_out_arc(Node*, Op&) that accepts rvalues.
 
template<class Op >
bool all_out_arcs (Node *p, Op &op) const
 Return true if op is true for all the outcoming arcs to node p
 
template<class Op >
bool all_out_arcs (Node *p, Op &&op=Op()) const
 Overload of all_out_arcs(Node*, Op&) that accepts rvalues.
 
template<class Op >
bool exists_out_arc (Node *p, Op &op) const
 Return true if it exists a outcoming arc to p returning true for op
 
template<class Op >
bool exists_out_arc (Node *p, Op &&op=Op()) const
 Overload of exists_out_arc(Node*, Op&) that accepts rvalues.
 
template<class Op >
auto search_out_arc (Node *p, Op &op) const
 Search an outcoming arc to a node satisfaying a condition.
 
template<class Op >
auto search_out_arc (Node *p, Op &&op=Op()) const
 Overload of search_out_arc(Node*, Op&) that accepts rvalues.
 
template<typename T = Arc_Type, class Op >
requires std::is_invocable_r_v<T, Op &, Arc *>
auto out_arcs_map (Node *p, Op op) const
 Return a list of outcoming arcs of a node mapped to items of type given by transformation op.
 
template<typename T = Arc_Type, class Op >
requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
T foldl_out_arcs (Node *p, const T &init, Op op) const
 Fold-left over outcoming arcs of a node.
 
template<class Op >
DynList< Arc * > filter_out_arcs (Node *p, Op &op) const
 Filter the outcoming arcs of a node.
 
template<class Op >
auto filter_out_arcs (Node *p, Op &&op=Op()) const
 Overload of filter_out_arcs(Node*, Op&) that accepts rvalues.
 
template<class Compare >
requires (has_node_dlink_v<GT>)
void sort_nodes (Compare &cmp) noexcept(nothrow_cmp_v< Compare, Node >)
 Sort all the nodes of the graph according to a specific criteria.
 
template<class Compare >
requires (has_node_dlink_v<GT>)
void sort_nodes (Compare &&cmp=Compare()) noexcept(nothrow_cmp_v< Compare, Node >)
 See sort_nodes(Compare & cmp).
 
template<class Compare >
requires (has_arc_dlink_v<GT>)
void sort_arcs (Compare &cmp) noexcept(nothrow_cmp_v< Compare, Arc >)
 Sort all the arcs of the graph according to a specific criteria.
 
template<class Compare >
requires (has_arc_dlink_v<GT>)
void sort_arcs (Compare &&cmp=Compare()) noexcept(nothrow_cmp_v< Compare, Arc >)
 See sort_arcs(Compare & cmp).
 

Static Public Member Functions

static Flow_Type get_node_cap (const Node *node) noexcept
 Get the capacity of a node.
 
static void set_node_cap (Node *node, const Flow_Type &cap)
 Set the capacity of a node.
 
- Static Public Member Functions inherited from Aleph::Net_Graph< NodeT, ArcT >
static Flow_Type node_tolerance (const Flow_Type &in, const Flow_Type &out) noexcept
 The tolerance of rounding of the flow of a node whose flows into and out of it are in and out.
 
- Static Public Member Functions inherited from GraphCommon< GT, Node, Arc >
template<class N1 , class N2 = N1>
static void map_nodes (N1 *p, N2 *q) noexcept
 Map the nodes through their cookies.
 
template<class A1 , class A2 = A1>
static void map_arcs (A1 *p, A2 *q) noexcept
 Map the arcs through their cookies.
 

Private Member Functions

void swapped () noexcept final
 What swap() calls on each of its two networks, once their nodes and arcs are exchanged: nothing, in Net_Graph.
 

Private Attributes

Aux_Net * aux_net = nullptr
 
struct Aleph::Net_Cap_Graph::Aux_Stamp aux_stamp
 

Additional Inherited Members

- Public Attributes inherited from Aleph::Net_Graph< NodeT, ArcT >
Flow_Type Infinity
 
bool with_super_source
 True if the network has a super-source.
 
bool with_super_sink
 True if the network has a super-sink.
 
- Static Public Attributes inherited from GraphCommon< GT, Node, Arc >
template<class U >
static constexpr bool has_node_dlink_v
 Whether U::get_node_dlink() returns a Dlink &.
 
template<class U >
static constexpr bool has_arc_dlink_v
 
template<class Compare , class T >
static constexpr bool nothrow_cmp_v
 
- Protected Member Functions inherited from Aleph::Net_Graph< NodeT, ArcT >
void swap_contents (Net_Graph &other) noexcept
 Exchange the nodes, the arcs and the rest of the state of this network with those of other, as swap() does, without calling swapped().
 
- Protected Member Functions inherited from GraphCommon< GT, Node, Arc >
void init () noexcept
 
void common_swap (GT &g) noexcept
 
template<class Predicate >
DynList< Arc * > collect_arcs_if (Predicate pred) const
 Collect all arcs matching a predicate.
 
template<class Predicate >
void remove_arcs_if (Predicate pred)
 Remove all arcs matching a predicate.
 
- Protected Attributes inherited from GraphCommon< GT, Node, Arc >
void * cookie = nullptr
 
size_t num_nodes = 0
 
size_t num_arcs = 0
 
bool digraph = false
 

Detailed Description

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
class Aleph::Net_Cap_Graph< NodeT, ArcT >

Capacitated network with node capacity constraints.

Net_Cap_Graph models a flow network where nodes have maximum throughput limits in addition to arc capacities. This extends the standard maximum flow model to handle vertex-capacitated networks.

Network Transformation

A node-capacitated network cannot be directly solved by standard maximum flow algorithms. Instead, it must be transformed into an equivalent arc-capacitated network (called the auxiliary network).

The transformation works as follows:

  • Each node v with capacity c(v) is split into two nodes: v_in and v_out
  • An arc (v_in, v_out) with capacity c(v) is added
  • All incoming arcs to v now go to v_in
  • All outgoing arcs from v now come from v_out

Usage Pattern

// Build the network
auto n1 = net.insert_node("A", 10); // Node with capacity 10
auto n2 = net.insert_node("B", 5); // Node with capacity 5
net.insert_arc(n1, n2, 15, 0); // Arc with capacity 15
// Compute auxiliary network
auto aux = net.compute_aux_net();
// Run max flow on auxiliary network
// Transfer flow values back
net.update();
// Clean up
Capacitated network with node capacity constraints.
void free_aux_net()
Free the auxiliary network.
void update()
Update flow values from auxiliary network to this network.
Node * insert_node(Node *p) override
Aux_Net * compute_aux_net()
Compute the equivalent arc-capacitated auxiliary network.
Net::Flow_Type ford_fulkerson_maximum_flow(Net &net)
Maximize flow using the Ford-Fulkerson algorithm.
Definition tpl_net.H:2306
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.
Definition tpl_net.H:799

The auxiliary network keeps pointers to the nodes and the arcs of the network, which update() follows. A change of the network after compute_aux_net(), a node or an arc inserted or removed (also by a copy_graph() over it), an arc disconnected (also if it is connected again), or the nodes and the arcs exchanged by a swap() or an assignment through a reference to Net_Graph, leaves it without its network: update() then throws std::domain_error, and the auxiliary network stays as it is, for free_aux_net(). A change of the order of the nodes or of the arcs, as sort_nodes(), is not one.

Template Parameters
NodeTNode type (must derive from Net_Cap_Node).
ArcTArc type (must derive from Net_Arc).
See also
Net_Graph compute_aux_net() Net_Cap_Node

Definition at line 277 of file tpl_netcapgraph.H.

Member Typedef Documentation

◆ Arc

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
using Aleph::Net_Cap_Graph< NodeT, ArcT >::Arc = ArcT

Arc type.

Definition at line 284 of file tpl_netcapgraph.H.

◆ Arc_Type

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
using Aleph::Net_Cap_Graph< NodeT, ArcT >::Arc_Type = typename Arc::Arc_Type

Type of information stored in arcs.

Definition at line 296 of file tpl_netcapgraph.H.

◆ Aux_Net

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
using Aleph::Net_Cap_Graph< NodeT, ArcT >::Aux_Net = Net_Graph<Net_Node<Empty_Class>, Net_Arc<bool, Flow_Type> >

Auxiliary network type for solving node-capacitated networks.

Aux_Net is the equivalent arc-capacitated network that can be processed by standard maximum flow algorithms.

The auxiliary network is created by compute_aux_net(). Each node in Net_Cap_Graph maps to an arc in Aux_Net. The arc's boolean info indicates whether it represents a node (true) or an original arc (false).

Mapping between networks:

  • For a node p in Net_Cap_Graph: NODE_COOKIE(p) points to the corresponding arc in Aux_Net
  • For an arc in Aux_Net: ARC_COOKIE(arc) points to either the original node (if arc->get_info() == true) or the original arc (if arc->get_info() == false)

Definition at line 410 of file tpl_netcapgraph.H.

◆ Flow_Type

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
using Aleph::Net_Cap_Graph< NodeT, ArcT >::Flow_Type = typename Arc::Flow_Type

Type representing capacity and flow values.

Definition at line 290 of file tpl_netcapgraph.H.

◆ Net_Class

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
using Aleph::Net_Cap_Graph< NodeT, ArcT >::Net_Class = Net_Graph<NodeT, ArcT>

Base network class type.

Definition at line 281 of file tpl_netcapgraph.H.

◆ Node

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
using Aleph::Net_Cap_Graph< NodeT, ArcT >::Node = NodeT

Node type.

Definition at line 287 of file tpl_netcapgraph.H.

◆ Node_Type

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
using Aleph::Net_Cap_Graph< NodeT, ArcT >::Node_Type = typename Node::Node_Type

Type of information stored in nodes.

Definition at line 293 of file tpl_netcapgraph.H.

Constructor & Destructor Documentation

◆ Net_Cap_Graph() [1/3]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Aleph::Net_Cap_Graph< NodeT, ArcT >::Net_Cap_Graph ( )
inlinenoexcept

Default constructor.

Creates an empty node-capacitated network.

Definition at line 440 of file tpl_netcapgraph.H.

◆ Net_Cap_Graph() [2/3]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Aleph::Net_Cap_Graph< NodeT, ArcT >::Net_Cap_Graph ( const Net_Cap_Graph< NodeT, ArcT > &  other)
inline

Copy constructor.

Parameters
otherNetwork to copy from, with the capacities and flows of its nodes.
Exceptions
std::bad_allocif there is not enough memory.
Note
The auxiliary network is NOT copied.

Definition at line 453 of file tpl_netcapgraph.H.

References GTNodeIterator< GT >::get_curr().

◆ Net_Cap_Graph() [3/3]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Aleph::Net_Cap_Graph< NodeT, ArcT >::Net_Cap_Graph ( Net_Cap_Graph< NodeT, ArcT > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherNetwork to move from.

Definition at line 473 of file tpl_netcapgraph.H.

References Aleph::Net_Graph< NodeT, ArcT >::swap_contents().

◆ ~Net_Cap_Graph()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Aleph::Net_Cap_Graph< NodeT, ArcT >::~Net_Cap_Graph ( )
inline

Destructor.

Automatically frees the auxiliary network if it exists.

Definition at line 539 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net.

Member Function Documentation

◆ check_node_capacities()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
bool Aleph::Net_Cap_Graph< NodeT, ArcT >::check_node_capacities ( ) const
inlinenoexcept

Check if all node capacity constraints are satisfied.

Verifies that for each node, the flow through it does not exceed its maximum capacity.

Returns
true if all node capacities are respected, false otherwise.

Definition at line 749 of file tpl_netcapgraph.H.

◆ compute_aux_net()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Aux_Net * Aleph::Net_Cap_Graph< NodeT, ArcT >::compute_aux_net ( )
inline

Compute the equivalent arc-capacitated auxiliary network.

Transforms this node-capacitated network into an equivalent arc-capacitated network that can be solved by standard maximum flow algorithms.

The transformation:

  • Each node v is split into v_in and v_out
  • Arc (v_in, v_out) with capacity = v.max_cap is added
  • Original arcs are remapped accordingly

Cookie mappings are established for update():

Returns
Pointer to the computed auxiliary network.
Exceptions
std::domain_errorif auxiliary network already exists.
std::bad_allocif memory allocation fails.
Note
Call update() after running max flow on the auxiliary network to transfer flow values back to this network, before any change of this network: after one, update() refuses it.

Definition at line 595 of file tpl_netcapgraph.H.

References ah_domain_error_if, ARC_COOKIE, Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net, Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_stamp, Aleph::clear_graph(), GraphCommon< GT, Node, Arc >::get_num_arcs(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::Net_Graph< NodeT, ArcT >::insert_arc(), Aleph::Net_Graph< NodeT, ArcT >::insert_node(), and NODE_COOKIE.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ disconnect_arc()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
void Aleph::Net_Cap_Graph< NodeT, ArcT >::disconnect_arc ( Arc *  arc)
inlineoverridevirtual

Disconnect the arc arc from the network without deleting it, as Net_Graph::disconnect_arc() does.

An auxiliary network computed before no longer maps to the network, also if the arc is connected again: update() refuses it.

Parameters
[in]arcthe arc to disconnect.
Exceptions
std::bad_allocas Net_Graph::disconnect_arc().

Reimplemented from Aleph::Net_Graph< NodeT, ArcT >.

Definition at line 342 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_stamp, Aleph::Net_Graph< NodeT, ArcT >::disconnect_arc(), and Aleph::Net_Cap_Graph< NodeT, ArcT >::Aux_Stamp::stale.

◆ free_aux_net()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
void Aleph::Net_Cap_Graph< NodeT, ArcT >::free_aux_net ( )
inline

Free the auxiliary network.

Releases all memory used by the auxiliary network, without allocating. The cookies of the nodes and arcs, which compute_aux_net() pointed to it, are left as they are.

Exceptions
std::domain_errorif auxiliary network has not been computed.

Definition at line 715 of file tpl_netcapgraph.H.

References ah_domain_error_if, and Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ get_aux_net() [1/2]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
const Aux_Net * Aleph::Net_Cap_Graph< NodeT, ArcT >::get_aux_net ( ) const
inlinenoexcept

Get const pointer to the auxiliary network.

Returns
Const pointer to the auxiliary network, or nullptr if not computed.

Definition at line 557 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net.

◆ get_aux_net() [2/2]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Aux_Net * Aleph::Net_Cap_Graph< NodeT, ArcT >::get_aux_net ( )
inlinenoexcept

Get pointer to the auxiliary network.

Returns
Pointer to the auxiliary network, or nullptr if not computed.

Definition at line 548 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net.

◆ get_node_cap()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
static Flow_Type Aleph::Net_Cap_Graph< NodeT, ArcT >::get_node_cap ( const Node *  node)
inlinestaticnoexcept

Get the capacity of a node.

Parameters
nodePointer to the node.
Returns
The maximum capacity of the node.

Definition at line 784 of file tpl_netcapgraph.H.

◆ get_total_flow()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Flow_Type Aleph::Net_Cap_Graph< NodeT, ArcT >::get_total_flow ( ) const
inline

Get the total flow value of the network.

Returns the value of the flow, the flow out of the sources, which update() copied from the auxiliary network to the arcs.

Returns
Total network flow value.
Exceptions
std::domain_errorif auxiliary network has not been computed.
Note
update() must be called first to transfer flow values.

Definition at line 734 of file tpl_netcapgraph.H.

References ah_domain_error_if, Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net, and Aleph::Net_Graph< NodeT, ArcT >::flow_value().

◆ has_aux_net()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
bool Aleph::Net_Cap_Graph< NodeT, ArcT >::has_aux_net ( ) const
inlinenoexcept

Check if auxiliary network has been computed.

Returns
true if auxiliary network exists, false otherwise.

Definition at line 566 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net.

Referenced by TEST_F(), and TEST_F().

◆ insert_node() [1/4]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Node * Aleph::Net_Cap_Graph< NodeT, ArcT >::insert_node ( )
inline

Insert a new node with default info and unlimited capacity.

Returns
Pointer to the newly created and inserted node.
Exceptions
std::bad_allocif memory allocation fails.

Definition at line 388 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::insert_node().

Referenced by Aleph::Net_Cap_Graph< NodeT, ArcT >::insert_node(), and Aleph::Net_Cap_Graph< NodeT, ArcT >::insert_node().

◆ insert_node() [2/4]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Node * Aleph::Net_Cap_Graph< NodeT, ArcT >::insert_node ( const Flow_Type &  cap)
inline

Insert a new node with default info and specified capacity.

Parameters
capMaximum flow capacity for this node.
Returns
Pointer to the newly created and inserted node.
Exceptions
std::bad_allocif memory allocation fails.
std::domain_errorif cap is negative.

Definition at line 378 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::insert_node().

◆ insert_node() [3/4]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Node * Aleph::Net_Cap_Graph< NodeT, ArcT >::insert_node ( const Node_Type &  node_info,
const Flow_Type &  cap = std::numeric_limits<Flow_Type>::max() 
)
inline

Insert a new capacitated node into the network.

Creates a new node with the given information and capacity, and inserts it into the network.

Parameters
node_infoInformation to store in the node.
capMaximum flow capacity for this node. Defaults to the maximum representable value (unlimited).
Returns
Pointer to the newly created and inserted node.
Exceptions
std::bad_allocif memory allocation fails.
std::domain_errorif cap is negative.

Definition at line 360 of file tpl_netcapgraph.H.

References ah_domain_error_if, and Aleph::Net_Graph< NodeT, ArcT >::insert_node().

◆ insert_node() [4/4]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Node * Aleph::Net_Cap_Graph< NodeT, ArcT >::insert_node ( Node *  p)
inlineoverride

◆ operator=() [1/2]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Net_Cap_Graph & Aleph::Net_Cap_Graph< NodeT, ArcT >::operator= ( const Net_Cap_Graph< NodeT, ArcT > &  other)
inline

Copy assignment operator.

Parameters
otherNetwork to copy from.
Returns
Reference to this network, which keeps its cookie.
Exceptions
std::bad_allocif there is not enough memory. Then the network is as it was.
Note
Frees the existing auxiliary network.

Definition at line 490 of file tpl_netcapgraph.H.

References GraphCommon< GT, Node, Arc >::get_cookie(), and Aleph::Net_Cap_Graph< NodeT, ArcT >::swap().

◆ operator=() [2/2]

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
Net_Cap_Graph & Aleph::Net_Cap_Graph< NodeT, ArcT >::operator= ( Net_Cap_Graph< NodeT, ArcT > &&  other)
inlinenoexcept

Move assignment operator.

Parameters
otherNetwork to move from.
Returns
Reference to this network.

Definition at line 522 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net, Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_stamp, and Aleph::Net_Graph< NodeT, ArcT >::swap_contents().

◆ remove_arc()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
void Aleph::Net_Cap_Graph< NodeT, ArcT >::remove_arc ( Arc *  arc)
inlineoverride

Remove the arc arc from the network, as Net_Graph::remove_arc() does.

An auxiliary network computed before no longer maps to the network: update() refuses it.

Parameters
[in]arcthe arc to remove.
Exceptions
std::bad_allocas Net_Graph::remove_arc().

Definition at line 312 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_stamp, Aleph::Net_Graph< NodeT, ArcT >::remove_arc(), and Aleph::Net_Cap_Graph< NodeT, ArcT >::Aux_Stamp::stale.

◆ remove_node()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
void Aleph::Net_Cap_Graph< NodeT, ArcT >::remove_node ( Node *  p)
inlineoverride

Remove the node p and its arcs from the network, as Net_Graph::remove_node() does.

An auxiliary network computed before no longer maps to the network: update() refuses it.

Parameters
[in]pthe node to remove.
Exceptions
std::bad_allocas Net_Graph::remove_node().

Definition at line 327 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_stamp, Aleph::Net_Graph< NodeT, ArcT >::remove_node(), and Aleph::Net_Cap_Graph< NodeT, ArcT >::Aux_Stamp::stale.

◆ reset_flows()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
void Aleph::Net_Cap_Graph< NodeT, ArcT >::reset_flows ( )
inlinenoexcept

Reset all flow values to zero.

Resets flows in both arcs and nodes.

Definition at line 764 of file tpl_netcapgraph.H.

◆ set_node_cap()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
static void Aleph::Net_Cap_Graph< NodeT, ArcT >::set_node_cap ( Node *  node,
const Flow_Type &  cap 
)
inlinestatic

Set the capacity of a node.

Parameters
nodePointer to the node.
capNew capacity value.
Exceptions
std::domain_errorif cap is negative.
std::overflow_errorif current flow exceeds new capacity.

Definition at line 796 of file tpl_netcapgraph.H.

References ah_domain_error_if, and ah_overflow_error_if.

◆ swap()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
void Aleph::Net_Cap_Graph< NodeT, ArcT >::swap ( Net_Cap_Graph< NodeT, ArcT > &  other)
inlinenoexcept

Swap contents with another network, with their auxiliary networks.

O(1).

copy_graph() empties a target whose copy fails by a swap with an empty network: so the auxiliary network, which maps to the nodes and arcs that went, goes with them.

Parameters
otherNetwork to swap with.

Definition at line 510 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net, Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_stamp, and Aleph::Net_Graph< NodeT, ArcT >::swap_contents().

Referenced by Aleph::Net_Cap_Graph< NodeT, ArcT >::operator=(), and TEST().

◆ swapped()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
void Aleph::Net_Cap_Graph< NodeT, ArcT >::swapped ( )
inlinefinalprivatevirtualnoexcept

What swap() calls on each of its two networks, once their nodes and arcs are exchanged: nothing, in Net_Graph.

A derived network that keeps something for its nodes and arcs, as Net_Cap_Graph its auxiliary network, overrides it: a swap(), a move or an assignment through a reference to Net_Graph exchange the nodes and the arcs, and not what the derived network keeps for them.

Net_Cap_Graph and Net_Sup_Dem_Graph make it final, since what they do in it has to be done: a network derived from one of them is told of no exchange, neither through a reference to Net_Graph nor through one to its base, and must keep nothing for the nodes and the arcs that such an exchange would leave behind.

Reimplemented from Aleph::Net_Graph< NodeT, ArcT >.

Definition at line 433 of file tpl_netcapgraph.H.

References Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_stamp, and Aleph::Net_Cap_Graph< NodeT, ArcT >::Aux_Stamp::stale.

◆ update()

template<class NodeT = Net_Cap_Node<Empty_Class, double>, class ArcT = Net_Arc<Empty_Class, double>>
void Aleph::Net_Cap_Graph< NodeT, ArcT >::update ( )
inline

Update flow values from auxiliary network to this network.

After running a maximum flow algorithm on the auxiliary network, call this method to transfer the computed flow values back to the original node-capacitated network.

Updates:

  • Node in_flow and out_flow from node-representing arcs
  • Arc flow values from edge-representing arcs
Exceptions
std::domain_errorif auxiliary network has not been computed, or if, after compute_aux_net(), a node or an arc was inserted in this network or removed from it, an arc was disconnected, or its nodes and arcs were exchanged through a reference to Net_Graph: the auxiliary network, which points to them, no longer maps to it. Nothing is written then.

Definition at line 679 of file tpl_netcapgraph.H.

References ah_domain_error_if, ARC_COOKIE, Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_net, Aleph::Net_Cap_Graph< NodeT, ArcT >::aux_stamp, Aleph::Net_Cap_Graph< NodeT, ArcT >::Aux_Stamp::num_arcs, Aleph::Net_Cap_Graph< NodeT, ArcT >::Aux_Stamp::num_nodes, and Aleph::Net_Cap_Graph< NodeT, ArcT >::Aux_Stamp::stale.

Referenced by TEST(), TEST_F(), TEST_F(), and TEST_F().

Member Data Documentation

◆ aux_net

◆ aux_stamp


The documentation for this class was generated from the following file: