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";
275template <
class NodeT = Net_Cap_Node<Empty_Class,
double>,
276 class ArcT = Net_Arc<Empty_Class,
double>>
361 const Flow_Type& cap = std::numeric_limits<Flow_Type>::max())
364 <<
"Node capacity cannot be negative";
462 const Node* q = jt.get_curr();
463 p->max_cap = q->max_cap;
464 p->in_flow = q->in_flow;
465 p->out_flow = q->out_flow;
479 other.aux_net =
nullptr;
513 std::swap(
aux_net, other.aux_net);
530 other.aux_net =
nullptr;
598 <<
"Auxiliary network has already been computed";
607 Node* p = it.get_curr();
626 Arc* arc = it.get_curr();
639 arc->cap, arc->flow,
false);
652 if (aux_net !=
nullptr)
682 <<
"Auxiliary network has not been computed";
686 <<
"The network changed after compute_aux_net(): free its auxiliary"
687 <<
" network and compute it again";
696 p->in_flow = arc->flow;
697 p->out_flow = arc->flow;
718 <<
"Auxiliary network has not been computed";
737 <<
"Auxiliary network has not been computed";
753 Node* p = it.get_curr();
754 if (p->in_flow > p->max_cap || p->out_flow > p->max_cap)
773 Node* p = it.get_curr();
786 return node->max_cap;
799 <<
"Node capacity cannot be negative";
801 <<
"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.
void remove_arc(Arc *arc) override
Remove the arc arc from the network, as Net_Graph::remove_arc() does.
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.
void swapped() noexcept final
What swap() calls on each of its two networks, once their nodes and arcs are exchanged: nothing,...
Net_Cap_Graph & operator=(Net_Cap_Graph &&other) noexcept
Move assignment operator.
struct Aleph::Net_Cap_Graph::Aux_Stamp aux_stamp
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 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.
void remove_node(Node *p) override
Remove the node p and its arcs from the network, as Net_Graph::remove_node() does.
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.
void swap(Net_Cap_Graph &other) noexcept
Swap contents with another network, with their auxiliary networks.
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.
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)
void *& get_cookie() noexcept
Return a modifiable reference to graph's cookie.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
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)
Clean a graph: all its nodes and arcs are removed and freed.
Main namespace for Aleph-w library functions.
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.
void remove_arc(Arc *arc) override
Remove arc arc from the network.
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.
Flow_Type flow_value() const
Return the total flow value of the network: the flow out of its sources, which a valid flow also take...
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,...
Node * insert_node()
Insert a new node with default info.
Node * get_curr() const
Return the current node.
Network flow graph structures.