-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.cpp
47 lines (44 loc) · 1.47 KB
/
execute.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
//
// execute.cpp
// search
//
// Created by WU,MENG-TING on 2020/7/1.
// Copyright © 2020 WU,MENG-TING. All rights reserved.
//
#include "execute.hpp"
void execute(const int Algo,const int runs,const int iterations,const int bits,const string filename,const double temperature, const double alpha){
ofstream fout,file;
fout.open("RESULT.txt");
file.open("data.txt");
vector<double> avg(iterations/block);
if (filename==""){
for (int i=0;i<runs;i++){
fout<<"----------------------------------------"<<endl;
fout<<"run: "<<i+1<<endl;
time_t start=0, end=0;
if (Algo==1){
SA *r = new SA(bits,iterations,temperature,alpha);
start = time(NULL);
r->run();
for (int j=0;j<=iterations/block;j++){
avg[j] += r->get_record_value(j*block);
}
fout<<"Best: "<<r->get_record_value(iterations-1)<<endl;
end = time(NULL);
}
double diff = difftime(end, start);
fout<<"Run time: "<<diff<<"s"<<endl;
}
fout<<"----------------------------------------"<<endl;
for (int i=0;i<avg.size();i++){
avg[i] /= runs;
fout<<"Iter "<<i*block<<" : "<<avg[i]<<endl;
file<<i*block<<" "<<avg[i]<<endl;
}
}
else{
cout<<"random number file"<<endl;
//left blank
//complete when needed
}
}