-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsingleton_inf.cpp
135 lines (115 loc) · 2.99 KB
/
singleton_inf.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
#include "option.h"
#include "graph.h"
#include <algorithm>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <random>
#include <omp.h>
using namespace std;
typedef pair<float,int> fi;
typedef vector<fi> vfi;
// estimate influence of singleton seeds using 10K monte carlo simulations
void estimateInfluence(Graph &g, int n, int r, vfi &inf) {
omp_set_num_threads(16);
#pragma omp parallel
{
long long int running_total;
float influence;
int cnt = 0;
#pragma omp for
for (int i = 0; i < n; i++) {
// vector<bool> visit(n,false);
// vector<int> visit_index(n,0);
// vector<double> threshold(n,2.0);
// vector<int> dist(n,100000);
running_total = 0;
for (int j = 0; j < r; j++) {
vector<bool> visit(n,false);
vector<int> visit_index(n,0);
vector<double> threshold(n,2.0);
vector<int> dist(n,100000);
auto res = g.generateInfluenceSample(visit, visit_index, threshold, dist, i);
// if(j == 0)
// cout << res << endl;
if(res < 100000000){
running_total += res * r;
break;
}
else{
running_total += res;
// cout << res << endl;
}
// cout << running_total << endl;
}
influence = (float)running_total / r;
// #pragma omp critical
// {
// cnt++;
// if( cnt % 100 == 0)
// cout << cnt << endl;
// }
inf[i] = fi(influence, i);
}
}
sort(inf.begin(), inf.end());
}
int main(int argc, char ** argv)
{
srand(time(NULL));
OptionParser op(argc, argv);
if (!op.validCheck()){
printf("Parameters error, please check the readme.txt file for correct format!\n");
return -1;
}
char * inFile = op.getPara("-i");
if (inFile == NULL){
inFile = (char*)"network";
}
char * outFile = op.getPara("-o");
if (outFile == NULL){
outFile = (char*)"singleton.inf";
}
float ew = -1.0;
char * tmp = op.getPara("-ew");
if (tmp != NULL){
ew = atof(tmp);
}
int t = 8;
tmp = op.getPara("-t");
if (tmp != NULL){
t = atoi(tmp);
}
int T = 32;
tmp = op.getPara("-T");
if (tmp != NULL){
T = atoi(tmp);
}
int r = 1000;
tmp = op.getPara("-r");
if (tmp != NULL){
r = atoi(tmp);
}
bool fixed = (ew < 0.0) ? false : true;
Graph g(t,T);
g.readGraph(inFile, fixed, ew);
g.init_visit_thresh_hold();
int n = g.getNumNodes();
vfi inf(n);
double start = omp_get_wtime();
estimateInfluence(g, n, r, inf);
cout << "Time to estimate singleton influences: " << (omp_get_wtime()-start) << "s" << endl;
ofstream of(outFile);
for (int i = n-1; i >= 0; i--){
of << inf[i].second << "\t" << inf[i].first << endl;
}
of.close();
//
// ALL DONE
//
}