-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.cpp
110 lines (101 loc) · 3.05 KB
/
demo.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
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
103
104
105
106
107
108
109
110
#include"demo.h"
bool demo::rundemo(int simtype, int par_nsimiter) {
//system("mkdir -p ./CACHEFE_res");
// get parameters ready
double par_t_C = (simtype==SAFAIL_? 1019.6867251526046:1.0);
int par_nCend = 8, par_randseed = 7;
double *par_u01 = new double[2], *par_sig01 = new double[2];
par_u01[0] = 0; par_u01[1] = INFINITY;
par_sig01[0] = 2.451733398437500e-05; par_sig01[1] = 2.451733398437500e-05;
// initialzation
SUS SUS_instance(par_nCend, par_u01, par_sig01, par_t_C, par_randseed, par_nsimiter);
// let's do simulation !
vector<vector<double> >XSeed, Yseed, XsaSeed, ylimSeed;
SUS_instance.sus_delta_sim(XSeed, Yseed, XsaSeed, ylimSeed, simtype);
vector<int>cells = { 1,2,3,4,5,6,7,8,10,13,16,32,48,64 };
// get results
double prob = 1;
vector<double>probAnd(SUS_instance.nCend);
vector<vector<double> >Fp(par_nCend, vector<double>(cells.size()));
for (int j = 1; j <= par_nCend; j++) {
prob *= SUS_instance.APA_probEstList[j - 1];
//cout<<SUS_instance.APA_probEstList[j-1]<<endl;
probAnd[j - 1] = prob;
// APA result
for (int m = 0; m < cells.size(); m++) {
Fp[j - 1][m] = (cells[m] - j + 1)*pow(-1, j - 1)*probAnd[j - 1];
}
for (int k = 1; k <= j - 1; k++) {
for (int m = 0; m < Fp[0].size(); m++) {
Fp[j - 1][m] = Fp[j - 1][m] + pow(-1, k - 1)*probAnd[k - 1] * (helperfunc::combntns(j, k) + (cells[m] - j)*helperfunc::combntns(j - 1, k - 1));
}
}
}
string cur;
switch (simtype) {
case READFAIL_:
cur = "read";
break;
case WRITEFAIL_:
cur = "write";
break;
case SAFAIL_:
cur = "sa";
break;
default:
cout << "[Error]:wrong simulatinon type for CACHFE\n";
exit(1);
}
string wrk_pre = "./CACHEFE_res/APAdemo_";
string wrk_pos = "fail__res.txt";
wrk_pre.append(cur);
wrk_pre.append(wrk_pos);
const char* file = wrk_pre.c_str();
helperfunc::write_to_txt(Fp, file);
delete[]par_u01;
delete[]par_sig01;
return 1;
}
bool demo::MCdemo(int simtype) {
//system("mkdir -p ./CACHEFE_res");
// get parameters ready
double par_t_C = 1019.6867251526046;
int par_nCend = 8, par_randseed = 7;
double *par_u01 = new double[2], *par_sig01 = new double[2]; int par_nsimiter = 1000;
par_u01[0] = 0; par_u01[1] = INFINITY;
par_sig01[0] = 2.451733398437500e-05; par_sig01[1] = 2.451733398437500e-05;
// initialzation
SUS SUS_instance(par_nCend, par_u01, par_sig01, par_t_C, par_randseed, par_nsimiter);
// let's do simulation !
vector<int>cells = { 1,2,3,4,5,6,7,8,10,13,16,32,48,64 };
std::vector<double> dst(cells.size());
SUS_instance.MC(cells, dst, simtype, 100);
string cur;
switch (simtype) {
case READFAIL_:
cur = "read";
break;
case WRITEFAIL_:
cur = "write";
break;
case SAFAIL_:
cur = "sa";
break;
default:
cout << "[Error]:wrong simulatinon type for CACHFE\n";
exit(1);
}
string wrk_pre = "./CACHEFE_res/APAdemo_";
string wrk_pos = "fail__MC_res.txt";
wrk_pre.append(cur);
wrk_pre.append(wrk_pos);
const char* file = wrk_pre.c_str();
helperfunc::write_to_txt(dst, file);
delete[]par_u01;
delete[]par_sig01;
return 1;
}
bool demo::cleardemo() {
//system("rm -r ./CACHEFE");
return 1;
}