-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathgraphlet_utils.cpp
executable file
·160 lines (143 loc) · 4.5 KB
/
graphlet_utils.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
============================================================================
Name : Parallel Parameterized Graphlet Decomposition (PGD) Library
Author : Nesreen K. Ahmed, ([email protected]),
Ryan A. Rossi ([email protected])
Description : A general high-performance parallel framework for computing
the graphlet decomposition. The library is designed to be fast
for both large sparse graphs as well as dense graphs.
Copyright (C) 2012-2015,
Nesreen K. Ahmed (http://nesreenahmed.com), All rights reserved.
Please cite the following paper:
Nesreen K. Ahmed, Jennifer Neville, Ryan A. Rossi, Nick Duffield,
Efficient Graphlet Counting for Large Networks, IEEE International
Conference on Data Mining (ICDM), pages 10, 2015.
Download PDF: http://www.nesreenahmed.com/publications/ahmed-et-al-icdm2015.pdf
@inproceedings{ahmed2015icdm,
title={Efficient Graphlet Counting for Large Networks},
author={Nesreen K. Ahmed and Jennifer Neville and Ryan A. Rossi and Nick Duffield},
booktitle={ICDM},
pages={1--10},
year={2015}
}
See http://nesreenahmed.com/graphlets for more information.
============================================================================
*/
#include "graphlet_utils.h"
using namespace std;
bool fexists(const char *filename) {
ifstream ifile(filename);
#ifdef WIN32
return ifile!=0;
#else
return ifile;
#endif
}
#if defined(_WIN32) || defined(_WIN64)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
double get_time() {
LARGE_INTEGER t, freq;
QueryPerformanceCounter(&t);
QueryPerformanceFrequency(&freq);
return double(t.QuadPart)/double(freq.QuadPart);
}
#else
#include <sys/types.h>
#include <sys/timeb.h>
#include <sys/time.h>
double get_time() {
struct timeval t;
gettimeofday(&t, 0);
return (t.tv_sec*1.0 + t.tv_usec/1000000.0);
}
#endif
double tic() { return get_time(); }
void toc(double & start) {
start = get_time() - start;
}
string memory_usage() {
ostringstream mem;
ifstream proc("/proc/self/status");
string s;
while(getline(proc, s), !proc.fail()) {
if(s.substr(0, 6) == "VmSize") {
mem << s;
return mem.str();
}
}
return mem.str();
}
void indent(int level = 0, string str = "") {
for (int i = 0; i < level; i++) cout << " ";
cout << "(" << level << ") ";
}
void validate(bool condition, const string& msg) {
if (!condition) {
cerr << msg << endl;
assert(condition);
}
}
int getdir (string dir, vector<string> &files) {
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL) {
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL) {
if (dirp->d_name != ".")
files.push_back(string(dirp->d_name));
}
closedir(dp);
return 0;
}
void print_line(int n, string sym) {
for (int i = 0; i < n; ++i) cout << sym;
cout <<endl;
}
template<typename T>
void write_vector(std::vector<T> &data, string suffix, string fn) {
string::size_type result;
string::size_type beg;
string name = "stats/";
string rawname, fn_str;
int last_index = fn.find_last_of(".");
if (last_index != string::npos) {
rawname = fn.substr(0, last_index);
int beg_index = rawname.find_last_of("/");
string fn_new = rawname.substr(beg_index,rawname.size()-1);
fn_str = string("stats") + fn_new + suffix;
}
ofstream myfile;
char *fileName = (char*)fn_str.c_str();
myfile.open (fileName);
int sum = 0;
for (long long e = 0; e < data.size(); e++) {
myfile << data[e] << "\n";
sum += data[e];
}
myfile.close();
}
template void write_vector(std::vector<long long> &data, string suffix, string fn);
template void write_vector(std::vector<int> &data, string suffix, string fn);
template void write_vector(std::vector<double> &data, string suffix, string fn);
string extract_filename(string fn, bool remove_ext) {
if (remove_ext) { fn = remove_file_extension(fn); }
int idx = 0;
idx = fn.find_last_of("/")+1;
return fn.substr(idx, idx - fn.size());
}
string remove_file_extension(string fn) {
return fn.substr(0,fn.size() - (fn.size()-fn.find_last_of(".")));
}
int sample_rand_dist(int num_vals, vector<double> & dist_tmp) {
double rand_num = get_cust_rand();
int i = 0;
for (i = 0; i < num_vals; i++) {
if (dist_tmp[i] > rand_num) { break; }
}
return i;
};