forked from gmgu/graph-analysis-tool
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathstatanalyzer.cpp
More file actions
98 lines (80 loc) · 2.86 KB
/
Copy pathstatanalyzer.cpp
File metadata and controls
98 lines (80 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "statanalyzer.h"
#include <getopt.h>
#include <stdio.h>
#include <chrono>
#include "parse.h"
using namespace std::chrono;
namespace snu {
template <typename T>
static void printElapsedTime(const char *msg, T &t) {
printf("%10ldms: %s\n", (duration_cast<milliseconds>(high_resolution_clock::now() - t)).count(), msg);
t = high_resolution_clock::now();
}
StatAnalyzer::StatAnalyzer(std::string _graph_name,
std::shared_ptr<Graph> _graph_shptr,
bool _file_output,
bool _display_time,
bool _verify)
: graph_name(_graph_name), graph_shptr(_graph_shptr), file_output(_file_output), display_time(_display_time), verify(_verify) {
}
bool StatAnalyzer::run() {
std::vector<snu::Stat *> all_stats;
USGraph *usgraph_ptr = dynamic_cast<USGraph *>(graph_shptr.get());
DSGraph *dsgraph_ptr = dynamic_cast<DSGraph *>(graph_shptr.get());
bool directed = dsgraph_ptr != nullptr;
auto &graph = *graph_shptr.get();
for (auto p : common_stats)
all_stats.push_back(p);
if (directed) {
for (auto p : directed_only_stats)
all_stats.push_back(p);
} else {
for (auto p : undirected_only_stats)
all_stats.push_back(p);
}
auto t = high_resolution_clock::now();
// calculate common stats
for (auto commonStat : common_stats) {
if (!commonStat->calculate(graph, verify)) {
printf("%s failed\n", commonStat->statName().c_str());
}
printElapsedTime(commonStat->statName().c_str(), t);
}
// calculate directed stats
if (directed) {
for (auto dirStat : directed_only_stats) {
if (!dirStat->calculateDirected(*dsgraph_ptr, verify)) {
printf("%s failed\n", dirStat->statName().c_str());
}
printElapsedTime(dirStat->statName().c_str(), t);
}
}
// calculate undirected stats
else {
for (auto undirStat : undirected_only_stats) {
if (!undirStat->calculateUndirected(*usgraph_ptr, verify)) {
printf("%s failed\n", undirStat->statName().c_str());
}
printElapsedTime(undirStat->statName().c_str(), t);
}
}
// file output
if (file_output) {
for (auto stat : all_stats) {
if (stat->getSuccess() && stat->writeToFile(graph_name, directed)) {
printElapsedTime(("Writing to file: " + stat->statName()).c_str(), t);
}
}
}
return true;
}
void StatAnalyzer::addCommonStats(std::vector<CommonStat *> vec) {
common_stats = vec;
}
void StatAnalyzer::addDirectedStats(std::vector<DirectedStat *> vec) {
directed_only_stats = vec;
}
void StatAnalyzer::addUndirectedStats(std::vector<UndirectedStat *> vec) {
undirected_only_stats = vec;
}
} // namespace snu