From bc5c51b294a20167407e73c9dd8a07f7b728ad96 Mon Sep 17 00:00:00 2001 From: Eric Hein Date: Wed, 4 Jan 2017 10:25:49 -0500 Subject: [PATCH] Added validation for random graph construction. After the graph has been constructed, dumps all the edges to a list and compares with the list of randomly generated edges. --- .../bench_graphConstruct/graphconstruct.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/benchmark/bench_graphConstruct/graphconstruct.cpp b/benchmark/bench_graphConstruct/graphconstruct.cpp index 1b006ce..f5040b9 100644 --- a/benchmark/bench_graphConstruct/graphconstruct.cpp +++ b/benchmark/bench_graphConstruct/graphconstruct.cpp @@ -8,6 +8,7 @@ #include "perf.h" #include "openG.h" #include "omp.h" +#include #ifdef SIM #include "SIM.h" #endif @@ -112,6 +113,36 @@ void parallel_randomgraph_construction(graph_t &g, size_t vertex_num, size_t edg #endif } + + cout << "Validating random graph..."; + // Check to make sure the graph was constructed correctly + vector> actual_edges; + actual_edges.reserve(edge_num); + + for (vertex_iterator vit = g.vertices_begin(); vit != g.vertices_end(); ++vit) + { + for (edge_iterator eit = vit->out_edges_begin(); eit != vit->out_edges_end(); ++eit) + { + actual_edges.push_back(make_pair(vit->id(), eit->target())); + } + } + + std::sort(edges.begin(), edges.end()); + std::sort(actual_edges.begin(), actual_edges.end()); + + bool match = true; + if (edges.size() != actual_edges.size()) { + match = false; + } else { + auto mismatch = std::mismatch(edges.begin(), edges.end(), actual_edges.begin()); + if (mismatch.first != edges.end()) { + match = false; + } + } + + if (match) { cout << "OK\n"; } + else { cout << "FAIL\n"; } + } //==============================================================//