32 #define TEST_NAME "base/graph_cut"
40 const std::vector<std::pair<int, int>> edges = {
41 {3, 4}, {3, 6}, {3, 5}, {0, 4}, {0, 1}, {0, 6}, {0, 7}, {0, 5},
42 {0, 2}, {4, 1}, {1, 6}, {1, 5}, {6, 7}, {7, 5}, {5, 2}, {3, 4}};
43 const std::vector<int> weights = {0, 3, 1, 3, 1, 2, 6, 1,
44 8, 1, 1, 80, 2, 1, 1, 4};
46 std::vector<char> cut_labels;
48 BOOST_CHECK_EQUAL(cut_weight, 7);
49 BOOST_CHECK_EQUAL(cut_labels.size(), 8);
50 for (
const auto& label : cut_labels) {
51 BOOST_CHECK_GE(label, 0);
52 BOOST_CHECK_LT(label, 2);
57 const std::vector<std::pair<int, int>> edges = {
58 {3, 4}, {3, 6}, {3, 5}, {0, 4}, {0, 1}, {0, 6}, {0, 7}, {0, 5}, {0, 2},
59 {4, 1}, {1, 6}, {1, 5}, {6, 7}, {7, 5}, {5, 2}, {3, 4}, {3, 4}};
60 const std::vector<int> weights = {0, 3, 1, 3, 1, 2, 6, 1, 8,
61 1, 1, 80, 2, 1, 1, 4, 4};
63 std::vector<char> cut_labels;
65 BOOST_CHECK_EQUAL(cut_weight, 7);
66 BOOST_CHECK_EQUAL(cut_labels.size(), 8);
67 for (
const auto& label : cut_labels) {
68 BOOST_CHECK_GE(label, 0);
69 BOOST_CHECK_LT(label, 2);
74 const std::vector<std::pair<int, int>> edges = {
75 {3, 4}, {3, 6}, {3, 5}, {0, 1}, {0, 6}, {0, 7}, {0, 5},
76 {0, 2}, {4, 1}, {1, 6}, {1, 5}, {6, 7}, {7, 5}, {5, 2}};
77 const std::vector<int> weights = {0, 3, 1, 3, 1, 2, 6, 1, 8, 1, 1, 80, 2, 1};
79 std::vector<char> cut_labels;
81 BOOST_CHECK_EQUAL(cut_weight, 2);
82 BOOST_CHECK_EQUAL(cut_labels.size(), 8);
83 for (
const auto& label : cut_labels) {
84 BOOST_CHECK_GE(label, 0);
85 BOOST_CHECK_LT(label, 2);
90 const std::vector<std::pair<int, int>> edges = {{0, 1}, {1, 2}, {3, 4}};
91 const std::vector<int> weights = {1, 3, 1};
93 std::vector<char> cut_labels;
95 BOOST_CHECK_EQUAL(cut_weight, 0);
96 BOOST_CHECK_EQUAL(cut_labels.size(), 5);
97 for (
const auto& label : cut_labels) {
98 BOOST_CHECK_GE(label, 0);
99 BOOST_CHECK_LT(label, 2);
104 const std::vector<std::pair<int, int>> edges = {
105 {3, 4}, {3, 6}, {3, 5}, {0, 4}, {0, 1}, {0, 6}, {0, 7}, {0, 5},
106 {0, 2}, {4, 1}, {1, 6}, {1, 5}, {6, 7}, {7, 5}, {5, 2}, {3, 4}};
107 const std::vector<int> weights = {0, 3, 1, 3, 1, 2, 6, 1,
108 8, 1, 1, 80, 2, 1, 1, 4};
110 BOOST_CHECK_EQUAL(cut_labels.size(), 8);
111 for (
const auto& label : cut_labels) {
112 BOOST_CHECK_GE(label.second, 0);
113 BOOST_CHECK_LT(label.second, 2);
118 const std::vector<std::pair<int, int>> edges = {
119 {3, 4}, {3, 6}, {3, 5}, {0, 4}, {0, 1}, {0, 6}, {0, 7}, {0, 5}, {0, 2},
120 {4, 1}, {1, 6}, {1, 5}, {6, 7}, {7, 5}, {5, 2}, {3, 4}, {3, 4}};
121 const std::vector<int> weights = {0, 3, 1, 3, 1, 2, 6, 1, 8,
122 1, 1, 80, 2, 1, 1, 4, 4};
124 BOOST_CHECK_EQUAL(cut_labels.size(), 8);
125 for (
const auto& label : cut_labels) {
126 BOOST_CHECK_GE(label.second, 0);
127 BOOST_CHECK_LT(label.second, 2);
132 const std::vector<std::pair<int, int>> edges = {
133 {3, 4}, {3, 6}, {3, 5}, {0, 1}, {0, 6}, {0, 7}, {0, 5},
134 {0, 2}, {4, 1}, {1, 6}, {1, 5}, {6, 7}, {7, 5}, {5, 2}};
135 const std::vector<int> weights = {0, 3, 1, 3, 1, 2, 6, 1, 8, 1, 1, 80, 2, 1};
137 BOOST_CHECK_EQUAL(cut_labels.size(), 8);
138 for (
const auto& label : cut_labels) {
139 BOOST_CHECK_GE(label.second, 0);
140 BOOST_CHECK_LT(label.second, 2);
145 const std::vector<std::pair<int, int>> edges = {{0, 1}, {1, 2}, {3, 4}};
146 const std::vector<int> weights = {1, 3, 1};
148 BOOST_CHECK_EQUAL(cut_labels.size(), 5);
149 for (
const auto& label : cut_labels) {
150 BOOST_CHECK_GE(label.second, 0);
151 BOOST_CHECK_LT(label.second, 2);
157 BOOST_CHECK_EQUAL(graph.
NumNodes(), 2);
158 BOOST_CHECK_EQUAL(graph.
NumEdges(), 0);
162 BOOST_CHECK_EQUAL(graph.
NumEdges(), 10);
163 BOOST_CHECK_EQUAL(graph.
Compute(), 6);
173 BOOST_CHECK_EQUAL(graph.
NumEdges(), 10);
174 BOOST_CHECK_EQUAL(graph.
Compute(), 3);
185 BOOST_CHECK_EQUAL(graph.
NumEdges(), 12);
186 BOOST_CHECK_EQUAL(graph.
Compute(), 9);
bool IsConnectedToSource(const node_t node_idx) const
void AddNode(const node_t node_idx, const value_t source_capacity, const value_t sink_capacity)
bool IsConnectedToSink(const node_t node_idx) const
void AddEdge(const node_t node_idx1, const node_t node_idx2, const value_t capacity, const value_t reverse_capacity)
BOOST_AUTO_TEST_CASE(TestComputeMinGraphCutStoerWagner)
std::unordered_map< int, int > ComputeNormalizedMinGraphCut(const std::vector< std::pair< int, int >> &edges, const std::vector< int > &weights, const int num_parts)
void ComputeMinGraphCutStoerWagner(const std::vector< std::pair< int, int >> &edges, const std::vector< int > &weights, int *cut_weight, std::vector< char > *cut_labels)