-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleSearchMain.cpp
45 lines (34 loc) · 1.06 KB
/
SimpleSearchMain.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
// ***************************************************
// A very simple example program for the TSearch class
// ***************************************************
#include "TSearch.h"
// A simple 2D inverted quadratic evaluation function
double Evaluate(TVector<double> &v, RandomState &)
{
double p1 = MapSearchParameter(v[1],-10,10),
p2 = MapSearchParameter(v[2],-10,10);
return 200-(p1*p1+p2*p2);
}
// The main program
int main (int argc, const char* argv[]) {
TSearch s(2);
// Configure the search
s.SetRandomSeed(87632455);
s.SetEvaluationFunction(Evaluate);
s.SetSelectionMode(RANK_BASED);
s.SetReproductionMode(HILL_CLIMBING);
s.SetPopulationSize(1000);
s.SetMaxGenerations(250);
s.SetMutationVariance(0.1);
s.SetCrossoverProbability(0.5);
s.SetCrossoverMode(TWO_POINT);
s.SetMaxExpectedOffspring(1.1);
s.SetElitistFraction(0.1);
s.SetSearchConstraint(1);
s.SetCheckpointInterval(5);
// Run the search
s.ExecuteSearch();
// Display the best individual found
cout << s.BestIndividual() << endl;
return 0;
}