adding evaluation in some places

This commit is contained in:
gustavoromero 2000-11-13 12:09:53 +00:00
commit 34be1fd174

View file

@ -41,13 +41,14 @@ void main_function()
unsigned i, j; unsigned i, j;
Chrom chrom(SIZE), chrom2; Chrom chrom(SIZE), chrom2;
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
cout << "chrom: " << chrom << endl; cout << "chrom: " << chrom << endl;
chrom[0] = chrom[SIZE - 1] = true; chrom[0] = chrom[SIZE - 1] = true; chrom.fitness(binary_value(chrom));
cout << "chrom: " << chrom << endl; cout << "chrom: " << chrom << endl;
chrom[0] = chrom[SIZE - 1] = false; chrom[0] = chrom[SIZE - 1] = false; chrom.fitness(binary_value(chrom));
cout << "chrom: " << chrom << endl; cout << "chrom: " << chrom << endl;
chrom[0] = chrom[SIZE - 1] = true; chrom[0] = chrom[SIZE - 1] = true; chrom.fitness(binary_value(chrom));
cout << "chrom.className() = " << chrom.className() << endl; cout << "chrom.className() = " << chrom.className() << endl;
@ -58,7 +59,7 @@ void main_function()
ostrstream os(buff, 1024); ostrstream os(buff, 1024);
os << chrom; os << chrom;
istrstream is(os.str()); istrstream is(os.str());
is >> chrom2; is >> chrom2; chrom.fitness(binary_value(chrom2));
cout << "\nTesting reading, writing\n"; cout << "\nTesting reading, writing\n";
cout << "chrom: " << chrom << "\nchrom2: " << chrom2 << '\n'; cout << "chrom: " << chrom << "\nchrom2: " << chrom2 << '\n';
@ -70,31 +71,31 @@ void main_function()
eoInitFixedLength<Chrom, boolean_generator> eoInitFixedLength<Chrom, boolean_generator>
random(chrom.size(), boolean_generator()); random(chrom.size(), boolean_generator());
random(chrom); random(chrom); chrom.fitness(binary_value(chrom));
cout << "after eoBinRandom ............ " << chrom << endl; cout << "after eoBinRandom ............ " << chrom << endl;
eoBinBitFlip<Chrom> bitflip; eoBinBitFlip<Chrom> bitflip;
bitflip(chrom); bitflip(chrom); chrom.fitness(binary_value(chrom));
cout << "after eoBitFlip .............. " << chrom << endl; cout << "after eoBitFlip .............. " << chrom << endl;
eoBinMutation<Chrom> mutation(0.5); eoBinMutation<Chrom> mutation(0.5);
mutation(chrom); mutation(chrom); chrom.fitness(binary_value(chrom));
cout << "after eoBinMutation(0.5) ..... " << chrom << endl; cout << "after eoBinMutation(0.5) ..... " << chrom << endl;
eoBinInversion<Chrom> inversion; eoBinInversion<Chrom> inversion;
inversion(chrom); inversion(chrom); chrom.fitness(binary_value(chrom));
cout << "after eoBinInversion ......... " << chrom << endl; cout << "after eoBinInversion ......... " << chrom << endl;
eoBinNext<Chrom> next; eoBinNext<Chrom> next;
next(chrom); next(chrom); chrom.fitness(binary_value(chrom));
cout << "after eoBinNext .............. " << chrom << endl; cout << "after eoBinNext .............. " << chrom << endl;
eoBinPrev<Chrom> prev; eoBinPrev<Chrom> prev;
prev(chrom); prev(chrom); chrom.fitness(binary_value(chrom));
cout << "after eoBinPrev .............. " << chrom << endl; cout << "after eoBinPrev .............. " << chrom << endl;
fill(chrom.begin(), chrom.end(), false); fill(chrom.begin(), chrom.end(), false); chrom.fitness(binary_value(chrom));
fill(chrom2.begin(), chrom2.end(), true); fill(chrom2.begin(), chrom2.end(), true); chrom2.fitness(binary_value(chrom2));
cout << "--------------------------------------------------" cout << "--------------------------------------------------"
<< endl << "eoBinOp's aplied to ... " << endl << "eoBinOp's aplied to ... "
<< chrom << " " << chrom2 << endl; << chrom << " " << chrom2 << endl;
@ -103,6 +104,7 @@ void main_function()
fill(chrom.begin(), chrom.end(), false); fill(chrom.begin(), chrom.end(), false);
fill(chrom2.begin(), chrom2.end(), true); fill(chrom2.begin(), chrom2.end(), true);
xover(chrom, chrom2); xover(chrom, chrom2);
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
cout << "eoBinCrossover ........ " << chrom << " " << chrom2 << endl; cout << "eoBinCrossover ........ " << chrom << " " << chrom2 << endl;
for (i = 1; i < SIZE; i++) for (i = 1; i < SIZE; i++)
@ -111,6 +113,7 @@ void main_function()
fill(chrom.begin(), chrom.end(), false); fill(chrom.begin(), chrom.end(), false);
fill(chrom2.begin(), chrom2.end(), true); fill(chrom2.begin(), chrom2.end(), true);
nxover(chrom, chrom2); nxover(chrom, chrom2);
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
cout << "eoBinNxOver(" << i << ") ........ " cout << "eoBinNxOver(" << i << ") ........ "
<< chrom << " " << chrom2 << endl; << chrom << " " << chrom2 << endl;
} }
@ -122,6 +125,7 @@ void main_function()
fill(chrom.begin(), chrom.end(), false); fill(chrom.begin(), chrom.end(), false);
fill(chrom2.begin(), chrom2.end(), true); fill(chrom2.begin(), chrom2.end(), true);
gxover(chrom, chrom2); gxover(chrom, chrom2);
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
cout << "eoBinGxOver(" << i << ", " << j << ") ..... " cout << "eoBinGxOver(" << i << ", " << j << ") ..... "
<< chrom << " " << chrom2 << endl; << chrom << " " << chrom2 << endl;
} }
@ -146,10 +150,9 @@ void main_function()
eoProportional<Chrom> select; eoProportional<Chrom> select;
eoEvalFuncPtr<Chrom> eval(binary_value); eoEvalFuncPtr<Chrom> eval(binary_value);
eoSGA<Chrom> sga(checkpoint, bitflip, 0.1f, xover, 0.8f, select, eval); eoSGA<Chrom> sga(select, xover, 0.8f, bitflip, 0.1f, eval, checkpoint);
eoInitFixedLength<Chrom, boolean_generator> eoInitFixedLength<Chrom, boolean_generator> init(16, boolean_generator());
init(16, boolean_generator());
eoPop<Chrom> pop(100, init); eoPop<Chrom> pop(100, init);
apply<Chrom>(eval, pop); apply<Chrom>(eval, pop);