-
Notifications
You must be signed in to change notification settings - Fork 0
/
greedyIC.cc
102 lines (81 loc) · 2.57 KB
/
greedyIC.cc
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
#include "metaheuristicIC.hh"
#include <string.h>
#define INPUT_PATH "./input-graphs/"
using namespace std;
int main(int argc, char * argv[]){
// MODE 1: Read graph manually
if(argc == 1){
// graph order
int n, m; double pr;
cout << "Number of nodes: " ;
cin >> n;
cout << "Number of edges: " ;
cin >> m;
// spreading probability | propagating ratio
cout << "Introduce Spreading probability: ";
cin >> pr; cout << endl;
if(pr > 1 || pr < 0){
cerr << "Invalid probability" << endl;
return -1;
}
// build graph
greedyIC g = greedyIC(n,pr);
cout << "Introduce edges in the folllowing format : i j " << endl;
g.readEdges(m);
// begin difusion
g.beginDifusion_IC_v2();
}
// MODE 2: graph input from file
else if (argc == 2){
// build graph
string filename = argv[1];
greedyIC g = greedyIC();
double pr;
// spreading probability | propagating ratio
cout << "Introduce Spreading probability: ";
cin >> pr; cout << endl;
if(pr > 1 || pr < 0){
cerr << "Invalid probability" << endl;
return -1;
}
// read graph edges
g.readEdgesFromFile2(pr, INPUT_PATH + filename);
// begin difusion
g.beginDifusion_IC_v2();
}
// MODE 3: Test Graph propagation
else if(argc == 3 && strcmp(argv[2], "test") == 0){
// build graph
string filename = argv[1];
greedyIC g = greedyIC();
double pr;
// spreading probability | propagating ratio
cout << "Introduce Spreading probability: ";
cin >> pr; cout << endl;
if(pr > 1 || pr < 0){
cerr << "Invalid probability" << endl;
return -1;
}
// read graph edges
g.readEdgesFromFile2(pr, INPUT_PATH + filename);
// read subset of nodes to propagate
list<int> l;
int x;
int c = 0;
while(cin >> x && x != -1){
l.push_back(x);
++c;
}
// begin difusion
cout << g.testDifusionIC(l)<<endl;
}
else{
cerr << "Invalid arguments." << endl;
cerr << "USAGE:" << endl;
cerr << " manual input: $ ./program_Greedy " << endl;
cerr << " input from file: $ ./program_Greedy graph_NAME " << endl;
cerr << " test propagation: $ ./program_Greedy graph_NAME test " << endl;
return -1;
}
return 0;
}