forked from SNUCSE-CTA/graph-analysis-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeplot.cpp
120 lines (86 loc) · 3.54 KB
/
makeplot.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "makeplot.h"
#include <fstream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
namespace snu {
void makePlot(DSGraph& graph, Plot& plot)
{
std::ofstream out;
// label-vertex
out.open("./pyplot/label-vertex.txt");
unsigned int n = graph.id_to_vertex.size();
typedef std::pair<std::string*, unsigned int> label_vertex;
std::vector<label_vertex> lv;
lv.reserve(n);
for (auto it = graph.vlabel_to_class.begin(); it != graph.vlabel_to_class.end(); ++it) {
auto vlabel = it->second;
lv.push_back(make_pair(&(vlabel->label), vlabel->vertices.size()));
}
std::sort(lv.begin(), lv.end(), [](label_vertex a, label_vertex b) { return a.second > b.second; });
for (auto it = lv.begin(); it != lv.end(); ++it)
out << *(it->first) << " " << it->second << std::endl;
out.close();
std::string cmd = "python label-vertex.py " + plot.name;
system(cmd.c_str());
// indegree
out.open("./pyplot/indegree.txt");
std::vector<unsigned int> degree;
degree.reserve(n);
for (auto it = graph.id_to_vertex.begin(); it != graph.id_to_vertex.end(); ++it)
degree.push_back((*it->second).indegree);
std::sort(degree.begin(), degree.end());
for (auto it = degree.begin(); it != degree.end(); ++it)
out << *it << " ";
out.close();
cmd = "python indegree.py " + plot.name;
system(cmd.c_str());
// outdegree
out.open("./pyplot/outdegree.txt");
degree.clear();
degree.reserve(n);
for (auto it = graph.id_to_vertex.begin(); it != graph.id_to_vertex.end(); ++it)
degree.push_back((*it->second).edges.size());
std::sort(degree.begin(), degree.end());
for (auto it = degree.begin(); it != degree.end(); ++it)
out << *it << " ";
out.close();
cmd = "python outdegree.py " + plot.name;
system(cmd.c_str());
plot.makeplot = true;
}
void makePlot(USGraph& graph, Plot& plot)
{
std::ofstream out;
// label-vertex
out.open("./pyplot/label-vertex.txt");
unsigned int n = graph.id_to_vertex.size();
typedef std::pair<std::string*, unsigned int> label_vertex;
std::vector<label_vertex> lv;
lv.reserve(n);
for (auto it = graph.vlabel_to_class.begin(); it != graph.vlabel_to_class.end(); ++it) {
auto vlabel = it->second;
lv.push_back(make_pair(&(vlabel->label), vlabel->vertices.size()));
}
std::sort(lv.begin(), lv.end(), [](label_vertex a, label_vertex b) { return a.second > b.second; });
for (auto it = lv.begin(); it != lv.end(); ++it)
out << *(it->first) << " " << it->second << std::endl;
out.close();
std::string cmd = "python label-vertex.py " + plot.name;
system(cmd.c_str());
// degree
out.open("./pyplot/degree.txt");
std::vector <unsigned int> degree;
degree.reserve(n);
for (auto it = graph.id_to_vertex.begin(); it != graph.id_to_vertex.end(); ++it)
degree.push_back((*it->second).indegree);
std::sort(degree.begin(), degree.end());
for (auto it = degree.begin(); it != degree.end(); ++it)
out << *it << " ";
out.close();
cmd = "python degree.py " + plot.name;
system(cmd.c_str());
// pyplot
plot.makeplot = true;
}
}