25 class MyFitness :
public IFitterTarget {
27 MyFitness() : IFitterTarget() {
41 Double_t EstimatorFunction( std::vector<Double_t> & factors ){
43 return (10.- factors.at(0) *factors.at(1) + factors.at(2));
50 class MyGA2nd :
public GeneticAlgorithm {
52 MyGA2nd( IFitterTarget& target, Int_t size, vector<Interval*>& ranges ) : GeneticAlgorithm(target,
78 void TMVAGAexample() {
80 std::cout <<
"Start Test TMVAGAexample" << std::endl
81 <<
"========================" << std::endl
82 <<
"\nEXAMPLE" << std::endl;
85 vector<Interval*> ranges;
86 ranges.push_back(
new Interval(0,15,30) );
87 ranges.push_back(
new Interval(0,13) );
88 ranges.push_back(
new Interval(0,5,3) );
90 for( std::vector<Interval*>::iterator it = ranges.begin(); it != ranges.end(); it++ ){
91 std::cout <<
" range: " << (*it)->GetMin() <<
" " << (*it)->GetMax() << std::endl;
94 IFitterTarget* myFitness =
new MyFitness();
102 MyGA2nd mg( *myFitness, 100, ranges );
106 #define CONVCRIT 0.0001
109 #define SCFACTOR 0.95
116 mg.CalculateFitness();
118 mg.GetGeneticPopulation().Print(0);
119 std::cout <<
"---" << std::endl;
122 mg.GetGeneticPopulation().TrimPopulation();
132 mg.SpreadControl( SCSTEPS, SCRATE, SCFACTOR );
134 }
while (!mg.HasConverged( CONVSTEPS, CONVCRIT ));
136 GeneticGenes* genes = mg.GetGeneticPopulation().GetGenes( 0 );
137 std::vector<Double_t> gvec;
138 gvec = genes->GetFactors();
140 for( std::vector<Double_t>::iterator it = gvec.begin(); it<gvec.end(); it++ ){
141 std::cout <<
"FACTOR " << n <<
" : " << (*it) << std::endl;
147 int main(
int argc,
char** argv )