Skip to content

Commit

Permalink
Developing version to verify whether the obtained CCs are the same.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhwjhw0123 committed Feb 21, 2024
1 parent 1b079de commit 902cf28
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/util/mat_graph_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ void MatGraphVerifier::verify_soln(std::vector<std::set<node_id_t>> &retval) {
std::sort(temp.begin(),temp.end());
std::sort(kruskal_ref.begin(),kruskal_ref.end());
if (kruskal_ref != temp)
std::cout << std::endl;
std::cout << "The size of temp is "<< temp.size() << std::endl;
std::cout << "The size of kruskal_ref is "<< kruskal_ref.size() << std::endl;
for (int i=0; i<kruskal_ref.size();i++) {
std::cout << "The nodes in the "<< (i+1) << "-th temp" << std::endl;
for (auto temp_node: temp[i]) {
std::cout << temp_node << " ";
}
std::cout << std::endl;
std::cout << "The nodes in the "<< (i+1) << "-th first kruskal" << std::endl;
for (auto krus_node: kruskal_ref[i]) {
std::cout << krus_node << " ";
}
std::cout << std::endl;
}
throw IncorrectCCException();

std::cout << "Solution ok: " << retval.size() << " CCs found." << std::endl;
Expand Down
22 changes: 22 additions & 0 deletions tools/process_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <graph_sketch_driver.h>
#include <sys/resource.h> // for rusage
#include <test/mat_graph_verifier.h>
#include <map>

#include <thread>

Expand Down Expand Up @@ -218,6 +219,27 @@ int main(int argc, char **argv) {
std::vector<std::pair<node_id_t, std::vector<node_id_t>>> temp_forest;
for(unsigned int i=0;i<num_edge_connect;i++) {
temp_forest = k_edge_alg.forests_collection[i];
// Test the maximality of the connected components
DisjointSetUnion<node_id_t> kruskal_dsu(num_nodes);
std::vector<std::set<node_id_t>> temp_retval;
for (unsigned int l = 0; l < temp_forest.size(); l++) {
for (unsigned int j = 0; j < temp_forest[l].second.size(); j++) {
kruskal_dsu.merge(temp_forest[l].first, temp_forest[l].second[j]);
}
}
std::map<node_id_t, std::set<node_id_t>> temp_map;
for (unsigned l = 0; l < num_nodes; ++l) {
temp_map[kruskal_dsu.find_root(l)].insert(l);
}
temp_retval.reserve(temp_map.size());
for (const auto& entry : temp_map) {
temp_retval.push_back(entry.second);
}
std::cout<< std::endl;
kEdgeVerifier.reset_cc_state();
kEdgeVerifier.verify_soln(temp_retval);
// End of the test of CC maximality
// start of the test of CC edge existence
for (unsigned int j = 0; j < temp_forest.size(); j++) {
for (auto dst: temp_forest[j].second) {
temp_edge.src = temp_forest[j].first;
Expand Down

0 comments on commit 902cf28

Please sign in to comment.