-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnsambleSearchMethod.cpp
More file actions
87 lines (81 loc) · 3.19 KB
/
AnsambleSearchMethod.cpp
File metadata and controls
87 lines (81 loc) · 3.19 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
86
87
#include "stdafx.h"
#include "AnsambleSearchMethod.h"
ByteVector AnsambleSearchMethod::find() {
int i = 0;
clog << "Ensemble Iteration:" << i + 1 << endl;
clog << "/---------------------------------------------\\" << endl;
k = rand() % 3;
switch (k)
{
case 0:
clog << "Monte Carlo's" << endl;;
break;
case 2:
clog << "In Depth" << endl;;
break;
case 1:
clog << "In Width" << endl;
break;
default:
break;
}
ByteVector bestAnswer = methods[k]->find();
funcvalue max = elements->at(bestAnswer);
clog << "\\---------------------------------------------/" << endl;
clog << "Best max value" << bestAnswer << ":" << max << endl;
for (i = 1; i < NSteps; i++)
{
clog << "Ensemble Iteration:" << i + 1 << endl;
clog << "/---------------------------------------------\\" << endl;
k = rand() % 3;
switch (k)
{
case 0:
clog << "Monte Carlo's" << endl;;
break;
case 2:
clog << "In Depth" << endl;;
break;
case 1:
clog << "In Width" << endl;
break;
default:
break;
}
methods[k]->addReorderedNums();
ByteVector tempAnswer = methods[k]->find();
clog << "\\---------------------------------------------/" << endl;
float tempFuncValue = elements->at(tempAnswer);
clog << "Finded value:" << tempAnswer << ":" << tempFuncValue << endl;
if (tempFuncValue > max) { bestAnswer = tempAnswer;max = tempFuncValue; }
clog << "Best max value" << bestAnswer << ":" << max << endl;
}
clog << endl << "Best finded value" << bestAnswer << ":" << max << endl;;
return bestAnswer;
}
AnsambleSearchMethod::AnsambleSearchMethod(ByteVector vectors[], funcvalue values[], int size, int NSteps, int inMethodNSteps, int randomseed) :AbstractMethodSearching(vectors, values, size), NSteps(NSteps), inMethodNSteps(inMethodNSteps)
{
k = 0;
this->randomseed = randomseed;
srand(randomseed);
methods = vector<AbstractMethodSearching*>();
methods.push_back(new MonteCarlosMethodSearching(vectors, values, size, inMethodNSteps, randomseed));
methods.push_back(new SearchInWidthMethod(vectors, values, size, inMethodNSteps, randomseed));
methods.push_back(new DepthSearchMethod(vectors, values, size, inMethodNSteps, randomseed));
/*methods = { MonteCarlosMethodSearching(vectors,values,size,inMethodNSteps,randomseed),
SearchInWidthMethod(vectors,values,size,inMethodNSteps,randomseed),
DepthSearchMethod(vectors,values,size,inMethodNSteps,randomseed) };*/
}
AnsambleSearchMethod::AnsambleSearchMethod(const vector<ByteVector>& vectors, const vector<funcvalue>& values, int NSteps, int inMethodNSteps, int randomseed) :AbstractMethodSearching(vectors, values), NSteps(NSteps), inMethodNSteps(inMethodNSteps)
{
k = 0;
this->randomseed = randomseed;
srand(randomseed);
methods = vector<AbstractMethodSearching*>();
methods.push_back(new MonteCarlosMethodSearching(vectors, values, inMethodNSteps, randomseed));
methods.push_back(new SearchInWidthMethod(vectors, values, inMethodNSteps, randomseed));
methods.push_back(new DepthSearchMethod(vectors, values, inMethodNSteps, randomseed));
/*methods = { MonteCarlosMethodSearching(vectors,values,inMethodNSteps,randomseed),
SearchInWidthMethod(vectors,values,inMethodNSteps,randomseed),
DepthSearchMethod(vectors,values,inMethodNSteps,randomseed) };*/
}