-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
147 lines (126 loc) · 4.79 KB
/
Copy pathmain.cpp
File metadata and controls
147 lines (126 loc) · 4.79 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "read_hypergraph.h"
#include "degeneracy.h"
#include "types.h"
#include "HypergraphCSR.h"
#include "count_patterns.h"
#include <ctime>
#include <tuple>
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <hypergraph_file> <c(losed)/a(ll)/s(tatistics)/st(ars)> <output_file (only for s and st, do not include .csv)>\n";
return 1;
}
//Mode selector c for only patterns 1-20, a computes also patterns 21-26, s only output statistics
std::string mode = argv[2];
if (mode != "c" && mode != "a" && mode != "s" && mode != "st") {
std::cerr << "Usage: " << argv[0] << " <hypergraph_file> <c(losed)/a(ll)/s(tatistics)/st(ars)> <output_file (only for s and st, do not include .csv)>\n";
return 1;
}
if ((mode == "s" || mode == "st") && argc < 4) {
std::cerr << "Usage: " << argv[0] << " <hypergraph_file> <c(losed)/a(ll)/s(tatistics)/st(ars)> <output_file (only for s and st, do not include .csv)>\n";
return 1;
}
std::string filename = argv[1];
clock_t start;
clock_t stop;
clock_t prev;
// Read hypergraph
start = clock();
HypergraphCSR H;
DirHypergraphCSR dirH;
EdgeId* star_counts;
int rank = read_hypergraph(H, filename);
if (rank == -1) return 0;
std::cout << "Number of vertices: " << H.num_vertices << "\n";
std::cout << "Number of hyperedges: " << H.num_hyperedges << "\n";
stop = clock();
std::cout << "Read hypergraph and created adjacency lists (s): "
<< (double)(stop - start) / CLOCKS_PER_SEC << std::endl;
//Compute the degeneracy ordering
VertexId* ordering = new VertexId[H.num_vertices]();
compute_degeneracy_ordering(dirH, H, ordering);
prev = stop;
stop = clock();
std::cout << "Computed degeneracy ordering (s): " << (double)(stop - prev) / CLOCKS_PER_SEC << std::endl;
EdgeId* counts = new EdgeId[26]();
//Compute statistics for the hypergraph
if(mode == "s"){
std::string output = argv[3];
H.compute_degrees(output+"_degrees.csv");
dirH.compute_outdegrees(output+"_outdegrees.csv");
dirH.compute_outdegree_times_degree();
} else {
//Compute the hyperedge degrees
dirH.compute_edge_degrees();
prev = stop;
stop = clock();
std::cout << "Computed edge_degrees (s): " << (double)(stop - prev) / CLOCKS_PER_SEC << std::endl;
//Compute the triangle based patterns
count_triangle_based_patterns(dirH,counts);
prev = stop;
stop = clock();
std::cout << "Computed triangle based patterns (s): " << (double)(stop - prev) / CLOCKS_PER_SEC << std::endl;
//Compute closed contained patterns
count_closed_contained_patterns(dirH,counts);
prev = stop;
stop = clock();
std::cout << "Computed closed contained patterns (s): " << (double)(stop - prev) / CLOCKS_PER_SEC << std::endl;
//Compute the number of stars and extended stars
bool stars_mode = false;
if(mode == "st"){
stars_mode = true;
star_counts = new EdgeId[rank+1]();
}
std::tuple<EdgeId, EdgeId> stars = count_stars(dirH, stars_mode, star_counts);
//Compute the counts of patterns 9 and 10
compute_final_counts(stars, counts);
prev = stop;
stop = clock();
std::cout << "Computed stars and extended stars (s): " << (double)(stop - prev) / CLOCKS_PER_SEC << std::endl;
if(mode == "a") {
//Compute open patterns
compute_open_patterns(dirH, counts);
prev = stop;
stop = clock();
std::cout << "Computed open patterns (s): " << (double)(stop - prev) / CLOCKS_PER_SEC << std::endl;
}
//Print the counts
std::cout <<"Counts: \n";
if(mode == "c" || mode == "st"){
for (int i = 1; i <= 20; i++){
std::cout << i<<"\t" << counts[i-1]<< "\n";
}
} else if (mode == "a"){
for (int i = 1; i <= 26; i++){
std::cout << i<<"\t" << counts[i-1]<< "\n";
}
}
//Output the stars file
if (mode == "st"){
std::string output = argv[3];
std::string output_file = (output+"_stars.csv");
EdgeId total_stars = 0;
for (int i = 2; i <= rank; i++){
total_stars += star_counts[i];
}
star_counts[1] = counts[8] - total_stars;
std::ofstream csv(output_file);
if (csv.is_open()) {
csv << "Size, Quantity\n";
for (int i = 1; i <= rank; ++i) {
csv << i << "," << star_counts[i] << "\n";
}
}
csv.close();
}
}
stop = clock();
std::cout << "\n" << "Time (s):\t" << (double)(stop - start) / CLOCKS_PER_SEC << std::endl;
delete[] ordering;
delete[] counts;
return 0;
}