71#ifndef TPL_NETCAPGRAPH_H
72#define TPL_NETCAPGRAPH_H
97template <
typename Node_Info = Empty_Class,
typename F_Type =
double>
145 max_cap(std::numeric_limits<Flow_Type>::max())
212 <<
"Node capacity cannot be negative";
265template <
class NodeT = Net_Cap_Node<Empty_Class,
double>,
266 class ArcT = Net_Arc<Empty_Class,
double>>
306 const Flow_Type& cap = std::numeric_limits<Flow_Type>::max())
309 <<
"Node capacity cannot be negative";
390 other.aux_net =
nullptr;
423 other.aux_net =
nullptr;
495 <<
"Auxiliary network has already been computed";
504 Node* p = it.get_curr();
523 Arc* arc = it.get_curr();
536 arc->cap, arc->flow,
false);
573 <<
"Auxiliary network has not been computed";
582 p->in_flow = arc->flow;
583 p->out_flow = arc->flow;
603 <<
"Auxiliary network has not been computed";
623 <<
"Auxiliary network has not been computed";
628 Node* p = it.get_curr();
645 Node* p = it.get_curr();
646 if (p->in_flow > p->max_cap || p->out_flow > p->max_cap)
665 Node* p = it.get_curr();
678 return node->max_cap;
691 <<
"Node capacity cannot be negative";
693 <<
"Current flow exceeds new capacity";
Exception handling system with formatted messages for Aleph-w.
#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.
Graph_Anode & operator=(const Graph_Anode &node)
Capacitated network with node capacity constraints.
Net_Cap_Graph & operator=(const Net_Cap_Graph &other)
Copy assignment operator.
static void set_node_cap(Node *node, const Flow_Type &cap)
Set the capacity of a node.
Net_Cap_Graph(const Net_Cap_Graph &other)
Copy constructor.
~Net_Cap_Graph()
Destructor.
bool has_aux_net() const noexcept
Check if auxiliary network has been computed.
const Aux_Net * get_aux_net() const noexcept
Get const pointer to the auxiliary network.
Aux_Net * get_aux_net() noexcept
Get pointer to the auxiliary network.
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.
typename Node::Node_Type Node_Type
Type of information stored in nodes.
Net_Cap_Graph & operator=(Net_Cap_Graph &&other) noexcept
Move assignment operator.
Node * insert_node(const Flow_Type &cap)
Insert a new node with default info and specified capacity.
static Flow_Type get_node_cap(const Node *node) noexcept
Get the capacity of a node.
typename Arc::Arc_Type Arc_Type
Type of information stored in arcs.
Net_Graph< Net_Node< Empty_Class >, Net_Arc< bool, Flow_Type > > Aux_Net
Auxiliary network type for solving node-capacitated networks.
Net_Cap_Graph(Net_Cap_Graph &&other) noexcept
Move constructor.
Node * insert_node()
Insert a new node with default info and unlimited capacity.
Net_Graph< NodeT, ArcT > Net_Class
Base network class type.
void free_aux_net()
Free the auxiliary network.
Flow_Type get_total_flow() const
Get the total flow value of the network.
void update()
Update flow values from auxiliary network to this network.
Node * insert_node(Node *p) override
bool check_node_capacities() const noexcept
Check if all node capacity constraints are satisfied.
void reset_flows() noexcept
Reset all flow values to zero.
Aux_Net * compute_aux_net()
Compute the equivalent arc-capacitated auxiliary network.
Net_Cap_Graph() noexcept
Default constructor.
typename Arc::Flow_Type Flow_Type
Type representing capacity and flow values.
Node with capacity constraint for flow networks.
F_Type Flow_Type
Type representing flow and capacity values.
Net_Cap_Node(const Net_Cap_Node &other)
Copy constructor.
void set_max_cap(const Flow_Type &cap)
Set the maximum capacity of this node.
Net_Cap_Node(Node_Info &&node_info) noexcept
Move constructor from node info.
Node_Info Node_Type
Type of information stored in the node.
Net_Cap_Node & operator=(const Net_Cap_Node &other)
Copy assignment operator.
Flow_Type in_flow
Tracked incoming flow (updated by update() after auxiliary net computation).
const Flow_Type & get_max_cap() const noexcept
Get the maximum capacity of this node.
Graph_Anode< Node_Info > Base
Flow_Type out_flow
Tracked outgoing flow (updated by update() after auxiliary net computation).
Net_Cap_Node(const Node_Info &node_info)
Construct a node with the given information.
Flow_Type max_cap
Maximum flow capacity that can pass through this node.
Net_Cap_Node() noexcept
Default constructor. Sets max_cap to the maximum possible value.
Net_Cap_Node(const Net_Cap_Node *node)
Copy constructor from another Net_Cap_Node.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the 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)
__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)
#define ARC_COOKIE(p)
Return the arc cookie
#define NODE_COOKIE(p)
Return the node cookie
void clear_graph(GT &g) noexcept
Clean a graph: all its nodes and arcs are removed and freed.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Iterator over arcs of a graph.
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 * 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.
Net_Graph & operator=(Net_Graph &&other) noexcept
Move-assign a network. O(1) operation.
Node * insert_node()
Insert a new node with default info.
Network flow graph structures.