96#ifndef TPL_NET_SUP_DEM_H
97#define TPL_NET_SUP_DEM_H
118template <
typename Node_Info,
typename F_Type =
long>
221template <
class NodeT = Net_Sup_Dem_Node<Empty_Class,
double>,
222 class ArcT = Net_Arc<Empty_Class,
double>>
332 <<
"Auxiliary net is already computed";
340 Node* p = it.get_curr();
341 if (p->supply_flow > 0)
344 <<
"Supply flow in node at " <<
static_cast<void*
>(p)
345 <<
" is greater than out capacity";
346 this->
insert_arc(super_source, p, p->supply_flow);
348 else if (p->supply_flow < 0)
351 <<
"Supply flow in node at " <<
static_cast<void*
>(p)
352 <<
" is smaller than in capacity";
406 <<
"Auxiliary net has not been computed";
441 <<
"Auxiliary net has not been computed";
445 Node* p = it.get_curr();
446 const Flow_Type& supply_flow = p->supply_flow;
448 if (supply_flow == 0)
451 if (supply_flow > 0
and p->out_flow < supply_flow)
476 Node* p = it.get_curr();
477 const Flow_Type& supply_flow = p->supply_flow;
479 if (supply_flow == 0)
482 if (supply_flow > 0
and p->out_flow < supply_flow)
509 <<
"Supply flow in node at " <<
static_cast<void*
>(p)
510 <<
" is greater than out capacity";
512 <<
"Supply flow in node at " <<
static_cast<void*
>(p)
513 <<
" is smaller than in capacity";
526 return p->supply_flow;
542 if (it.get_curr()->supply_flow > 0)
555 if (it.get_curr()->supply_flow < 0)
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Dynamic doubly linked list with O(1) size and bidirectional access.
T & append(const T &item)
Append a new item by copy.
Network graph with supply and demand nodes.
void non_feasible_nodes(DynDlist< Node * > &supply_list, DynDlist< Node * > &demand_list)
Get lists of nodes with unsatisfied supply/demand.
typename Node::Node_Type Node_Type
Type of information stored in nodes.
Node * get_super_sink() const noexcept
Get the super-sink node.
Node * super_sink
Super-sink for auxiliary network.
Node * get_super_source() const noexcept
Get the super-source node.
bool exist_aux_net() const noexcept
Check if the auxiliary network has been computed.
void free_aux_net()
Free the auxiliary network structures.
bool is_feasible() const
Check if the current flow is feasible.
typename Arc::Arc_Type Arc_Type
Type of information stored in arcs.
Node * super_source
Super-source for auxiliary network.
Flow_Type total_demand() const noexcept
Calculate total demand in the network.
Node * insert_node(const Flow_Type &supply)
Insert a node with supply/demand value only.
Net_Sup_Dem_Graph()=default
Default constructor.
typename Arc::Flow_Type Flow_Type
Type representing capacity and flow values.
Flow_Type get_supply_flow(Node *p) const noexcept
Get the supply/demand value for a node.
bool is_balanced() const noexcept
Check if the network is balanced.
~Net_Sup_Dem_Graph()
Destructor. Frees auxiliary network if it exists.
Net_Sup_Dem_Graph * compute_aux_net()
Compute the auxiliary capacitated network.
size_t count_demand_nodes() const noexcept
Count the number of demand nodes.
size_t count_supply_nodes() const noexcept
Count the number of supply nodes.
void set_supply_flow(Node *p, const Flow_Type &supply)
Set the supply/demand value for a node.
Flow_Type total_supply() const noexcept
Calculate total supply in the network.
Node * insert_node()
Insert a new node with default info.
Node * insert_node(const Node_Type &node_info, const Flow_Type &supply=0)
Insert a node with info and supply/demand value.
Net_Sup_Dem_Graph * get_aux_net() noexcept
Get the auxiliary network if it exists.
Node with supply/demand flow value.
const Flow_Type & get_supply_flow() const noexcept
Get the supply/demand flow value (const version).
Flow_Type & get_supply_flow() noexcept
Get the supply/demand flow value.
Net_Sup_Dem_Node(const Node_Info &node_info)
Construct node with info.
Flow_Type out_flow
Tracked outgoing flow.
Flow_Type in_flow
Tracked incoming flow.
Net_Sup_Dem_Node(Net_Sup_Dem_Node *node)
Copy constructor from pointer.
Flow_Type out_cap
Outgoing capacity constraint.
Flow_Type supply_flow
Supply flow value: positive = supply, negative = demand, zero = transit.
Flow_Type in_cap
Incoming capacity constraint.
F_Type Flow_Type
Type representing flow values.
Net_Sup_Dem_Node()
Default constructor. Initializes all values to zero.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Flow network implemented with adjacency lists.
size_t get_out_degree(Node *p) const noexcept
Return the out-degree of p (number of outgoing arcs).
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) noexcept override
Remove node p and all its arcs from the network.
Node * insert_node()
Insert a new node with default info.
size_t get_in_degree(Node *p) const noexcept
Return the in-degree of p (number of incoming arcs).
Network flow graph structures.