-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (37 loc) · 814 Bytes
/
main.cpp
File metadata and controls
40 lines (37 loc) · 814 Bytes
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
#include "Percolation.h"
#include <iostream>
#include <random>
#include <functional>
#include <ctime>
using namespace std;
int main() {
int n = 200;
int trails = 100;
Percolation p0(n);
std::default_random_engine generator(time(0));
std::uniform_int_distribution<int> distribution(1, n);
auto randpos = std::bind(distribution, generator);
bool isper = false;
vector<double> xi(trails, 0);
for (int k = 0;k < trails;++k) {
isper = false;
while (!isper)
{
int i = randpos(), j = randpos();
p0.open(i, j);
isper = p0.percolates();
//cout << p0.site_cnt<< endl;
}
xi[k] = (double)(p0.site_cnt) / (n*n);
p0.clear();
cout << k << endl;
}
double thre=0;
for (int k = 0;k < trails;++k) {
thre += xi[k];
}
thre /= trails;
cout << thre << endl;
system("pause");
return 0;
}