forked from lannn2410/streamingksubmodular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Greedy.cpp
41 lines (37 loc) · 827 Bytes
/
Greedy.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
#include "Greedy.h"
Greedy::Greedy(Network * g) : Framework(g)
{
}
Greedy::~Greedy()
{
}
double Greedy::get_solution(bool is_ds)
{
vector<pair<uint, uint>> seeds;
int no_nodes = g->get_no_nodes();
vector<bool> selected(no_nodes, false);
for (int j = 0; j < Constants::BUDGET; ++j) {
double max = 0;
int e = 0, i = 0, u = 0;
for (u = 0; u < no_nodes; ++u) {
if (!selected[u]) {
for (int ii = 0; ii < Constants::K; ++ii) {
vector<pair<uint, uint>> seeds_tmp = seeds;
seeds_tmp.push_back(pair<uint, uint>(u, ii));
double est_F = estimate_influence(seeds_tmp);
if (max < est_F) {
max = est_F;
e = u;
i = ii;
}
}
}
}
if (max > 0) {
seeds.push_back(pair<uint, uint>(e, i));
selected[e] = true;
}
else break;
}
return estimate_influence(seeds);
}