84template <
typename Flow_Type>
153 Arc *arc = it.get_curr();
180 Arc *arc =
ait.get_curr();
206 Arc *arc = it.get_curr();
221 Arc *arc = it.get_curr();
226 if (src == super_source
or tgt == super_sink)
264 result.
feasible = (max_flow == total_demand);
275 Arc *arc = it.get_curr();
297 Arc *arc =
ait.get_curr();
315 Arc *arc =
ait.get_curr();
339 Arc *arc =
ait.get_curr();
364 Arc *arc = it.get_curr();
390template <
typename Value_Type>
399 const std::string &name_ =
"")
407template <
typename Value_Type>
449template <
typename Value_Type>
461 const Value_Type INF = std::numeric_limits<Value_Type>::max() / 2;
469 for (
size_t i = 0; i <
projects.size(); ++i)
475 for (
size_t i = 0; i <
projects.size(); ++i)
481 Value_Type
source_cap = (p > 0) ? p : Value_Type{0};
488 Value_Type
sink_cap = (p < 0) ? -p : Value_Type{0};
517 auto arc = it.get_curr();
526 residual = arc->cap - arc->flow;
528 residual = arc->flow;
530 if (residual > Value_Type{0})
539 for (
size_t i = 0; i <
projects.size(); ++i)
567 Team(
const std::string &n =
"",
int w = 0,
int l = 0,
int r = 0)
630 for (
size_t i = 0; i <
teams.size(); ++i)
645 for (
size_t i = 0; i <
teams.size(); ++i)
657 for (
size_t i = 0; i <
teams.size(); ++i)
662 for (
size_t j = i + 1; j <
teams.size(); ++j)
670 constexpr int INF = 1000000;
705 const auto arc = it.get_curr();
711 if (
const int residual =
712 (net.
get_src_node(arc) == u) ? (arc->cap - arc->flow) : arc->flow;
721 for (
size_t i = 0; i <
teams.size(); ++i)
779template <
typename Value_Type>
781 const std::vector<std::vector<std::array<Value_Type, 2>>> &
data_cost,
800 std::vector<std::vector<Node *>> pixels(
rows, std::vector<Node *>(
cols));
801 for (
size_t i = 0; i <
rows; ++i)
802 for (
size_t j = 0; j <
cols; ++j)
807 for (
size_t i = 0; i <
rows; ++i)
808 for (
size_t j = 0; j <
cols; ++j)
820 for (
size_t i = 0; i <
rows; ++i)
821 for (
size_t j = 0; j <
cols; ++j)
860 auto arc = it.get_curr();
866 Value_Type residual = (net.
get_src_node(arc) == u) ? (arc->cap - arc->flow) : arc->flow;
868 if (residual > Value_Type{0})
877 for (
size_t i = 0; i <
rows; ++i)
878 for (
size_t j = 0; j <
cols; ++j)
949 for (
size_t i = 0; i <
questions.size(); ++i)
983 for (
size_t i = 0; i <
questions.size(); ++i)
987 if (
const auto arc = it.get_curr(); net.
get_tgt_node(arc) == sink)
1001 if (
const auto arc = it.get_curr(); arc->flow > 0)
1005 for (
size_t q = 0; q <
questions.size(); ++q)
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.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
Generic key-value map implemented on top of a binary search tree.
Dynamic set backed by balanced binary search trees with automatic memory management.
const size_t & size() const
Returns the cardinality of the set.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
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)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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.
and
Check uniqueness with explicit hash + equality functors.
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.
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.