15 #ifndef PAAL_MIN_CUT_HPP
16 #define PAAL_MIN_CUT_HPP
18 #include <boost/graph/adjacency_list.hpp>
19 #include <boost/graph/boykov_kolmogorov_max_flow.hpp>
32 using Traits = boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::directedS>;
34 using Edge = Traits::edge_descriptor;
35 using Vertex = Traits::vertex_descriptor;
39 : m_graph(0), m_cap(get(boost::edge_capacity, m_graph)),
40 m_rev(get(boost::edge_reverse, m_graph)),
41 m_colors(get(boost::vertex_color, m_graph)) {}
46 void init(
int vertices_num) {
48 for (
int i = 0; i < vertices_num; ++i) {
51 m_cap =
get(boost::edge_capacity, m_graph);
52 m_rev =
get(boost::edge_reverse, m_graph);
74 std::tie(e, b) = add_edge(src, trg, m_graph);
75 std::tie(e_rev, b_rev) = add_edge(trg, src, m_graph);
79 put(m_cap, e_rev, rev_cap);
84 return std::make_pair(e, e_rev);
97 double min_cut_val = boost::boykov_kolmogorov_max_flow(m_graph, src, trg);
98 m_colors =
get(boost::vertex_color, m_graph);
99 m_src_color =
get(m_colors, src);
100 m_last_cut = std::make_pair(src, trg);
110 return (m_src_color ==
get(m_colors, v));
118 auto verts = vertices(m_graph);
119 return std::accumulate(verts.first, verts.second, 0,
120 [&](
int count, Vertex v) {
146 auto e = edge(src, trg, m_graph);
148 set_capacity(e.first, cap);
152 using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
153 boost::property<boost::vertex_color_t, boost::default_color_type,
154 boost::property<boost::vertex_distance_t, long,
155 boost::property<boost::vertex_predecessor_t, Edge>>>,
156 boost::property<boost::edge_capacity_t, double,
157 boost::property<boost::edge_residual_capacity_t, double,
158 boost::property<boost::edge_reverse_t, Edge>>>>;
159 using EdgeCapacity = boost::property_map<Graph, boost::edge_capacity_t>::type;
160 using EdgeReverse = boost::property_map<Graph, boost::edge_reverse_t>::type;
161 using VertexColors = boost::property_map<Graph, boost::vertex_color_t>::type;
167 VertexColors m_colors;
169 boost::default_color_type m_src_color;
170 std::pair<Vertex, Vertex> m_last_cut;
175 #endif // PAAL_MIN_CUT_HPP
std::pair< Edge, Edge > add_edge_to_graph(Vertex src, Vertex trg, double cap, double rev_cap=0.)
bool is_in_source_set(Vertex v) const
void set_capacity(Edge e, double cap)
Class for creating and modifying directed graphs with edge capacities and finding directed minimum cu...
void set_capacity(Vertex src, Vertex trg, double cap)
double find_min_cut(Vertex src, Vertex trg)
double get_capacity(Edge e) const
min_cut_finder()
Constructor.
Vertex add_vertex_to_graph()
int source_set_size() const
void init(int vertices_num)
std::pair< Vertex, Vertex > get_last_cut() const