-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonteCarloSampling.cpp
More file actions
27 lines (23 loc) · 1.01 KB
/
MonteCarloSampling.cpp
File metadata and controls
27 lines (23 loc) · 1.01 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
#include "MonteCarloSampling.h"
#include "BruteForce.h"
void MonteCarloSampling(Model &model) {
ComputePriority(model);
double ans = 0;
for (int i = 0; i < model.monte_carlo_iteration; i++) {
if (i % 1 == 0) cout << "iteration: " << i << "/" << model.monte_carlo_iteration << endl;
model.sampling_neighbor.clear();
model.sampling_neighbor.resize(model.neighbor.size(), vector<Edge>{});
for (auto &u: model.node_l) {
for (auto edge: model.neighbor[u]) {
if (rand() % 100 <= edge.pr * 100) {
model.sampling_neighbor[edge.u].push_back(Edge{edge.u, edge.v, edge.weight, edge.pr});
model.sampling_neighbor[edge.v].push_back(Edge{edge.v, edge.u, edge.weight, edge.pr});
}
}
}
MaximumButterfly(model, 1);
}
cout << "total " << ans << "**" << endl;
model.fout << "total " << ans << "*" << endl;
model.PrintResult(model.monte_carlo_iteration);
}