diff --git a/include/test/file_graph_verifier.h b/include/test/file_graph_verifier.h index cf416c4e..4c717923 100644 --- a/include/test/file_graph_verifier.h +++ b/include/test/file_graph_verifier.h @@ -11,14 +11,11 @@ */ class FileGraphVerifier : public GraphVerifier { std::vector> kruskal_ref; - std::vector> boruvka_cc; - DisjointSetUnion sets; public: FileGraphVerifier(node_id_t n, const std::string& input_file); void verify_edge(Edge edge); - void verify_cc(node_id_t node); void verify_soln(std::vector>& retval); /** diff --git a/include/test/graph_verifier.h b/include/test/graph_verifier.h index d318c6e3..c2aab207 100644 --- a/include/test/graph_verifier.h +++ b/include/test/graph_verifier.h @@ -13,29 +13,19 @@ class GraphVerifier { public: /** - * Verifies an edge exists in the graph. Verifies that the edge is in the cut - * of both the endpoints of the edge. + * Verifies an edge exists in the graph. * @param edge the edge to be tested. - * @param det_graph the adjacency list representation of the graph in question. - * @throws BadEdgeException if the edge does not satisfy both conditions. + * @throws BadEdgeException if the edge does not exist in the graph. */ virtual void verify_edge(Edge edge) = 0; - /** - * Verifies the supernode of the given node is a (maximal) connected component. - * That is, there are no edges in its cut. - * @param node the node to be tested. - * @throws NotCCException if the supernode is not a connected component. - */ - virtual void verify_cc(node_id_t node) = 0; - /** * Verifies the connected components solution is correct. Compares * retval against kruskal_ref. */ virtual void verify_soln(std::vector> &retval) = 0; - std::vector> extract_adj_matrix() {return adj_matrix;} + std::vector> extract_adj_matrix() { return adj_matrix; } GraphVerifier() = default; GraphVerifier(std::vector> _adj) : adj_matrix(std::move(_adj)) {}; @@ -49,12 +39,6 @@ class BadEdgeException : public std::exception { } }; -class NotCCException : public std::exception { - virtual const char* what() const throw() { - return "The supernode is not a connected component. It has edges in its cut!"; - } -}; - class IncorrectCCException : public std::exception { virtual const char* what() const throw() { return "The connected components are incorrect!"; diff --git a/include/test/mat_graph_verifier.h b/include/test/mat_graph_verifier.h index 07aeeb16..6b1138bc 100644 --- a/include/test/mat_graph_verifier.h +++ b/include/test/mat_graph_verifier.h @@ -11,10 +11,7 @@ */ class MatGraphVerifier : public GraphVerifier { std::vector> kruskal_ref; - std::vector> boruvka_cc; - node_id_t n; - DisjointSetUnion sets; /** * Runs Kruskal's (deterministic) CC algo. @@ -27,12 +24,11 @@ class MatGraphVerifier : public GraphVerifier { // When we want to build a MatGraphVerifier without iterative edge_updates MatGraphVerifier(node_id_t n, std::vector> _adj) - : GraphVerifier(_adj), n(n), sets(n) { reset_cc_state(); }; + : GraphVerifier(_adj), n(n) { reset_cc_state(); }; void reset_cc_state(); // run this function before using as a verifier in CC void edge_update(node_id_t src, node_id_t dst); void verify_edge(Edge edge); - void verify_cc(node_id_t node); void verify_soln(std::vector> &retval); }; diff --git a/src/graph.cpp b/src/graph.cpp index 93af2bb0..ddedbe71 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -169,12 +169,8 @@ inline std::vector> Graph::supernodes_to_merge( new_reps.push_back(i); continue; } - if (ret_code == ZERO) { -#ifdef VERIFY_SAMPLES_F - verifier->verify_cc(i); -#endif + if (ret_code == ZERO) continue; - } // query dsu node_id_t a = get_parent(edge.src); diff --git a/test/util/file_graph_verifier.cpp b/test/util/file_graph_verifier.cpp index dc40103f..854dcc19 100644 --- a/test/util/file_graph_verifier.cpp +++ b/test/util/file_graph_verifier.cpp @@ -5,7 +5,7 @@ #include #include -FileGraphVerifier::FileGraphVerifier(node_id_t n, const std::string &input_file) : sets(n) { +FileGraphVerifier::FileGraphVerifier(node_id_t n, const std::string &input_file) { std::ifstream in(input_file); if (!in) { throw std::invalid_argument("FileGraphVerifier: Could not open: " + input_file); @@ -19,7 +19,6 @@ FileGraphVerifier::FileGraphVerifier(node_id_t n, const std::string &input_file) if (num_nodes != n) throw std::invalid_argument("num_nodes != n in FileGraphVerifier"); for (unsigned i = 0; i < n; ++i) { - boruvka_cc.push_back({i}); adj_matrix.emplace_back(n - i); } while (m--) { @@ -63,23 +62,6 @@ void FileGraphVerifier::verify_edge(Edge edge) { printf("Got an error on edge (%u, %u): edge is not in graph!\n", edge.src, edge.dst); throw BadEdgeException(); } - - DSUMergeRet ret = sets.merge(edge.src, edge.dst); - if (!ret.merged) { - printf("Got an error of node (%u, %u): components already joined!\n", edge.src, edge.dst); - throw BadEdgeException(); - } - - // if all checks pass, merge supernodes - for (auto& i : boruvka_cc[ret.child]) boruvka_cc[ret.root].insert(i); -} - -void FileGraphVerifier::verify_cc(node_id_t node) { - node = sets.find_root(node); - for (const auto& cc : kruskal_ref) { - if (boruvka_cc[node] == cc) return; - } - throw NotCCException(); } void FileGraphVerifier::verify_soln(std::vector> &retval) { diff --git a/test/util/graph_verifier_test.cpp b/test/util/graph_verifier_test.cpp index a3c9f6b6..85d852c1 100644 --- a/test/util/graph_verifier_test.cpp +++ b/test/util/graph_verifier_test.cpp @@ -18,26 +18,13 @@ TEST(DeterministicToolsTestSuite, TestEdgeVerifier) { // throw on nonexistent edge ASSERT_THROW(verifier.verify_edge({69,420}), BadEdgeException); ASSERT_THROW(verifier.verify_edge({420,69}), BadEdgeException); - // throw on already-included edge - ASSERT_THROW(verifier.verify_edge({120,240}), BadEdgeException); - ASSERT_THROW(verifier.verify_edge({240,120}), BadEdgeException); - // throw on edge within the same set - ASSERT_THROW(verifier.verify_edge({250,1000}), BadEdgeException); - ASSERT_THROW(verifier.verify_edge({1000,250}), BadEdgeException); } TEST(DeterministicToolsTestSuite, TestCCVerifier) { FileGraphVerifier verifier (1024, curr_dir+"/../res/multiples_graph_1024.txt"); // {0}, {1}, and primes \in [521,1021] are CCs - verifier.verify_cc(0); - verifier.verify_cc(1); - verifier.verify_cc(911); // add edges of the form {i,2i} for (node_id_t i = 2; i < 512; ++i) { verifier.verify_edge({i, i*2}); } - // nothing else is currently a CC - for (int i = 2; i < 512; ++i) { - ASSERT_THROW(verifier.verify_cc(i), NotCCException); - } } diff --git a/test/util/mat_graph_verifier.cpp b/test/util/mat_graph_verifier.cpp index 2ceba25c..8c2db81a 100644 --- a/test/util/mat_graph_verifier.cpp +++ b/test/util/mat_graph_verifier.cpp @@ -5,7 +5,7 @@ #include #include -MatGraphVerifier::MatGraphVerifier(node_id_t n) : n(n), sets(n) { +MatGraphVerifier::MatGraphVerifier(node_id_t n) : n(n) { adj_matrix = std::vector>(n); for (node_id_t i = 0; i < n; ++i) adj_matrix[i] = std::vector(n - i); @@ -23,10 +23,6 @@ void MatGraphVerifier::edge_update(node_id_t src, node_id_t dst) { void MatGraphVerifier::reset_cc_state() { kruskal_ref = kruskal(); - sets.reset(); - boruvka_cc.clear(); - for (node_id_t i = 0; i < n; ++i) - boruvka_cc.push_back({i}); } std::vector> MatGraphVerifier::kruskal() { @@ -58,23 +54,6 @@ void MatGraphVerifier::verify_edge(Edge edge) { printf("Got an error on edge (%u, %u): edge is not in adj_matrix\n", edge.src, edge.dst); throw BadEdgeException(); } - - DSUMergeRet ret = sets.merge(edge.src, edge.dst); // perform the merge - if (!ret.merged) { - printf("Got an error on edge (%u, %u): components already joined!\n", edge.src, edge.dst); - throw BadEdgeException(); - } - - // if all checks pass, update boruvka_cc by merging in set elements of child - for (auto& i : boruvka_cc[ret.child]) boruvka_cc[ret.root].insert(i); -} - -void MatGraphVerifier::verify_cc(node_id_t node) { - node = sets.find_root(node); - for (const auto& cc : kruskal_ref) { - if (boruvka_cc[node] == cc) return; - } - throw NotCCException(); } void MatGraphVerifier::verify_soln(std::vector> &retval) {