85template <
typename Flow_Type>
155 Arc* arc = it.get_curr();
182 Arc* arc =
ait.get_curr();
208 Arc* arc = it.get_curr();
223 Arc* arc = it.get_curr();
228 if (src == super_source
or tgt == super_sink)
258 Arc* arc =
ait.get_curr();
269 result.
feasible = (max_flow == total_demand);
280 Arc* arc = it.get_curr();
302 Arc* arc =
ait.get_curr();
320 Arc* arc =
ait.get_curr();
344 Arc* arc =
ait.get_curr();
369 Arc* arc = it.get_curr();
396template <
typename Value_Type>
405 const std::vector<size_t>&
prereqs = {},
406 const std::string&
name_ =
"")
413template <
typename Value_Type>
455template <
typename Value_Type>
469 const Value_Type
INF = std::numeric_limits<Value_Type>::max() / 2;
489 Value_Type
source_cap = (p > 0) ? p : Value_Type{0};
496 Value_Type
sink_cap = (p < 0) ? -p : Value_Type{0};
527 auto arc = it.get_curr();
536 residual = arc->cap - arc->flow;
538 residual = arc->flow;
540 if (residual > Value_Type{0})
580 Team(
const std::string& n =
"",
int w = 0,
int l = 0,
int r = 0)
642 for (
size_t i = 0; i <
teams.
size(); ++i)
653 const int INF = 1000000;
660 for (
size_t i = 0; i <
teams.
size(); ++i)
675 for (
size_t i = 0; i <
teams.
size(); ++i)
680 for (
size_t j = i + 1; j <
teams.
size(); ++j)
722 auto arc = it.get_curr();
729 (arc->cap - arc->flow) : arc->flow;
739 for (
size_t i = 0; i <
teams.
size(); ++i)
799template <
typename Value_Type>
801 size_t rows,
size_t cols,
802 const std::vector<std::vector<std::array<Value_Type, 2>>>&
data_cost,
810 result.
labels.resize(rows, std::vector<int>(cols, 0));
812 if (rows == 0
or cols == 0)
822 std::vector<std::vector<Node*>>
pixels(rows, std::vector<Node*>(cols));
823 for (
size_t i = 0; i < rows; ++i)
824 for (
size_t j = 0; j < cols; ++j)
829 for (
size_t i = 0; i < rows; ++i)
830 for (
size_t j = 0; j < cols; ++j)
842 for (
size_t i = 0; i < rows; ++i)
843 for (
size_t j = 0; j < cols; ++j)
882 auto arc = it.get_curr();
889 (arc->cap - arc->flow) : arc->flow;
891 if (residual > Value_Type{0})
900 for (
size_t i = 0; i < rows; ++i)
901 for (
size_t j = 0; j < cols; ++j)
1014 auto arc = it.get_curr();
1034 auto arc = it.get_curr();
WeightedDigraph::Node Node
bool has_curr() const noexcept
Check if there is a current valid item.
Dynamic queue of elements of generic type T based on single linked list.
T & put(const T &data)
The type of element.
T get()
Remove the oldest item of the queue.
T & front()
Return a modifiable reference to the oldest item in the queue.
bool is_empty() const noexcept
Return true if this is empty.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
void empty() noexcept
empty the list
Generic key-value map implemented on top of a binary search tree.
Dynamic set backed by balanced binary search trees with automatic memory management.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
size_t size() const noexcept
Count the number of elements of the list.
Filtered iterator on the nodes of a graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source 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.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Net_Graph< Net_Node< string >, Net_Arc< Empty_Class, FlowType > > Net
Main namespace for Aleph-w library functions.
BaseballEliminationResult check_baseball_elimination(const std::vector< Team > &teams, size_t team_idx)
Check if a team is mathematically eliminated from winning.
Net::Flow_Type dinic_maximum_flow(Net &net)
Compute maximum flow using Dinic's algorithm.
ProjectSelectionResult< Value_Type > solve_project_selection(const std::vector< Project< Value_Type > > &projects)
Solve project selection problem using max-flow.
SegmentationResult segment_image(size_t rows, size_t cols, const std::vector< std::vector< std::array< Value_Type, 2 > > > &data_cost, Value_Type smoothness)
Segment image using graph cuts.
SurveyDesignResult design_survey(const std::vector< SurveyQuestion > &questions, const std::vector< SurveyRespondent > &respondents)
Design survey assignment using network flow.
CirculationResult< typename Net::Flow_Type > solve_circulation(Net &net, GetDemand get_demand, GetLower get_lower)
Solve a circulation problem with demands.
Net::Flow_Type min_cut(Net &net, DynSetTree< typename Net::Node * > &vs, DynSetTree< typename Net::Node * > &vt, DynList< typename Net::Arc * > &cuts, DynList< typename Net::Arc * > &cutt)
Compute max flow and the corresponding minimum cut.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Filtered iterator on all the arcs of a graph.
Result of baseball elimination check.
std::vector< size_t > certificate
Teams that form elimination certificate.
int max_possible_wins
Maximum wins team can achieve.
bool eliminated
Is the team mathematically eliminated?
Result of a circulation problem.
bool feasible
Is there a feasible circulation?
Flow_Type excess_flow
Flow needed to satisfy demands.
DynMapTree< void *, Flow_Type > flow
Flow on each edge (arc pointer -> flow)
Functor wrapper for Dinic's algorithm.
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.
void make_super_source()
Convert a multi-source network into a single super-source network.
void make_super_sink()
Convert a multi-sink network into a single super-sink network.
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.
typename Arc::Flow_Type Flow_Type
Capacity/flow numeric type.
void remove_node(Node *p) noexcept override
Remove node p and all its arcs from the network.
size_t get_in_degree(Node *p) const noexcept
Return the in-degree of p (number of incoming arcs).
Result of project selection.
Value_Type max_profit
Maximum achievable profit.
std::vector< size_t > selected
IDs of selected projects.
Value_Type total_cost
Sum of negative profits (costs)
Value_Type total_revenue
Sum of positive profits.
Project with profit and dependencies.
Value_Type profit
Profit (positive) or cost (negative)
size_t id
Unique project ID.
std::string name
Optional name.
std::vector< size_t > prerequisites
IDs of prerequisite projects.
Project(size_t id_, Value_Type profit_, const std::vector< size_t > &prereqs={}, const std::string &name_="")
Result of binary image segmentation.
std::vector< std::vector< int > > labels
0 or 1 for each pixel
double energy
Total energy of segmentation.
std::vector< std::pair< size_t, size_t > > assignments
(respondent, question)
Survey question with constraints.
int max_responses
Maximum responses accepted.
int min_responses
Minimum number of responses needed.
Survey respondent with constraints.
std::vector< size_t > eligible_questions
Questions this respondent can answer.
int min_questions
Minimum questions to answer.
int max_questions
Maximum questions can answer.
Team information for baseball elimination.
std::vector< int > against
Games remaining against each team.
Team(const std::string &n="", int w=0, int l=0, int r=0)
int remaining
Games remaining.
Dynamic queue implementation based on linked lists.
Dynamic set implementations based on balanced binary search trees.
Advanced maximum flow algorithms.
Network flow graph structures.
Maximum flow minimum cost network algorithms.