-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwo_Level_FST.cpp
More file actions
86 lines (61 loc) · 1.29 KB
/
Two_Level_FST.cpp
File metadata and controls
86 lines (61 loc) · 1.29 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
//Vamos a modificar el metodo para modelar tiempo medio de primer paso de la probabilidad de T 0->0
#include<cstdlib>
#include<fstream> //Libreria para grabar cosas en archivos
#include<iostream>
// En la terminal podemos correr ls *.dat > names.txt para hace una lista de archivos
using namespace std;
int Coin(double p){
double val = 1.0*rand()/RAND_MAX;
int out;
if (val<=p){
out = 0;
}
else{
out = 1;
}
return out;
}
int Transition(int state, double p, double q){
if (state == 0){
state = Coin(1-p);
}
else{
state = Coin(q);
}
return state;
}
int FPT(int initial, int target, double p, double q){
int state = initial;
int time = 0;
if (state == target){
state = Transition(state,p,q);
time += 1;
while(state != target){
state = Transition(state,p,q);
time += 1;
}
}
else{
while(state != target){
state = Transition(state,p,q);
time += 1;
}
}
return time;
}
int main(){
//En la semilla, ponemos el tiempo para generar numeros aleatorios.
srand(time(NULL));
double p = 0.01;
string namef;
while(p<=0.8){
namef = "Pass T/FPT_p" + to_string(p).substr(0,4) + ".dat";
ofstream FPT_data (namef);
for(int i = 0; i<10000; i++){
FPT_data<<FPT(0,1,p,0.1)<<endl;
}
FPT_data.close();
p += 0.01;
}
return 0;
}