-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonteCarlosMethodSearching.cpp
More file actions
42 lines (33 loc) · 1.45 KB
/
MonteCarlosMethodSearching.cpp
File metadata and controls
42 lines (33 loc) · 1.45 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
#include "stdafx.h"
#include "MonteCarlosMethodSearching.h"
MethodSearching::MonteCarlosMethodSearching::MonteCarlosMethodSearching(ByteVector vectors[], funcvalue values[], int size, int NSteps, int randomseed) :AbstractMethodSearching(vectors, values, size), NSteps(NSteps)
{
this->randomseed = randomseed;
srand(randomseed);
}
MethodSearching::MonteCarlosMethodSearching::MonteCarlosMethodSearching(const vector<ByteVector>& vectors, const vector<funcvalue>& values, int NSteps, int randomseed) :AbstractMethodSearching(vectors, values), NSteps(NSteps)
{
this->randomseed = randomseed;
srand(randomseed);
}
ByteVector MethodSearching::MonteCarlosMethodSearching::find() {
int i = 0;
ByteVector Si = getReorderedNums()->at(i);
ByteVector Sstar = Si;
funcvalue max = elements->at(Sstar);
clog << "S*:" << Sstar << ", max:" << max << endl;
for (i = 1; i < getReorderedNums()->size() && i<NSteps; i++)
{
clog << "iter" << i << endl;
Si = getReorderedNums()->at(i);
funcvalue Mu = elements->at(Si);
//clog << *Si << " " << elements->at(Si)<<endl;
if (Mu > max) { max = Mu;Sstar = Si;clog << "S* changed "; }
clog << "Si:" << Si << ", f(Si):" << elements->at(Si) << ", S*:" << Sstar << ", f(S*):" << max << endl;
}
//clog <<endl<<"value:"<<*Sstar<<" answer:"<< elements->at(Sstar);
clog << "answer:" << Sstar << " value:" << elements->at(Sstar) << endl;
return Sstar;
}
MethodSearching::MonteCarlosMethodSearching::~MonteCarlosMethodSearching() {
}