-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathestimate_mit.cpp
More file actions
138 lines (114 loc) · 2.47 KB
/
Copy pathestimate_mit.cpp
File metadata and controls
138 lines (114 loc) · 2.47 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
#include "option.h"
#include "hypergraph.hpp"
#include "graph.h"
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <random>
#include <chrono>
#include <omp.h>
using namespace std;
void readSeeds(Graph &g, int k, const char* seedFile, vector<int> &seeds) {
ifstream in(seedFile);
int i, v;
i = 0;
while (i < k) {
in >> v;
if ( !g.isFakeSeed(v) ) {
seeds.push_back(v);
}
i++;
}
in.close();
}
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*)"results.txt";
}
char * fakeSeedsFile = op.getPara("-fakeseeds");
if (fakeSeedsFile == NULL){
fakeSeedsFile = (char*)"fake.seeds";
}
int aw = 30;
char * tmp = op.getPara("-aw");
if (tmp != NULL){
aw = atoi(tmp);
}
float rp = 0.6;
tmp = op.getPara("-rp");
if (tmp != NULL){
aw = atof(tmp);
}
int ml = 6;
tmp = op.getPara("-ml");
if (tmp != NULL){
ml = atoi(tmp);
}
int br = 200;
tmp = op.getPara("-br");
if (tmp != NULL){
br = atoi(tmp);
}
bool ego = false;
tmp = op.getPara("-ego");
if (tmp != NULL){
ego = atoi(tmp);
}
float ew = -1.0;
tmp = op.getPara("-ew");
if (tmp != NULL){
ew = atof(tmp);
}
bool fixed = (ew < 0.0) ? false : true;
Graph g(aw, ml, rp, br, ego);
g.readGraph(inFile, fixed, ew);
g.readFakeSeeds(fakeSeedsFile);
int n = g.getNumNodes();
int k = 1;
tmp = op.getPara("-k");
if (tmp != NULL){
k = atoi(tmp);
}
char * seedFile = op.getPara("-s");
if (seedFile == NULL){
seedFile = (char*)"input.seeds";
}
vector<int> seeds;
readSeeds(g, k, seedFile, seeds);
double start = omp_get_wtime();
unsigned int i;
cout << "seed set: ";
for (i = 0; i < seeds.size(); i++) {
cout << seeds[i] << " ";
}
cout << endl;
ff reward_data;
double mit = estimateMitigation(g, n, seeds, reward_data);
cout << "mitigation is " << mit << endl;
cout << "reward breakdown: " << reward_data.first << " " << reward_data.second << endl;
ofstream out(outFile, ios::app);
out << "\nmit: " << mit << endl;
out << "reward breakdown " << reward_data.first << " " << reward_data.second << endl;
out.close();
//
// ALL DONE
//
}