From 3211531d3f93cdb4aa9a61284e24e089bc7fab09 Mon Sep 17 00:00:00 2001 From: Vihan Shah Date: Wed, 10 Jul 2024 23:24:22 -0400 Subject: [PATCH] Added some unit tests --- src/KEdgeConnect.cpp | 18 +++++----- tools/process_stream.cpp | 74 ++++++++++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 24 deletions(-) diff --git a/src/KEdgeConnect.cpp b/src/KEdgeConnect.cpp index 18cc09db..79b30528 100644 --- a/src/KEdgeConnect.cpp +++ b/src/KEdgeConnect.cpp @@ -65,33 +65,33 @@ void KEdgeConnect::query() { std::vector>> temp_forest; for(unsigned int i=0;icalc_spanning_forest(); forests_collection.push_back(temp_forest); for (unsigned int j = 0; j < temp_forest.size(); j++) { - std::cout << temp_forest[j].first << ":"; + //std::cout << temp_forest[j].first << ":"; for (auto dst: temp_forest[j].second) { - std::cout << " " << dst; + //std::cout << " " << dst; temp_edge.edge.src = temp_forest[j].first; temp_edge.edge.dst = dst; for (int l=i+1;lupdate(temp_edge); } } - std::cout << std::endl; + //std::cout << std::endl; } } - std::cout << "THE LAST SPANNING FOREST" << std::endl; + //std::cout << "THE LAST SPANNING FOREST" << std::endl; temp_forest = cc_alg[num_forest-1]->calc_spanning_forest(); forests_collection.push_back(temp_forest); for (unsigned int j = 0; j < temp_forest.size(); j++) { - std::cout << temp_forest[j].first << ":"; + //std::cout << temp_forest[j].first << ":"; for (auto dst: temp_forest[j].second) { - std::cout << " " << dst; + //std::cout << " " << dst; } - std::cout << std::endl; + //std::cout << std::endl; } -} \ No newline at end of file +} diff --git a/tools/process_stream.cpp b/tools/process_stream.cpp index 51bc7539..2fdf56ee 100644 --- a/tools/process_stream.cpp +++ b/tools/process_stream.cpp @@ -14,6 +14,13 @@ // TODO: make num_edge_connect an input argument; // TODO: Daniel's concern: right now, the deletion of the edge to the stream makes the query only possible to be supported once -- fix this later +int ctr_x=0; +int ctr_y=0; + +unsigned long long ctr_z=0; +unsigned long long ctr_o=0; +unsigned long long ctr_t=0; + static bool shutdown = false; @@ -22,7 +29,7 @@ class MinCutSimple { const node_id_t num_nodes; unsigned int num_forest; // this value is k in the k-edge connectivity unsigned int num_subgraphs; - const int my_prime = 100003; // Prime number for polynomial hashing + const int my_prime = 44497; // Prime number for polynomial hashing std::vector> hash_coefficients; std::vector> k_edge_algs; std::vector mincut_values; @@ -31,12 +38,15 @@ class MinCutSimple { explicit MinCutSimple(node_id_t num_nodes, const std::vector> &config_vec): num_nodes(num_nodes) { num_subgraphs = (unsigned int)(2*std::ceil(std::log2(num_nodes))); + std::cout<<"Number of subgraphs(constructor):"<(num_nodes, num_forest, config_vec[i])); } // Initialize coefficients randomly + //std::cout<<"hash coeffs (constructor):"< dist_coeff(1, my_prime - 1); // random numbers between 1 and p-1 @@ -44,9 +54,12 @@ class MinCutSimple { std::vector this_subgraph_coeff; for (int j = 0; j < num_subgraphs; j++) { this_subgraph_coeff.push_back(dist_coeff(gen_ind)); + //std::cout<& coefficients, unsigned int src_vertex, unsigned int dst_vertex) { - int hash_val = 0; + unsigned int hash_val = 0; if (src_vertex>dst_vertex){ std::swap(src_vertex, dst_vertex); } @@ -86,6 +99,16 @@ class MinCutSimple { for (int i = 0; i < coefficients.size(); ++i) { hash_val = (hash_val + coefficients[i] * power(edge_id, i, my_prime)) % my_prime; } + //std::cout<<"Hash val inside hash func: "<<(hash_val % 2)<=0) { k_edge_algs[i]->apply_update_batch(thr_id, src_vertex, input_dst_vertices); + //std::cout<<"Nbhd size in round "<=0) { + while (dst_end_index[position].second <= i+1 && position>=0) { input_dst_vertices.pop_back(); position--; } @@ -172,6 +210,7 @@ class MinCutSimple { std::ofstream metis_file(file_name); std::cout << "Writing METIS file...\n"; + std::cout<<"no of vertices and edges "<< num_nodes << " " << num_edge << std::endl; // could be a hidden bug later -- at the moment, num_nodes is taken from the class metis_file << num_nodes << " " << num_edge << " 0" << "\n"; @@ -198,13 +237,13 @@ class MinCutSimple { continue; } new_count++; - }} - std::cout<<"new count: "<> nodes_list; std::vector>> current_forest; @@ -212,6 +251,7 @@ class MinCutSimple { // easy version: check from the i=0 to i=log n without using an additional layer of binary search k_edge_algs[i]->query(); // This creates the k forests unsigned int k = k_edge_algs[i]->forests_collection.size(); + std::cout<<"query func, k= "<forests_collection[j]; for(auto v_neighbors_pair: current_forest){ @@ -226,9 +266,6 @@ class MinCutSimple { // run the min-cut algorithm -- stolen from gpu min-cut std::string file_name = "temp-graph-min-cut.metis"; std::string output_name = "mincut.txt"; - // ************** test with a dummy cut value first **************** - //unsigned int cut_value = 5; - //mincut_values.push_back(cut_value); std::string command = "./mincut_parallel " + file_name + " exact >" + output_name; // Run VieCut and store the output std::system(command.data()); @@ -413,7 +450,9 @@ int main(int argc, char **argv) { std::cout << std::endl; num_subgraphs = (unsigned int)(2*std::ceil(std::log2(num_nodes))); - num_edge_connect = 10*num_subgraphs; + num_edge_connect = 2*num_subgraphs; + std::cout<<"Number of subgraphs:"<> config_vec; @@ -436,12 +475,9 @@ int main(int argc, char **argv) { driver.process_stream_until(END_OF_STREAM); - std::cout<<"************* Checkpoint 5 *******************"<