Removed "using namespace std" statements from header files in EO -- "std::" identifier were added where necessary.
This commit is contained in:
parent
6441ea1ec3
commit
86fa476c67
263 changed files with 2009 additions and 1976 deletions
|
|
@ -290,7 +290,7 @@ void algo(eoPop<EOT>& _pop)
|
|||
eoPop<EOT> offspring; // how to get the scaling info into this guy??
|
||||
offspring.setPerf2Worth(_pop.getPerf2Worth()); // like this!
|
||||
|
||||
copy(_pop.begin(), _pop.end(), back_inserter(offspring));
|
||||
std::copy(_pop.begin(), _pop.end(), back_inserter(offspring));
|
||||
|
||||
offspring.sort(); // should call scale
|
||||
|
||||
|
|
@ -307,9 +307,9 @@ void minimization_test()
|
|||
eo1.performance(1.0);
|
||||
eo2.performance(2.0);
|
||||
|
||||
cout << "With minimizing fitness" << endl;
|
||||
cout << eo1.fitness() << " < " << eo2.fitness() << " returns " << (eo1 < eo2) << endl;
|
||||
cout << eo2.fitness() << " < " << eo1.fitness() << " returns " << (eo2 < eo1) << endl;
|
||||
std::cout << "With minimizing fitness" << std::endl;
|
||||
std::cout << eo1.fitness() << " < " << eo2.fitness() << " returns " << (eo1 < eo2) << std::endl;
|
||||
std::cout << eo2.fitness() << " < " << eo1.fitness() << " returns " << (eo2 < eo1) << std::endl;
|
||||
}
|
||||
|
||||
void the_main()
|
||||
|
|
@ -325,10 +325,10 @@ void the_main()
|
|||
eo1.fitness(10); // could also use performance()
|
||||
eo3.fitness(5);
|
||||
|
||||
cout << eo1.fitness() << endl;
|
||||
cout << eo3.fitness() << endl;
|
||||
std::cout << eo1.fitness() << std::endl;
|
||||
std::cout << eo3.fitness() << std::endl;
|
||||
|
||||
cout << "eo1 < eo3 = " << (eo1 < eo3) << endl;
|
||||
std::cout << "eo1 < eo3 = " << (eo1 < eo3) << std::endl;
|
||||
|
||||
|
||||
scaled_eo eo2;
|
||||
|
|
@ -340,14 +340,14 @@ void the_main()
|
|||
|
||||
try
|
||||
{
|
||||
cout << eo2.fitness() << endl;
|
||||
cout << "did not throw" << endl;
|
||||
std::cout << eo2.fitness() << std::endl;
|
||||
std::cout << "did not throw" << std::endl;
|
||||
assert(false); // should throw
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Fitness threw exception, as it should" << endl;
|
||||
cout << e.what() << endl;
|
||||
std::cout << "Fitness threw exception, as it should" << std::endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
/* Set the worth and all is well (this is normally done by some perf2worth functor */
|
||||
|
|
@ -355,10 +355,10 @@ void the_main()
|
|||
eo2.worth(3);
|
||||
eo4.worth(5);
|
||||
|
||||
cout << "with maximization " << endl;
|
||||
cout << eo2.fitness() << endl;
|
||||
cout << eo4.fitness() << endl;
|
||||
cout << eo2.fitness() << " < " << eo4.fitness() << " returns " << (eo2 < eo4) << endl;
|
||||
std::cout << "with maximization " << std::endl;
|
||||
std::cout << eo2.fitness() << std::endl;
|
||||
std::cout << eo4.fitness() << std::endl;
|
||||
std::cout << eo2.fitness() << " < " << eo4.fitness() << " returns " << (eo2 < eo4) << std::endl;
|
||||
|
||||
/* Test the minimization of fitness */
|
||||
minimization_test();
|
||||
|
|
@ -373,7 +373,7 @@ void the_main()
|
|||
|
||||
algo(pop0);
|
||||
|
||||
cout << pop0[0].fitness() << endl;
|
||||
std::cout << pop0[0].fitness() << std::endl;
|
||||
|
||||
assert(pop0[0].fitness() == 1);
|
||||
|
||||
|
|
@ -389,14 +389,14 @@ void the_main()
|
|||
// at this point getting the fitness should throw
|
||||
try
|
||||
{
|
||||
cout << pop1[0].fitness() << endl;
|
||||
cout << "did not throw" << endl;
|
||||
std::cout << pop1[0].fitness() << std::endl;
|
||||
std::cout << "did not throw" << std::endl;
|
||||
assert(false); // should throw
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Fitness threw exception, as it should" << endl;
|
||||
cout << e.what() << endl;
|
||||
std::cout << "Fitness threw exception, as it should" << std::endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
// at this point trying to scale should throw
|
||||
|
|
@ -405,9 +405,9 @@ void the_main()
|
|||
algo(pop1); // should complain that it cannot scale
|
||||
assert(false); // so it would never get here
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{ // but rather ends here
|
||||
cout << e.what() << endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
// ok, now set the scaling
|
||||
|
|
@ -415,7 +415,7 @@ void the_main()
|
|||
|
||||
algo(pop1);
|
||||
|
||||
cout << "the fitness has been transformed from " << pop1[0].performance() << " to exp(-1) = " << pop1[0].fitness() << endl;
|
||||
std::cout << "the fitness has been transformed from " << pop1[0].performance() << " to exp(-1) = " << pop1[0].fitness() << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
|
@ -424,9 +424,9 @@ int main()
|
|||
{
|
||||
the_main();
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ int main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "population:" << endl;
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
|
@ -83,17 +83,17 @@ int main()
|
|||
{
|
||||
ea(pop);
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cout << "exception: " << e.what() << endl;;
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cout << "pop" << endl;
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
cout << "\n --> Number of Evaluations = " << eval.getValue() << endl;
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ int main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "population:" << endl;
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
|
@ -87,17 +87,17 @@ int main()
|
|||
{
|
||||
ea(pop);
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cout << "exception: " << e.what() << endl;;
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cout << "pop" << endl;
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
cout << "\n --> Number of Evaluations = " << eval.getValue() << endl;
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ int main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "population:" << endl;
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
|
@ -87,17 +87,17 @@ int main()
|
|||
{
|
||||
ea(pop);
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cout << "exception: " << e.what() << endl;;
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cout << "pop" << endl;
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
cout << "\n --> Number of Evaluations = " << eval.getValue() << endl;
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ int main()
|
|||
{
|
||||
Chrom chrom1, chrom2;
|
||||
|
||||
cout << "chrom1 = " << chrom1 << endl
|
||||
<< "chrom2 = " << chrom2 << endl;
|
||||
std::cout << "chrom1 = " << chrom1 << std::endl
|
||||
<< "chrom2 = " << chrom2 << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ main(int argc, char *argv[]) {
|
|||
eoAtomRandom<char> randomer( charNE );
|
||||
eoAtomMutation< eoString<float> > mutator2 ( randomer, 0.5 );
|
||||
|
||||
cout << "Before aString " << aString << endl;
|
||||
std::cout << "Before aString " << aString << std::endl;
|
||||
mutator( aString);
|
||||
cout << " after mutator " << aString << endl;
|
||||
std::cout << " after mutator " << aString << std::endl;
|
||||
mutator2( aString);
|
||||
cout << " after mutator2 " << aString << endl;;
|
||||
std::cout << " after mutator2 " << aString << std::endl;;
|
||||
return 0; // to avoid VC++ complaints
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ int main()
|
|||
eo2 _2;
|
||||
int i = _2();
|
||||
|
||||
cout << i << '\n';
|
||||
std::cout << i << '\n';
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ int the_main(int argc, char **argv)
|
|||
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
|
||||
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
|
||||
eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
|
||||
eoValueParam<string> load_name("", "Load","Load",'L');
|
||||
eoValueParam<string> save_name("", "Save","Save",'S');
|
||||
eoValueParam<std::string> load_name("", "Load","Load",'L');
|
||||
eoValueParam<std::string> save_name("", "Save","Save",'S');
|
||||
|
||||
// Register them
|
||||
parser.processParam(rate, "Genetic Operators");
|
||||
|
|
@ -122,7 +122,7 @@ int the_main(int argc, char **argv)
|
|||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
parser.printHelp(std::cout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ int the_main(int argc, char **argv)
|
|||
|
||||
while (time(0) == now) {} // wait a second to test timed saver
|
||||
|
||||
cout << "gen " << generationCounter.value() << endl;
|
||||
std::cout << "gen " << generationCounter.value() << std::endl;
|
||||
}
|
||||
|
||||
// run the algorithm
|
||||
|
|
@ -161,7 +161,7 @@ int the_main(int argc, char **argv)
|
|||
// Save when needed
|
||||
if (save_name.value() != "")
|
||||
{
|
||||
string file_name = save_name.value();
|
||||
std::string file_name = save_name.value();
|
||||
save_name.value() = ""; // so that it does not appear in the parser section of the state file
|
||||
state.save(file_name);
|
||||
}
|
||||
|
|
@ -175,9 +175,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << endl;
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,22 +46,22 @@ int main_function(int argc, char *argv[])
|
|||
// Run the appropriate algorithm
|
||||
if (simpleParam.value() == false)
|
||||
{
|
||||
cout << "Using eoReal" << endl;
|
||||
std::cout << "Using eoReal" << std::endl;
|
||||
runAlgorithm(eoReal<FitT>(), parser, state);
|
||||
}
|
||||
else if (stdevsParam.value() == false)
|
||||
{
|
||||
cout << "Using eoEsSimple" << endl;
|
||||
std::cout << "Using eoEsSimple" << std::endl;
|
||||
runAlgorithm(eoEsSimple<FitT>(), parser, state);
|
||||
}
|
||||
else if (corrParam.value() == false)
|
||||
{
|
||||
cout << "Using eoEsStdev" << endl;
|
||||
std::cout << "Using eoEsStdev" << std::endl;
|
||||
runAlgorithm(eoEsStdev<FitT>(), parser, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Using eoEsFull" << endl;
|
||||
std::cout << "Using eoEsFull" << std::endl;
|
||||
runAlgorithm(eoEsFull<FitT>(), parser, state);
|
||||
}
|
||||
|
||||
|
|
@ -84,9 +84,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -136,13 +136,13 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state)
|
|||
|
||||
//// GO
|
||||
///////
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
std::cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
std::cout << "Final Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,9 +99,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
@ -174,6 +174,6 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _
|
|||
es(pop);
|
||||
|
||||
pop.sort();
|
||||
cout << "Final population\n" << pop << endl;
|
||||
std::cout << "Final population\n" << pop << std::endl;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ main(int argc, char *argv[]) {
|
|||
FirstEO.StdDevLength(), FirstEO.size(),
|
||||
FirstEO.CorCffLength() );
|
||||
|
||||
cout << "First EO " << FirstEO << endl;
|
||||
std::cout << "First EO " << FirstEO << std::endl;
|
||||
MyMut(FirstEO);
|
||||
cout << "First EO mutated" << FirstEO << endl;
|
||||
std::cout << "First EO mutated" << FirstEO << std::endl;
|
||||
|
||||
/*
|
||||
// Evolution and population parameters
|
||||
|
|
@ -88,10 +88,10 @@ main(int argc, char *argv[]) {
|
|||
unsigned i, iind;
|
||||
|
||||
|
||||
cout << "Initial population: \n" << endl;
|
||||
std::cout << "Initial population: \n" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i) {
|
||||
eval(pop[i]);
|
||||
cout << pop[i].fitness() << "\t" << pop[i] << endl;
|
||||
std::cout << pop[i].fitness() << "\t" << pop[i] << std::endl;
|
||||
}
|
||||
|
||||
// the Operators
|
||||
|
|
@ -107,9 +107,9 @@ main(int argc, char *argv[]) {
|
|||
|
||||
ea(pop);
|
||||
|
||||
cout << "Final population: \n" << endl;
|
||||
std::cout << "Final population: \n" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << pop[i].fitness() << "\t" << pop[i] << endl;
|
||||
std::cout << pop[i].fitness() << "\t" << pop[i] << std::endl;
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "population:" << endl;
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
|
||||
// selection
|
||||
|
|
@ -68,15 +68,15 @@ main()
|
|||
{
|
||||
ea(pop);
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cout << "exception: " << e.what() << endl;;
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cout << "pop" << endl;
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ struct UserDefStruct
|
|||
enum Enum { just, another, test } d;
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os, const UserDefStruct& str)
|
||||
std::ostream& operator<<(std::ostream& os, const UserDefStruct& str)
|
||||
{
|
||||
return os << str.a << ' ' << str.b << ' ' << str.c << ' ' << static_cast<int>(str.d) << ' ';
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ istream& operator>>(istream& is, UserDefStruct& str)
|
|||
|
||||
UserDefStruct RandomStruct()
|
||||
{
|
||||
cout << "RandomStruct\n";
|
||||
std::cout << "RandomStruct\n";
|
||||
|
||||
UserDefStruct result;
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ UserDefStruct RandomStruct()
|
|||
|
||||
bool UserDefMutate(UserDefStruct& a)
|
||||
{
|
||||
cout << "UserDefMutate\n";
|
||||
std::cout << "UserDefMutate\n";
|
||||
a = RandomStruct(); // just for testing
|
||||
|
||||
if (rng.flip(0.1f))
|
||||
|
|
@ -69,7 +69,7 @@ bool UserDefMutate(UserDefStruct& a)
|
|||
|
||||
bool UserDefBinCrossover(UserDefStruct& a, const UserDefStruct& b)
|
||||
{
|
||||
cout << "UserDefBinCrossover\n";
|
||||
std::cout << "UserDefBinCrossover\n";
|
||||
|
||||
if (rng.flip(0.5))
|
||||
a.a = b.a;
|
||||
|
|
@ -84,7 +84,7 @@ bool UserDefBinCrossover(UserDefStruct& a, const UserDefStruct& b)
|
|||
|
||||
bool UserDefQuadCrossover(UserDefStruct& a, UserDefStruct& b)
|
||||
{
|
||||
cout << "UserDefQuadCrossover\n";
|
||||
std::cout << "UserDefQuadCrossover\n";
|
||||
if (rng.flip(0.5))
|
||||
swap(a.a, b.a);
|
||||
if (rng.flip(0.5))
|
||||
|
|
@ -99,7 +99,7 @@ bool UserDefQuadCrossover(UserDefStruct& a, UserDefStruct& b)
|
|||
|
||||
float UserDefEvalFunc(const UserDefStruct& a)
|
||||
{
|
||||
cout << "UserDefEvalFunc\n";
|
||||
std::cout << "UserDefEvalFunc\n";
|
||||
return a.b;
|
||||
}
|
||||
|
||||
|
|
@ -121,11 +121,11 @@ int main()
|
|||
EoType eo2;
|
||||
init(eo2);
|
||||
|
||||
cout << "before mutation " << eo1 << '\n';
|
||||
std::cout << "before mutation " << eo1 << '\n';
|
||||
mutate(eo1);
|
||||
cout << "after mutation " << eo1 << '\n';
|
||||
std::cout << "after mutation " << eo1 << '\n';
|
||||
cross1(eo1, eo2);
|
||||
cout << "after crossover " << eo1 << '\n';
|
||||
std::cout << "after crossover " << eo1 << '\n';
|
||||
|
||||
cross2(eo1,eo2);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,18 +55,18 @@ int main(int argc, char* argv[])
|
|||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<EOT>(eval, pop);
|
||||
// print it out
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
std::cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
std::cout << "Final Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,9 +75,9 @@ main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "population:" << endl;
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
eoBinBitFlip<Chrom> bitflip;
|
||||
eoBinCrossover<Chrom> xover;
|
||||
|
|
@ -123,7 +123,7 @@ main()
|
|||
|
||||
state.registerObject(pop);
|
||||
|
||||
state.save(std::cout);
|
||||
state.save(std::std::cout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,16 +32,16 @@
|
|||
|
||||
struct Dummy : public EO<double>
|
||||
{
|
||||
typedef double Type;
|
||||
typedef double Type;
|
||||
Dummy(std::string _s="") : s(_s) {}
|
||||
|
||||
void printOn(ostream & _os) const
|
||||
void printOn(std::ostream & _os) const
|
||||
{
|
||||
EO<double>::printOn(_os);
|
||||
_os << " - " << s ;
|
||||
}
|
||||
|
||||
string s;
|
||||
std::string s;
|
||||
};
|
||||
|
||||
typedef Dummy EOT;
|
||||
|
|
@ -59,9 +59,9 @@ class monop : public eoMonOp<EOT>
|
|||
_eo.fitness(_eo.fitness()+pSize);
|
||||
return false;
|
||||
}
|
||||
string className() const {return sig;}
|
||||
std::string className() const {return sig;}
|
||||
private:
|
||||
string sig;
|
||||
std::string sig;
|
||||
};
|
||||
|
||||
class binop: public eoBinOp<EOT>
|
||||
|
|
@ -74,13 +74,13 @@ class binop: public eoBinOp<EOT>
|
|||
_eo1.fitness(_eo1.fitness()+f);
|
||||
return false;
|
||||
}
|
||||
string className() const {return "binop";}
|
||||
std::string className() const {return "binop";}
|
||||
};
|
||||
|
||||
class quadop: public eoQuadOp<EOT>
|
||||
{
|
||||
public :
|
||||
string className() const {return "quadop";}
|
||||
std::string className() const {return "quadop";}
|
||||
bool operator()(EOT& a, EOT& b)
|
||||
{
|
||||
EOT oi = a;
|
||||
|
|
@ -98,7 +98,7 @@ class quadop: public eoQuadOp<EOT>
|
|||
class quadClone: public eoQuadOp<EOT>
|
||||
{
|
||||
public :
|
||||
string className() const {return "quadclone";}
|
||||
std::string className() const {return "quadclone";}
|
||||
bool operator()(EOT& , EOT& ) {return false;}
|
||||
};
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ class one2threeOp : public eoGenOp<EOT> // :-)
|
|||
eo.s = "v(" + eo.s + ", 0)"; // only now change the thing
|
||||
// oh right, and invalidate fitnesses
|
||||
}
|
||||
virtual string className() const {return "one2threeOp";}
|
||||
virtual std::string className() const {return "one2threeOp";}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ class two2oneOp : public eoGenOp<EOT> // :-)
|
|||
eo.s = "221(" + eo.s + ", " + eo2.s + ")";
|
||||
// oh right, and invalidate fitnesses
|
||||
}
|
||||
virtual string className() const {return "two2oneOp";}
|
||||
virtual std::string className() const {return "two2oneOp";}
|
||||
};
|
||||
|
||||
class three2threeOp : public eoGenOp<EOT> // :-)
|
||||
|
|
@ -152,14 +152,14 @@ class three2threeOp : public eoGenOp<EOT> // :-)
|
|||
EOT a = eo1;
|
||||
EOT b = eo2;
|
||||
EOT c = eo3;
|
||||
cout << "les selectionnes: a=" << a << " et b=" << b << " et c=" << c << endl;
|
||||
std::cout << "les selectionnes: a=" << a << " et b=" << b << " et c=" << c << std::endl;
|
||||
eo1.s = "323-1(" + a.s + ", " + b.s + ", " + c.s + ")";
|
||||
eo2.s = "323-2(" + a.s + ", " + b.s + ", " + c.s + ")";
|
||||
eo3.s = "323-3(" + a.s + ", " + b.s + ", " + c.s + ")";
|
||||
// oh right, and invalidate fitnesses
|
||||
cout << "les enfants: a=" << eo1 << " et b=" << eo2 << " et c=" << eo3 << endl;
|
||||
std::cout << "les enfants: a=" << eo1 << " et b=" << eo2 << " et c=" << eo3 << std::endl;
|
||||
}
|
||||
virtual string className() const {return "three2threeOp";}
|
||||
virtual std::string className() const {return "three2threeOp";}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -172,13 +172,13 @@ void init(eoPop<Dummy> & _pop, unsigned _pSize)
|
|||
}
|
||||
else
|
||||
{
|
||||
throw runtime_error("init pop with 0 size");
|
||||
throw std::runtime_error("init pop with 0 size");
|
||||
}
|
||||
for (unsigned i=0; i<_pSize; i++)
|
||||
{
|
||||
char s[255];
|
||||
ostrstream os(s, 254);
|
||||
os << i << ends;
|
||||
std::ostrstream os(s, 254);
|
||||
os << i << std::ends;
|
||||
_pop[i] = Dummy(s);
|
||||
_pop[i].fitness(i);
|
||||
}
|
||||
|
|
@ -200,7 +200,7 @@ int the_main(int argc, char **argv)
|
|||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -267,7 +267,7 @@ int the_main(int argc, char **argv)
|
|||
init(pop, pSize);
|
||||
// sort pop so seqPopulator is identical to SelectPopulator(SequentialSelect)
|
||||
pop.sort();
|
||||
cout << "Population initiale\n" << pop << endl;
|
||||
std::cout << "Population initiale\n" << pop << std::endl;
|
||||
|
||||
// To simulate SGA: first a prop between quadOp and quadClone
|
||||
eoProportionalOp<EOT> pSGAOp;
|
||||
|
|
@ -286,25 +286,25 @@ int the_main(int argc, char **argv)
|
|||
while (offspring.size() < pop.size())
|
||||
{
|
||||
virtualSGA(popit);
|
||||
cout << "SeqPopulator boucle et incremente\n";
|
||||
std::cout << "SeqPopulator boucle et incremente\n";
|
||||
++popit;
|
||||
}
|
||||
}
|
||||
catch(eoPopulator<EOT>::OutOfIndividuals&)
|
||||
{
|
||||
cout << "Warning: not enough individuals to handle\n";
|
||||
std::cout << "Warning: not enough individuals to handle\n";
|
||||
}
|
||||
|
||||
|
||||
swap(pop, offspring);
|
||||
std::swap(pop, offspring);
|
||||
offspring.clear();
|
||||
|
||||
// ok, now print
|
||||
cout << "Apres virtualSGA \n" << pop << endl;
|
||||
std::cout << "Apres virtualSGA \n" << pop << std::endl;
|
||||
init(pop, pSize);
|
||||
|
||||
cout << "=========================================================\n";
|
||||
cout << "Now the eoSelectPopulator version !" << endl;
|
||||
std::cout << "=========================================================\n";
|
||||
std::cout << "Now the eoSelectPopulator version !" << std::endl;
|
||||
|
||||
eoSequentialSelect<EOT> seqSelect;
|
||||
// select.init(); should be sorted out: is it the setup method???
|
||||
|
|
@ -313,18 +313,18 @@ int the_main(int argc, char **argv)
|
|||
while (offspring.size() < 2*pop.size())
|
||||
{
|
||||
virtualSGA(it_step3);
|
||||
cout << "SelectPopulator boucle et incremente\n";
|
||||
std::cout << "SelectPopulator boucle et incremente\n";
|
||||
++it_step3;
|
||||
}
|
||||
|
||||
swap(pop, offspring);
|
||||
std::swap(pop, offspring);
|
||||
offspring.clear();
|
||||
|
||||
// ok, now print
|
||||
cout << "Apres SGA-like eoSelectivePopulator\n" << pop << endl;
|
||||
std::cout << "Apres SGA-like eoSelectivePopulator\n" << pop << std::endl;
|
||||
|
||||
cout << "=========================================================\n";
|
||||
cout << "Now the pure addition !" << endl;
|
||||
std::cout << "=========================================================\n";
|
||||
std::cout << "Now the pure addition !" << std::endl;
|
||||
|
||||
init(pop, pSize);
|
||||
eoSelectivePopulator<EOT> it_step4(pop, offspring, seqSelect);
|
||||
|
|
@ -334,11 +334,11 @@ int the_main(int argc, char **argv)
|
|||
++it_step4;
|
||||
}
|
||||
|
||||
swap(pop, offspring);
|
||||
std::swap(pop, offspring);
|
||||
offspring.clear();
|
||||
|
||||
// ok, now print
|
||||
cout << "Apres Quad+Mon ds un eoSelectivePopulator\n" << pop << endl;
|
||||
std::cout << "Apres Quad+Mon ds un eoSelectivePopulator\n" << pop << std::endl;
|
||||
|
||||
// On teste 1->3
|
||||
init(pop, pSize);
|
||||
|
|
@ -349,11 +349,11 @@ int the_main(int argc, char **argv)
|
|||
++it_step5;
|
||||
}
|
||||
|
||||
swap(pop, offspring);
|
||||
std::swap(pop, offspring);
|
||||
offspring.clear();
|
||||
|
||||
// ok, now print
|
||||
cout << "Apres 1->3 seul ds un eoSelectivePopulator\n" << pop << endl;
|
||||
std::cout << "Apres 1->3 seul ds un eoSelectivePopulator\n" << pop << std::endl;
|
||||
|
||||
// On teste 3->3
|
||||
init(pop, pSize);
|
||||
|
|
@ -364,11 +364,11 @@ int the_main(int argc, char **argv)
|
|||
++it_step6;
|
||||
}
|
||||
|
||||
swap(pop, offspring);
|
||||
std::swap(pop, offspring);
|
||||
offspring.clear();
|
||||
|
||||
// ok, now print
|
||||
cout << "Apres 3->3 seul ds un eoSelectivePopulator\n" << pop << endl;
|
||||
std::cout << "Apres 3->3 seul ds un eoSelectivePopulator\n" << pop << std::endl;
|
||||
|
||||
|
||||
return 1;
|
||||
|
|
@ -380,9 +380,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << endl;
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,20 +11,20 @@ main()
|
|||
{
|
||||
eoNonUniform nu(1000);
|
||||
|
||||
cout << "----------------------------------------------------------" << endl
|
||||
std::cout << "----------------------------------------------------------" << std::endl
|
||||
<< "nu.step() = " << nu.step()
|
||||
<< "\t nu.num_step() = " << nu.num_step() << endl
|
||||
<< "----------------------------------------------------------" << endl;
|
||||
<< "\t nu.num_step() = " << nu.num_step() << std::endl
|
||||
<< "----------------------------------------------------------" << std::endl;
|
||||
|
||||
eoLinear l1(0, 1, nu), l2(1, 0, nu);
|
||||
eoNegExp2 n1(0.1, 8, nu), n2(0.75, 3, nu);
|
||||
|
||||
for (; nu; ++nu)
|
||||
{
|
||||
cout << nu.step()
|
||||
std::cout << nu.step()
|
||||
<< "\t" << l1() << "\t" << l2()
|
||||
<< "\t" << n1() << "\t" << n2()
|
||||
<< endl;
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,9 +121,9 @@ int main(int argc, char* argv[])
|
|||
|
||||
dea(distrib); // run the dea
|
||||
|
||||
cout << "Final Distribution\n";
|
||||
distrib.printOn(cout);
|
||||
cout << endl;
|
||||
std::cout << "Final Distribution\n";
|
||||
distrib.printOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
|
||||
#if !defined(NO_GNUPLOT)
|
||||
// wait - for graphical output
|
||||
|
|
@ -134,8 +134,8 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
#endif
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public:
|
|||
{
|
||||
unsigned sz = _parents.size();
|
||||
_parents.reserve(_parents.size() + _offspring.size());
|
||||
copy(_offspring.begin(), _offspring.end(), back_inserter(_parents));
|
||||
std::copy(_offspring.begin(), _offspring.end(), back_inserter(_parents));
|
||||
|
||||
// calculate worths
|
||||
perf2worth(_parents);
|
||||
|
|
@ -131,7 +131,7 @@ eoPerf2Worth<EOT, double>& make_perf2worth(eoParser& parser, eoState& state)
|
|||
|
||||
if (what > 2)
|
||||
{
|
||||
cout << "Warning, need an integer < 3 for perf2worth" << endl;
|
||||
std::cout << "Warning, need an integer < 3 for perf2worth" << std::endl;
|
||||
// should actually set parser flag, but I don't care
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +210,7 @@ void the_main(int argc, char* argv[])
|
|||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
parser.printHelp(std::cout);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -225,9 +225,9 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cout << "Exception thrown: " << e.what() << endl;
|
||||
std::cout << "Exception thrown: " << e.what() << std::endl;
|
||||
throw e; // make sure it does not pass the test
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,11 +42,11 @@ template <class F>
|
|||
void compare(F & _eo1, F & _eo2)
|
||||
{
|
||||
if (_eo1.dominates(_eo2))
|
||||
cout << _eo1 << " dominates " << _eo2 << endl;
|
||||
std::cout << _eo1 << " dominates " << _eo2 << std::endl;
|
||||
else if (_eo2.dominates(_eo1))
|
||||
cout << _eo2 << " dominates " << _eo1 << endl;
|
||||
std::cout << _eo2 << " dominates " << _eo1 << std::endl;
|
||||
else
|
||||
cout << "None of " << _eo1 << " and " << _eo2 << "dominates the other" << endl;
|
||||
std::cout << "None of " << _eo1 << " and " << _eo2 << "dominates the other" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ int main()
|
|||
|
||||
if (!f0.dominates(f2))
|
||||
{
|
||||
cout << f2 << " not dominated by " << f0;
|
||||
std::cout << f2 << " not dominated by " << f0;
|
||||
throw;
|
||||
}
|
||||
|
||||
|
|
@ -83,13 +83,13 @@ int main()
|
|||
|
||||
if (f0.dominates(f1) || f1.dominates(f0))
|
||||
{
|
||||
cout << f0 << " and " << f1 << " dominate";
|
||||
std::cout << f0 << " and " << f1 << " dominate";
|
||||
throw;
|
||||
}
|
||||
|
||||
if (! (f0 == f0))
|
||||
{
|
||||
cout << "f0 == f0 failed" << endl;
|
||||
std::cout << "f0 == f0 failed" << std::endl;
|
||||
throw;
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ int main()
|
|||
// now the run-time set-able number of objectives
|
||||
////////////////////////////////////////////
|
||||
|
||||
cout << "On y va" << endl;
|
||||
std::cout << "On y va" << std::endl;
|
||||
|
||||
|
||||
// setup fitness WARNING do not try to allocate any EO before that (runtime error)
|
||||
|
|
@ -140,7 +140,7 @@ int main()
|
|||
b[0]=true;
|
||||
b[1]=false;
|
||||
VarFitness::setUp(2, b);
|
||||
cout << "\nMAXimizing on Obj 0 and MINimizing on Obj 1\n";
|
||||
std::cout << "\nMAXimizing on Obj 0 and MINimizing on Obj 1\n";
|
||||
|
||||
VarFitness mv0;
|
||||
VarFitness mv1;
|
||||
|
|
@ -166,11 +166,11 @@ int main()
|
|||
compare <VarFitness>(mv1,mv3);
|
||||
compare <VarFitness>(mv2,mv3);
|
||||
|
||||
cout << "\nChanging now the min <-> max\n";
|
||||
std::cout << "\nChanging now the min <-> max\n";
|
||||
b[0]=false;
|
||||
b[1]=true;
|
||||
VarFitness::setUp(2, b);
|
||||
cout << "\nMINimizing on Obj 0 and MAXimizing on Obj 1\n";
|
||||
std::cout << "\nMINimizing on Obj 0 and MAXimizing on Obj 1\n";
|
||||
compare <VarFitness>(mv0,mv1);
|
||||
compare <VarFitness>(mv0,mv2);
|
||||
compare <VarFitness>(mv0,mv3);
|
||||
|
|
@ -178,7 +178,7 @@ int main()
|
|||
compare <VarFitness>(mv1,mv3);
|
||||
compare <VarFitness>(mv2,mv3);
|
||||
|
||||
cout << "\nTesting WARNING\n";
|
||||
std::cout << "\nTesting WARNING\n";
|
||||
b.resize(3);
|
||||
b[0]=false;
|
||||
b[1]=true;
|
||||
|
|
@ -186,9 +186,9 @@ int main()
|
|||
VarFitness::setUp(3, b);
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
CVS Info: $Date: 2001-04-24 04:52:04 $ $Author: evomarc $ $Revision: 1.12 $
|
||||
CVS Info: $Date: 2003-02-27 19:20:24 $ $Author: okoenig $ $Revision: 1.13 $
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -47,16 +47,16 @@ int main() {
|
|||
eoUniformGenerator<unsigned long> utest( 10000000U, 10000U);
|
||||
throw; // if this succeeds something is wrong, make sure that that is noticed
|
||||
}
|
||||
catch (logic_error& e)
|
||||
catch (std::logic_error& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
ofstream os("t-eoRandom.out");
|
||||
std::ofstream os("t-eoRandom.out");
|
||||
|
||||
for ( unsigned i = 0; i < 100; i ++)
|
||||
{
|
||||
os << u1() << "\t" << u2() << "\t" << u3() << endl;
|
||||
os << u1() << "\t" << u2() << "\t" << u3() << std::endl;
|
||||
}
|
||||
|
||||
return 0; // to avoid VC++ complaints
|
||||
|
|
|
|||
|
|
@ -55,18 +55,18 @@ int main(int argc, char* argv[])
|
|||
// evaluate intial population AFTER help and status in case it takes time
|
||||
apply<EOT>(eval, pop);
|
||||
// print it out
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
std::cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
|
||||
run_ea(ea, pop); // run the ea
|
||||
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
std::cout << "Final Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
struct Dummy : public EO<double>
|
||||
{
|
||||
typedef double Type;
|
||||
void printOn(ostream & _os) const
|
||||
void printOn(std::ostream & _os) const
|
||||
{
|
||||
_os << " - ";
|
||||
EO<double>::printOn(_os);
|
||||
|
|
@ -73,14 +73,14 @@ int the_main(int argc, char **argv)
|
|||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unsigned i;
|
||||
|
||||
cout << "Testing the replacements\nParents SIze = " << pSize
|
||||
<< " and offspring size = " << oSize << endl;
|
||||
std::cout << "Testing the replacements\nParents SIze = " << pSize
|
||||
<< " and offspring size = " << oSize << std::endl;
|
||||
|
||||
rng.reseed(42);
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ int the_main(int argc, char **argv)
|
|||
for (i=0; i<oSize; i++)
|
||||
orgOffspring[i].fitness(2*i);
|
||||
|
||||
cout << "Initial parents (odd)\n" << orgParents << "\n And initial offsprings (even)\n" << orgOffspring << endl;
|
||||
std::cout << "Initial parents (odd)\n" << orgParents << "\n And initial offsprings (even)\n" << orgOffspring << std::endl;
|
||||
|
||||
// now the ones we're going to play with
|
||||
eoDummyPop parents(0);
|
||||
|
|
@ -116,50 +116,50 @@ cout << "Initial parents (odd)\n" << orgParents << "\n And initial offsprings (e
|
|||
parents = orgParents;
|
||||
offspring = orgOffspring;
|
||||
|
||||
cout << "eoGenerationalReplacement\n";
|
||||
cout << "=========================\n";
|
||||
std::cout << "eoGenerationalReplacement\n";
|
||||
std::cout << "=========================\n";
|
||||
genReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (orogonally even\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (orogonally even\n" << offspring << std::endl;
|
||||
|
||||
// Plus
|
||||
parents = orgParents;
|
||||
offspring = orgOffspring;
|
||||
|
||||
cout << "eoPlusReplacement\n";
|
||||
cout << "=================\n";
|
||||
std::cout << "eoPlusReplacement\n";
|
||||
std::cout << "=================\n";
|
||||
plusReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
|
||||
|
||||
// EP (proche d'un PLUS
|
||||
parents = orgParents;
|
||||
offspring = orgOffspring;
|
||||
|
||||
cout << "eoEPReplacement\n";
|
||||
cout << "===============\n";
|
||||
std::cout << "eoEPReplacement\n";
|
||||
std::cout << "===============\n";
|
||||
epReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
|
||||
|
||||
// Comma
|
||||
parents = orgParents;
|
||||
offspring = orgOffspring;
|
||||
|
||||
if (parents.size() > offspring.size() )
|
||||
cout << "Skipping Comma Replacement, more parents than offspring\n";
|
||||
std::cout << "Skipping Comma Replacement, more parents than offspring\n";
|
||||
else
|
||||
{
|
||||
cout << "eoCommaReplacement\n";
|
||||
cout << "==================\n";
|
||||
std::cout << "eoCommaReplacement\n";
|
||||
std::cout << "==================\n";
|
||||
commaReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
|
||||
|
||||
// Comma with weak elitism
|
||||
parents = orgParents;
|
||||
offspring = orgOffspring;
|
||||
|
||||
cout << "The same, with WEAK elitism\n";
|
||||
cout << "===========================\n";
|
||||
std::cout << "The same, with WEAK elitism\n";
|
||||
std::cout << "===========================\n";
|
||||
weakElitistReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
|
||||
}
|
||||
|
||||
// preparing SSGA replace worse
|
||||
|
|
@ -167,31 +167,31 @@ cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originall
|
|||
offspring = orgOffspring;
|
||||
|
||||
if (parents.size() < offspring.size() )
|
||||
cout << "Skipping all SSGA Replacements, more offspring than parents\n";
|
||||
std::cout << "Skipping all SSGA Replacements, more offspring than parents\n";
|
||||
else
|
||||
{
|
||||
cout << "SSGA replace worse\n";
|
||||
cout << "==================\n";
|
||||
std::cout << "SSGA replace worse\n";
|
||||
std::cout << "==================\n";
|
||||
ssgaWorseReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
|
||||
|
||||
// SSGA deterministic tournament
|
||||
parents = orgParents;
|
||||
offspring = orgOffspring;
|
||||
|
||||
cout << "SSGA deterministic tournament\n";
|
||||
cout << "=============================\n";
|
||||
std::cout << "SSGA deterministic tournament\n";
|
||||
std::cout << "=============================\n";
|
||||
ssgaDTReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
|
||||
|
||||
// SSGA stochastic tournament
|
||||
parents = orgParents;
|
||||
offspring = orgOffspring;
|
||||
|
||||
cout << "SSGA stochastic tournament\n";
|
||||
cout << "==========================\n";
|
||||
std::cout << "SSGA stochastic tournament\n";
|
||||
std::cout << "==========================\n";
|
||||
ssgaDTReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
|
||||
}
|
||||
|
||||
// the general replacement
|
||||
|
|
@ -200,10 +200,10 @@ cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originall
|
|||
parents = orgParents;
|
||||
offspring = orgOffspring;
|
||||
|
||||
cout << "General - strong elitism\n";
|
||||
cout << "========================\n";
|
||||
std::cout << "General - strong elitism\n";
|
||||
std::cout << "========================\n";
|
||||
sAdReplace(parents, offspring);
|
||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
|
||||
|
||||
|
||||
return 1;
|
||||
|
|
@ -215,9 +215,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << endl;
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class eoMyEval : public eoEvalFunc<EOT>
|
|||
|
||||
void operator()(EOT& _eo)
|
||||
{
|
||||
_eo.fitness(*max_element(_eo.begin(), _eo.end()));
|
||||
_eo.fitness(*std::max_element(_eo.begin(), _eo.end()));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ class Xover : public eoBinOp<EOT>
|
|||
bool operator()(EOT& _eo, const EOT& _eo2)
|
||||
{
|
||||
unsigned point = rng.random(_eo.size());
|
||||
copy(_eo2.begin() + point, _eo2.end(), _eo.begin() + point);
|
||||
std::copy(_eo2.begin() + point, _eo2.end(), _eo.begin() + point);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
struct Dummy : public EO<double>
|
||||
{
|
||||
typedef double Type;
|
||||
void printOn(ostream & _os) const
|
||||
void printOn(std::ostream & _os) const
|
||||
{
|
||||
_os << " - ";
|
||||
EO<double>::printOn(_os);
|
||||
|
|
@ -44,15 +44,15 @@ unsigned isInPop(EOT & _indi, eoPop<EOT> & _pop)
|
|||
}
|
||||
|
||||
unsigned int pSize; // global variable, bouh!
|
||||
string fitnessType; // yes, a global variable :-)
|
||||
std::string fitnessType; // yes, a global variable :-)
|
||||
eoDummyPop parentsOrg;
|
||||
|
||||
template <class EOT>
|
||||
void testSelectMany(eoSelect<EOT> & _select, string _name)
|
||||
void testSelectMany(eoSelect<EOT> & _select, std::string _name)
|
||||
{
|
||||
unsigned i;
|
||||
cout << "\n\n" << fitnessType + _name << endl;
|
||||
cout << "===============\n";
|
||||
std::cout << "\n\n" << fitnessType + _name << std::endl;
|
||||
std::cout << "===============\n";
|
||||
|
||||
eoDummyPop parents(parentsOrg);
|
||||
eoDummyPop offspring(0);
|
||||
|
|
@ -61,28 +61,28 @@ void testSelectMany(eoSelect<EOT> & _select, string _name)
|
|||
_select(parents, offspring);
|
||||
|
||||
// compute stats
|
||||
vector<unsigned> nb(parents.size(), 0);
|
||||
std::vector<unsigned> nb(parents.size(), 0);
|
||||
for (i=0; i<offspring.size(); i++)
|
||||
{
|
||||
unsigned trouve = isInPop<Dummy>(offspring[i], parents);
|
||||
if (trouve == parents.size()) // pas trouve
|
||||
throw runtime_error("Pas trouve ds parents");
|
||||
throw std::runtime_error("Pas trouve ds parents");
|
||||
nb[trouve]++;
|
||||
}
|
||||
// dump to file so you can plot using gnuplot - dir name is hardcoded!
|
||||
string fName = "ResSelect/" + fitnessType + _name + ".select";
|
||||
ofstream os(fName.c_str());
|
||||
std::string fName = "ResSelect/" + fitnessType + _name + ".select";
|
||||
std::ofstream os(fName.c_str());
|
||||
for (i=0; i<parents.size(); i++)
|
||||
{
|
||||
cout << i << " -> " << ( (double)nb[i])/offspring.size() << endl;
|
||||
os << i << " " << ( (double)nb[i])/offspring.size() << endl;
|
||||
std::cout << i << " -> " << ( (double)nb[i])/offspring.size() << std::endl;
|
||||
os << i << " " << ( (double)nb[i])/offspring.size() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template <class EOT>
|
||||
void testSelectOne(eoSelectOne<EOT> & _select, eoHowMany & _offspringRate,
|
||||
eoHowMany & _fertileRate, string _name)
|
||||
eoHowMany & _fertileRate, std::string _name)
|
||||
{
|
||||
eoTruncatedSelectOne<EOT> truncSelect(_select, _fertileRate);
|
||||
eoSelectMany<EOT> percSelect(truncSelect, _offspringRate);
|
||||
|
|
@ -118,42 +118,42 @@ eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "to
|
|||
eoValueParam<double> rankingExponentParam = parser.createParam(1.0, "rankingExponent", "Exponent for the ranking selection",'e');
|
||||
double rankingExponent = rankingExponentParam.value();
|
||||
|
||||
eoValueParam<string> fitTypeParam = parser.createParam(string("linear"), "fitType", "Type of fitness (linear, exp, log, super",'f');
|
||||
eoValueParam<std::string> fitTypeParam = parser.createParam(std::string("linear"), "fitType", "Type of fitness (linear, exp, log, super",'f');
|
||||
fitnessType = fitTypeParam.value();
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
parser.printHelp(std::cout);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// hard-coded directory name ...
|
||||
system("mkdir ResSelect");
|
||||
cout << "Testing the Selections\nParents size = " << pSize
|
||||
std::cout << "Testing the Selections\nParents size = " << pSize
|
||||
<< ", offspring rate = " << oRate;
|
||||
cout << " and putting rsulting files in dir ResSelect" << endl;
|
||||
std::cout << " and putting rsulting files in dir ResSelect" << std::endl;
|
||||
|
||||
// initialize parent population
|
||||
parentsOrg.resize(pSize);
|
||||
if (fitnessType == string("linear"))
|
||||
if (fitnessType == std::string("linear"))
|
||||
for (unsigned i=0; i<pSize; i++)
|
||||
parentsOrg[i].fitness(i);
|
||||
else if (fitnessType == string("exp"))
|
||||
else if (fitnessType == std::string("exp"))
|
||||
for (unsigned i=0; i<pSize; i++)
|
||||
parentsOrg[i].fitness(exp((double)i));
|
||||
else if (fitnessType == string("log"))
|
||||
else if (fitnessType == std::string("log"))
|
||||
for (unsigned i=0; i<pSize; i++)
|
||||
parentsOrg[i].fitness(log(i+1.));
|
||||
else if (fitnessType == string("super"))
|
||||
else if (fitnessType == std::string("super"))
|
||||
{
|
||||
for (unsigned i=0; i<pSize-1; i++)
|
||||
parentsOrg[i].fitness(i);
|
||||
parentsOrg[pSize-1].fitness(10*pSize);
|
||||
}
|
||||
else
|
||||
throw runtime_error("Invalid fitness Type"+fitnessType);
|
||||
throw std::runtime_error("Invalid fitness Type"+fitnessType);
|
||||
|
||||
cout << "Initial parents (odd)\n" << parentsOrg << endl;
|
||||
std::cout << "Initial parents (odd)\n" << parentsOrg << std::endl;
|
||||
|
||||
// random seed
|
||||
eoValueParam<uint32>& seedParam = parser.createParam(uint32(0), "seed", "Random number seed", 'S');
|
||||
|
|
@ -177,7 +177,7 @@ eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "to
|
|||
testSelectOne<Dummy>(newRankingSelect, oRate, fRate, fileName);
|
||||
|
||||
// Exponential ranking using the perf2Worth construct
|
||||
cout << "rankingExponent " << rankingExponent << endl;
|
||||
std::cout << "rankingExponent " << rankingExponent << std::endl;
|
||||
eoRankingSelect<Dummy> expRankingSelect(rankingPressure,rankingExponent);
|
||||
sprintf(fileName,"ExpRank_%g_%g",rankingPressure, rankingExponent);
|
||||
testSelectOne<Dummy>(expRankingSelect, oRate, fRate, fileName);
|
||||
|
|
@ -215,9 +215,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << endl;
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,12 +48,12 @@ int the_main(int argc, char **argv)
|
|||
eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
|
||||
// test if user entered or if default value used
|
||||
if (parser.isItThere(seed))
|
||||
cout << "YES\n";
|
||||
std::cout << "YES\n";
|
||||
else
|
||||
cout << "NO\n";
|
||||
std::cout << "NO\n";
|
||||
|
||||
eoValueParam<string> load_name("", "Load","Load",'L');
|
||||
eoValueParam<string> save_name("", "Save","Save",'S');
|
||||
eoValueParam<std::string> load_name("", "Load","Load",'L');
|
||||
eoValueParam<std::string> save_name("", "Save","Save",'S');
|
||||
|
||||
|
||||
// Register them
|
||||
|
|
@ -69,7 +69,7 @@ int the_main(int argc, char **argv)
|
|||
|
||||
parser.processParam(boundParam, "Genetic Operators");
|
||||
|
||||
cout << "Bounds: " << boundParam.value() << endl;
|
||||
std::cout << "Bounds: " << boundParam.value() << std::endl;
|
||||
|
||||
eoState state;
|
||||
state.registerObject(parser);
|
||||
|
|
@ -89,7 +89,7 @@ int the_main(int argc, char **argv)
|
|||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
parser.printHelp(std::cout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ int the_main(int argc, char **argv)
|
|||
// Save when needed
|
||||
if (save_name.value() != "")
|
||||
{
|
||||
string file_name = save_name.value();
|
||||
std::string file_name = save_name.value();
|
||||
save_name.value() = ""; // so that it does not appear in the parser section of the state file
|
||||
state.save(file_name);
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ int the_main(int argc, char **argv)
|
|||
for (int i = 0; i < 100; ++i)
|
||||
rng.rand();
|
||||
|
||||
cout << "a random number is " << rng.random(1024) << endl;;
|
||||
std::cout << "a random number is " << rng.random(1024) << std::endl;;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -131,9 +131,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << endl;
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ private :
|
|||
template <class EOT, class FitnessType>
|
||||
void print_best(eoPop<EOT>& pop)
|
||||
{
|
||||
cout << endl;
|
||||
std::cout << std::endl;
|
||||
FitnessType best = pop[0].fitness();
|
||||
int index = 0;
|
||||
|
||||
|
|
@ -207,13 +207,13 @@ void print_best(eoPop<EOT>& pop)
|
|||
}
|
||||
}
|
||||
|
||||
cout << "\t";
|
||||
std::cout << "\t";
|
||||
|
||||
string str;
|
||||
pop[index].apply(str);
|
||||
|
||||
cout << str.c_str();
|
||||
cout << endl << "RMS Error = " << pop[index].fitness() << endl;
|
||||
std::cout << str.c_str();
|
||||
std::cout << std::endl << "RMS Error = " << pop[index].fitness() << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
|
@ -274,7 +274,7 @@ int main()
|
|||
// GP generation
|
||||
eoEasyEA<EoType> gp(checkPoint, eval, select, transform, replace);
|
||||
|
||||
cout << "Initialization done" << endl;
|
||||
std::cout << "Initialization done" << std::endl;
|
||||
|
||||
print_best<EoType, FitnessType>(pop);
|
||||
|
||||
|
|
@ -282,9 +282,9 @@ int main()
|
|||
{
|
||||
gp(pop);
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cout << "exception: " << e.what() << endl;;
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// t-eouniform
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream> // cout
|
||||
#include <iostream> // std::cout
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#include <eoUniform.h> // eoBin
|
||||
|
||||
|
|
@ -12,9 +12,9 @@ main() {
|
|||
eoUniform<float> u1(-2.5,3.5);
|
||||
eoUniform<double> u2(0.003, 0 );
|
||||
eoUniform<unsigned long> u3( 10000U, 10000000U);
|
||||
cout << "u1\t\tu2\t\tu3" << endl;
|
||||
std::cout << "u1\t\tu2\t\tu3" << std::endl;
|
||||
for ( unsigned i = 0; i < 100; i ++) {
|
||||
cout << u1() << "\t" << u2() << "\t" << u3() << endl;
|
||||
std::cout << u1() << "\t" << u2() << "\t" << u3() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream> // cout
|
||||
#include <iostream> // std::cout
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
|
||||
#include <assert.h>
|
||||
|
|
@ -59,11 +59,11 @@ int main()
|
|||
|
||||
init(chrom);
|
||||
|
||||
cout << chrom << endl;
|
||||
std::cout << chrom << std::endl;
|
||||
|
||||
Chrom2 chrom2(chrom);
|
||||
|
||||
cout << chrom2 << endl;
|
||||
std::cout << chrom2 << std::endl;
|
||||
|
||||
// eoInitVariableLength<Chrom1> initvar(
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream> // cout
|
||||
#include <iostream> // std::cout
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#include <eo> // general EO
|
||||
#include "../contrib/MGE/VirusOp.h"
|
||||
|
|
@ -47,30 +47,30 @@ int main()
|
|||
|
||||
Chrom chrom(SIZE), chrom2(SIZE);
|
||||
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
cout << chrom << endl;
|
||||
cout << chrom2 << endl;
|
||||
std::cout << chrom << std::endl;
|
||||
std::cout << chrom2 << std::endl;
|
||||
|
||||
// Virus Mutation
|
||||
VirusBitFlip<float> vf;
|
||||
unsigned i;
|
||||
for ( i = 0; i < 10; i++ ) {
|
||||
vf( chrom );
|
||||
cout << chrom << endl;
|
||||
std::cout << chrom << std::endl;
|
||||
}
|
||||
|
||||
// Chrom Mutation
|
||||
cout << "Chrom mutation--------" << endl;
|
||||
std::cout << "Chrom mutation--------" << std::endl;
|
||||
VirusMutation<float> vm;
|
||||
for ( i = 0; i < 10; i++ ) {
|
||||
vm( chrom );
|
||||
cout << chrom << endl;
|
||||
std::cout << chrom << std::endl;
|
||||
}
|
||||
|
||||
// Chrom Transmision
|
||||
cout << "Chrom transmission--------" << endl;
|
||||
std::cout << "Chrom transmission--------" << std::endl;
|
||||
VirusTransmission<float> vt;
|
||||
vt( chrom2, chrom );
|
||||
cout << chrom2 << endl;
|
||||
std::cout << chrom2 << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream> // cout
|
||||
#include <iostream> // std::cout
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#include <eo> // general EO
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
|
|
@ -45,91 +45,91 @@ void main_function()
|
|||
Chrom chrom(SIZE), chrom2;
|
||||
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
|
||||
cout << "chrom: " << chrom << endl;
|
||||
std::cout << "chrom: " << chrom << std::endl;
|
||||
chrom[0] = chrom[SIZE - 1] = true; chrom.fitness(binary_value(chrom));
|
||||
cout << "chrom: " << chrom << endl;
|
||||
std::cout << "chrom: " << chrom << std::endl;
|
||||
chrom[0] = chrom[SIZE - 1] = false; chrom.fitness(binary_value(chrom));
|
||||
cout << "chrom: " << chrom << endl;
|
||||
std::cout << "chrom: " << chrom << std::endl;
|
||||
chrom[0] = chrom[SIZE - 1] = true; chrom.fitness(binary_value(chrom));
|
||||
|
||||
cout << "chrom.className() = " << chrom.className() << endl;
|
||||
std::cout << "chrom.className() = " << chrom.className() << std::endl;
|
||||
|
||||
cout << "chrom: " << chrom << endl
|
||||
<< "chrom2: " << chrom2 << endl;
|
||||
std::cout << "chrom: " << chrom << std::endl
|
||||
<< "chrom2: " << chrom2 << std::endl;
|
||||
|
||||
char buff[1024];
|
||||
ostrstream os(buff, 1024);
|
||||
std::ostrstream os(buff, 1024);
|
||||
os << chrom;
|
||||
istrstream is(os.str());
|
||||
std::istrstream is(os.str());
|
||||
is >> chrom2; chrom.fitness(binary_value(chrom2));
|
||||
|
||||
cout << "\nTesting reading, writing\n";
|
||||
cout << "chrom: " << chrom << "\nchrom2: " << chrom2 << '\n';
|
||||
std::cout << "\nTesting reading, writing\n";
|
||||
std::cout << "chrom: " << chrom << "\nchrom2: " << chrom2 << '\n';
|
||||
|
||||
fill(chrom.begin(), chrom.end(), false);
|
||||
cout << "--------------------------------------------------"
|
||||
<< endl << "eoMonOp's aplied to .......... " << chrom << endl;
|
||||
std::fill(chrom.begin(), chrom.end(), false);
|
||||
std::cout << "--------------------------------------------------"
|
||||
<< std::endl << "eoMonOp's aplied to .......... " << chrom << std::endl;
|
||||
|
||||
eoInitFixedLength<Chrom>
|
||||
random(chrom.size(), gen);
|
||||
|
||||
random(chrom); chrom.fitness(binary_value(chrom));
|
||||
cout << "after eoBinRandom ............ " << chrom << endl;
|
||||
std::cout << "after eoBinRandom ............ " << chrom << std::endl;
|
||||
|
||||
eoOneBitFlip<Chrom> bitflip;
|
||||
bitflip(chrom); chrom.fitness(binary_value(chrom));
|
||||
cout << "after eoBitFlip .............. " << chrom << endl;
|
||||
std::cout << "after eoBitFlip .............. " << chrom << std::endl;
|
||||
|
||||
eoBitMutation<Chrom> mutation(0.5);
|
||||
mutation(chrom); chrom.fitness(binary_value(chrom));
|
||||
cout << "after eoBinMutation(0.5) ..... " << chrom << endl;
|
||||
std::cout << "after eoBinMutation(0.5) ..... " << chrom << std::endl;
|
||||
|
||||
eoBitInversion<Chrom> inversion;
|
||||
inversion(chrom); chrom.fitness(binary_value(chrom));
|
||||
cout << "after eoBinInversion ......... " << chrom << endl;
|
||||
std::cout << "after eoBinInversion ......... " << chrom << std::endl;
|
||||
|
||||
eoBitNext<Chrom> next;
|
||||
next(chrom); chrom.fitness(binary_value(chrom));
|
||||
cout << "after eoBinNext .............. " << chrom << endl;
|
||||
std::cout << "after eoBinNext .............. " << chrom << std::endl;
|
||||
|
||||
eoBitPrev<Chrom> prev;
|
||||
prev(chrom); chrom.fitness(binary_value(chrom));
|
||||
cout << "after eoBinPrev .............. " << chrom << endl;
|
||||
std::cout << "after eoBinPrev .............. " << chrom << std::endl;
|
||||
|
||||
fill(chrom.begin(), chrom.end(), false); chrom.fitness(binary_value(chrom));
|
||||
fill(chrom2.begin(), chrom2.end(), true); chrom2.fitness(binary_value(chrom2));
|
||||
cout << "--------------------------------------------------"
|
||||
<< endl << "eoBinOp's aplied to ... "
|
||||
<< chrom << " " << chrom2 << endl;
|
||||
std::fill(chrom.begin(), chrom.end(), false); chrom.fitness(binary_value(chrom));
|
||||
std::fill(chrom2.begin(), chrom2.end(), true); chrom2.fitness(binary_value(chrom2));
|
||||
std::cout << "--------------------------------------------------"
|
||||
<< std::endl << "eoBinOp's aplied to ... "
|
||||
<< chrom << " " << chrom2 << std::endl;
|
||||
|
||||
eo1PtBitXover<Chrom> xover;
|
||||
fill(chrom.begin(), chrom.end(), false);
|
||||
fill(chrom2.begin(), chrom2.end(), true);
|
||||
std::fill(chrom.begin(), chrom.end(), false);
|
||||
std::fill(chrom2.begin(), chrom2.end(), true);
|
||||
xover(chrom, chrom2);
|
||||
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
cout << "eoBinCrossover ........ " << chrom << " " << chrom2 << endl;
|
||||
std::cout << "eoBinCrossover ........ " << chrom << " " << chrom2 << std::endl;
|
||||
|
||||
for (i = 1; i < SIZE; i++)
|
||||
{
|
||||
eoNPtsBitXover<Chrom> nxover(i);
|
||||
fill(chrom.begin(), chrom.end(), false);
|
||||
fill(chrom2.begin(), chrom2.end(), true);
|
||||
std::fill(chrom.begin(), chrom.end(), false);
|
||||
std::fill(chrom2.begin(), chrom2.end(), true);
|
||||
nxover(chrom, chrom2);
|
||||
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
cout << "eoBinNxOver(" << i << ") ........ "
|
||||
<< chrom << " " << chrom2 << endl;
|
||||
std::cout << "eoBinNxOver(" << i << ") ........ "
|
||||
<< chrom << " " << chrom2 << std::endl;
|
||||
}
|
||||
|
||||
for (i = 1; i < SIZE / 2; i++)
|
||||
for (j = 1; j < SIZE / 2; j++)
|
||||
{
|
||||
eoBitGxOver<Chrom> gxover(i, j);
|
||||
fill(chrom.begin(), chrom.end(), false);
|
||||
fill(chrom2.begin(), chrom2.end(), true);
|
||||
std::fill(chrom.begin(), chrom.end(), false);
|
||||
std::fill(chrom2.begin(), chrom2.end(), true);
|
||||
gxover(chrom, chrom2);
|
||||
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
cout << "eoBinGxOver(" << i << ", " << j << ") ..... "
|
||||
<< chrom << " " << chrom2 << endl;
|
||||
std::cout << "eoBinGxOver(" << i << ", " << j << ") ..... "
|
||||
<< chrom << " " << chrom2 << std::endl;
|
||||
}
|
||||
|
||||
// test SGA algorithm
|
||||
|
|
@ -163,9 +163,9 @@ void main_function()
|
|||
|
||||
pop.sort();
|
||||
|
||||
cout << "Population " << pop << endl;
|
||||
std::cout << "Population " << pop << std::endl;
|
||||
|
||||
cout << "\nBest: " << pop[0].fitness() << '\n';
|
||||
std::cout << "\nBest: " << pop[0].fitness() << '\n';
|
||||
|
||||
/*
|
||||
|
||||
|
|
@ -174,16 +174,16 @@ void main_function()
|
|||
// Check multiOps
|
||||
eoMultiMonOp<Chrom> mOp( &next );
|
||||
mOp.adOp( &bitflip );
|
||||
cout << "before multiMonOp............ " << chrom << endl;
|
||||
std::cout << "before multiMonOp............ " << chrom << std::endl;
|
||||
mOp( chrom );
|
||||
cout << "after multiMonOp .............. " << chrom << endl;
|
||||
std::cout << "after multiMonOp .............. " << chrom << std::endl;
|
||||
|
||||
eoBinGxOver<Chrom> gxover(2, 4);
|
||||
eoMultiBinOp<Chrom> mbOp( &gxover );
|
||||
mOp.adOp( &bitflip );
|
||||
cout << "before multiBinOp............ " << chrom << " " << chrom2 << endl;
|
||||
std::cout << "before multiBinOp............ " << chrom << " " << chrom2 << std::endl;
|
||||
mbOp( chrom, chrom2 );
|
||||
cout << "after multiBinOp .............. " << chrom << " " << chrom2 <<endl;
|
||||
std::cout << "after multiBinOp .............. " << chrom << " " << chrom2 <<std::endl;
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
@ -207,9 +207,9 @@ int main()
|
|||
{
|
||||
main_function();
|
||||
}
|
||||
catch(exception& e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,9 +61,9 @@ main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "population:" << endl;
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
eoBinBitFlip<Chrom> bitflip;
|
||||
eoBinCrossover<Chrom> xover;
|
||||
|
|
@ -77,9 +77,9 @@ main()
|
|||
// reevaluation of fitness
|
||||
for_each(pop.begin(), pop.end(), BinaryValue());
|
||||
|
||||
cout << "new population:" << endl;
|
||||
std::cout << "new population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <time.h> // time
|
||||
#include <stdlib.h> // srand, rand
|
||||
#include <iostream> // cout
|
||||
#include <iostream> // std::cout
|
||||
|
||||
#include <eoScalarFitness.h>
|
||||
|
||||
|
|
@ -21,35 +21,35 @@ int test_fitness(Fitness a, Fitness b)
|
|||
// Fitness a = aval; //static_cast<double>(rand()) / RAND_MAX;
|
||||
// Fitness b = bval; //static_cast<double>(rand()) / RAND_MAX;
|
||||
|
||||
cout.precision(2);
|
||||
std::cout.precision(2);
|
||||
|
||||
unsigned repeat = 2;
|
||||
while (repeat--)
|
||||
{
|
||||
cout << "------------------------------------------------------" << endl;
|
||||
cout << "testing < ";
|
||||
std::cout << "------------------------------------------------------" << std::endl;
|
||||
std::cout << "testing < ";
|
||||
if (a < b)
|
||||
cout << a << " < " << b << " is true" << endl;
|
||||
std::cout << a << " < " << b << " is true" << std::endl;
|
||||
else
|
||||
cout << a << " < " << b << " is false" <<endl;
|
||||
std::cout << a << " < " << b << " is false" <<std::endl;
|
||||
|
||||
cout << "testing > ";
|
||||
std::cout << "testing > ";
|
||||
if (a > b)
|
||||
cout << a << " > " << b << " is true" << endl;
|
||||
std::cout << a << " > " << b << " is true" << std::endl;
|
||||
else
|
||||
cout << a << " > " << b << " is false" <<endl;
|
||||
std::cout << a << " > " << b << " is false" <<std::endl;
|
||||
|
||||
cout << "testing == ";
|
||||
std::cout << "testing == ";
|
||||
if (a == b)
|
||||
cout << a << " == " << b << " is true" << endl;
|
||||
std::cout << a << " == " << b << " is true" << std::endl;
|
||||
else
|
||||
cout << a << " == " << b << " is false" <<endl;
|
||||
std::cout << a << " == " << b << " is false" <<std::endl;
|
||||
|
||||
cout << "testing != ";
|
||||
std::cout << "testing != ";
|
||||
if (a != b)
|
||||
cout << a << " != " << b << " is true" << endl;
|
||||
std::cout << a << " != " << b << " is true" << std::endl;
|
||||
else
|
||||
cout << a << " != " << b << " is false" <<endl;
|
||||
std::cout << a << " != " << b << " is false" <<std::endl;
|
||||
|
||||
a = b;
|
||||
}
|
||||
|
|
@ -58,29 +58,29 @@ int test_fitness(Fitness a, Fitness b)
|
|||
|
||||
int main()
|
||||
{
|
||||
cout << "Testing minimizing fitness with 1 and 2" << endl;
|
||||
cout << "------------------------------------------------------" << endl;
|
||||
std::cout << "Testing minimizing fitness with 1 and 2" << std::endl;
|
||||
std::cout << "------------------------------------------------------" << std::endl;
|
||||
|
||||
eoMinimizingFitness a = 1;
|
||||
eoMinimizingFitness b = 2;
|
||||
|
||||
test_fitness(a, b);
|
||||
|
||||
cout << "Testing minimizing fitness with 2 and 1" << endl;
|
||||
cout << "------------------------------------------------------" << endl;
|
||||
std::cout << "Testing minimizing fitness with 2 and 1" << std::endl;
|
||||
std::cout << "------------------------------------------------------" << std::endl;
|
||||
|
||||
test_fitness(b, a);
|
||||
|
||||
cout << "Testing maximizing fitness with 1 and 2" << endl;
|
||||
cout << "------------------------------------------------------" << endl;
|
||||
std::cout << "Testing maximizing fitness with 1 and 2" << std::endl;
|
||||
std::cout << "------------------------------------------------------" << std::endl;
|
||||
|
||||
eoMaximizingFitness a1 = 1;
|
||||
eoMaximizingFitness b1 = 2;
|
||||
|
||||
test_fitness(a1,b1);
|
||||
|
||||
cout << "Testing maximizing fitness with 2 and 1" << endl;
|
||||
cout << "------------------------------------------------------" << endl;
|
||||
std::cout << "Testing maximizing fitness with 2 and 1" << std::endl;
|
||||
std::cout << "------------------------------------------------------" << std::endl;
|
||||
|
||||
test_fitness(b1,a1);
|
||||
|
||||
|
|
|
|||
|
|
@ -61,9 +61,9 @@ main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "population:" << endl;
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
|
||||
// selection
|
||||
|
|
@ -92,15 +92,15 @@ main()
|
|||
{
|
||||
generation(pop);
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cout << "exception: " << e.what() << endl;;
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cout << "pop[" << ++g << "]" << endl;
|
||||
std::cout << "pop[" << ++g << "]" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
} while (pop[0].fitness() < pow(2.0, CHROM_SIZE) - 1);
|
||||
|
||||
|
|
@ -126,19 +126,19 @@ main()
|
|||
{
|
||||
generation2(pop2);
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cout << "exception: " << e.what() << endl;;
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cout << "pop[" << ++g << "]" << endl;
|
||||
std::cout << "pop[" << ++g << "]" << std::endl;
|
||||
for (i = 0; i < pop2.size(); ++i)
|
||||
cout << "\t" << pop2[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << "\t" << pop2[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
} while (pop2[0].fitness() < pow(2.0, CHROM_SIZE) - 1);
|
||||
|
||||
cout << "Number of evaluations " << eval2.getNumOfEvaluations() << endl;
|
||||
std::cout << "Number of evaluations " << eval2.getNumOfEvaluations() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,18 +45,18 @@ main()
|
|||
pop2.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "--------------------------------------------------" << endl
|
||||
<< "breeders \tpop" << endl
|
||||
<< "--------------------------------------------------" << endl;
|
||||
std::cout << "--------------------------------------------------" << std::endl
|
||||
<< "breeders \tpop" << std::endl
|
||||
<< "--------------------------------------------------" << std::endl;
|
||||
for (i = 0; i < max(pop.size(), pop2.size()); i++)
|
||||
{
|
||||
if (pop.size() > i)
|
||||
cout << pop[i] << " " << pop[i].fitness() << " \t";
|
||||
std::cout << pop[i] << " " << pop[i].fitness() << " \t";
|
||||
else
|
||||
cout << "\t\t";
|
||||
std::cout << "\t\t";
|
||||
if (pop2.size() > i)
|
||||
cout << pop2[i] << " " << pop2[i].fitness();
|
||||
cout << endl;
|
||||
std::cout << pop2[i] << " " << pop2[i].fitness();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
eoInclusion<Chrom> inclusion(0.75);
|
||||
|
|
@ -71,22 +71,22 @@ main()
|
|||
pop5 = pop2;
|
||||
inclusion3(pop, pop5);
|
||||
|
||||
cout << endl
|
||||
<< "0.75 \t\t1.0 \t\t1.5" << endl
|
||||
<< "---- \t\t--- \t\t---" << endl;
|
||||
std::cout << std::endl
|
||||
<< "0.75 \t\t1.0 \t\t1.5" << std::endl
|
||||
<< "---- \t\t--- \t\t---" << std::endl;
|
||||
for (i = 0; i < pop5.size(); i++)
|
||||
{
|
||||
if (pop3.size() > i)
|
||||
cout << pop3[i] << " " << pop3[i].fitness() << " \t";
|
||||
std::cout << pop3[i] << " " << pop3[i].fitness() << " \t";
|
||||
else
|
||||
cout << " \t\t";
|
||||
std::cout << " \t\t";
|
||||
if (pop4.size() > i)
|
||||
cout << pop4[i] << " " << pop4[i].fitness() << " \t";
|
||||
std::cout << pop4[i] << " " << pop4[i].fitness() << " \t";
|
||||
else
|
||||
cout << " \t\t";
|
||||
std::cout << " \t\t";
|
||||
if (pop5.size() > i)
|
||||
cout << pop5[i] << " " << pop5[i].fitness();
|
||||
cout << endl;
|
||||
std::cout << pop5[i] << " " << pop5[i].fitness();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,18 +52,18 @@ main()
|
|||
pop2.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "--------------------------------------------------" << endl
|
||||
<< "breeders \tpop" << endl
|
||||
<< "--------------------------------------------------" << endl;
|
||||
std::cout << "--------------------------------------------------" << std::endl
|
||||
<< "breeders \tpop" << std::endl
|
||||
<< "--------------------------------------------------" << std::endl;
|
||||
for (i = 0; i < max(pop.size(), pop2.size()); i++)
|
||||
{
|
||||
if (pop.size() > i)
|
||||
cout << pop[i] << " " << pop[i].fitness() << " \t";
|
||||
std::cout << pop[i] << " " << pop[i].fitness() << " \t";
|
||||
else
|
||||
cout << "\t\t";
|
||||
std::cout << "\t\t";
|
||||
if (pop2.size() > i)
|
||||
cout << pop2[i] << " " << pop2[i].fitness();
|
||||
cout << endl;
|
||||
std::cout << pop2[i] << " " << pop2[i].fitness();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
eoInsertion<Chrom> insertion(0.75);
|
||||
|
|
@ -81,22 +81,22 @@ main()
|
|||
pop5 = pop2;
|
||||
insertion3(popx, pop5);
|
||||
|
||||
cout << endl
|
||||
<< "0.75 \t\t1.0 \t\t1.5" << endl
|
||||
<< "---- \t\t--- \t\t---" << endl;
|
||||
std::cout << std::endl
|
||||
<< "0.75 \t\t1.0 \t\t1.5" << std::endl
|
||||
<< "---- \t\t--- \t\t---" << std::endl;
|
||||
for (i = 0; i < pop5.size(); i++)
|
||||
{
|
||||
if (pop3.size() > i)
|
||||
cout << pop3[i] << " " << pop3[i].fitness() << " \t";
|
||||
std::cout << pop3[i] << " " << pop3[i].fitness() << " \t";
|
||||
else
|
||||
cout << " \t\t";
|
||||
std::cout << " \t\t";
|
||||
if (pop4.size() > i)
|
||||
cout << pop4[i] << " " << pop4[i].fitness() << " \t";
|
||||
std::cout << pop4[i] << " " << pop4[i].fitness() << " \t";
|
||||
else
|
||||
cout << " \t\t";
|
||||
std::cout << " \t\t";
|
||||
if (pop5.size() > i)
|
||||
cout << pop5[i] << " " << pop5[i].fitness();
|
||||
cout << endl;
|
||||
std::cout << pop5[i] << " " << pop5[i].fitness();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,18 +35,18 @@ main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
cout << "original population:" << endl;
|
||||
std::cout << "original population:" << std::endl;
|
||||
sort(pop.begin(), pop.end());
|
||||
for (i = 0; i < pop.size(); i++)
|
||||
cout << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
eoLottery<Chrom> lottery;
|
||||
lottery(pop, pop2);
|
||||
|
||||
cout << "selected by lottery population:" << endl;
|
||||
std::cout << "selected by lottery population:" << std::endl;
|
||||
sort(pop2.begin(), pop2.end());
|
||||
for (i = 0; i < pop2.size(); i++)
|
||||
cout << pop2[i] << " " << pop2[i].fitness() << endl;
|
||||
std::cout << pop2[i] << " " << pop2[i].fitness() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <time.h> // time
|
||||
#include <math.h> // fabs
|
||||
#include <iostream> // cout
|
||||
#include <iostream> // std::cout
|
||||
#include <eo> // eoVector, eoProblem
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -14,9 +14,9 @@ typedef eoVector<float, float> Chrom;
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ostream& operator<<(ostream& os, const Chrom& chrom)
|
||||
std::ostream& operator<<(std::ostream& os, const Chrom& chrom)
|
||||
{
|
||||
copy(chrom.begin(), chrom.end(), ostream_iterator<int>(os));
|
||||
copy(chrom.begin(), chrom.end(), std::ostream_iterator<int>(os));
|
||||
return os;
|
||||
}
|
||||
|
||||
|
|
@ -46,8 +46,8 @@ int main()
|
|||
chrom[0] = ((float)rand()) / ((float)RAND_MAX);
|
||||
chrom.fitness(easy(chrom));
|
||||
|
||||
cout << "chrom = " << chrom << endl
|
||||
<< "chrom.fitness() = " << chrom.fitness() << endl;
|
||||
std::cout << "chrom = " << chrom << std::endl
|
||||
<< "chrom.fitness() = " << chrom.fitness() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,24 +63,24 @@ main()
|
|||
}
|
||||
|
||||
// print population
|
||||
cout << "population:" << endl;
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
cout << pop[i] << " " << pop[i].fitness() << endl;
|
||||
std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// Declare 1-selectors
|
||||
eoUniformSelect<Chrom> uSelect;
|
||||
|
||||
Chrom aChrom;
|
||||
aChrom = uSelect( pop );
|
||||
cout << "Uniform Select " << aChrom << " " << aChrom.fitness() << endl;
|
||||
std::cout << "Uniform Select " << aChrom << " " << aChrom.fitness() << std::endl;
|
||||
|
||||
eoStochTournament<Chrom> sSelect(0.7);
|
||||
aChrom = sSelect( pop );
|
||||
cout << "Stochastic Tournament " << aChrom << " " << aChrom.fitness() << endl;
|
||||
std::cout << "Stochastic Tournament " << aChrom << " " << aChrom.fitness() << std::endl;
|
||||
|
||||
eoDetTournament<Chrom> dSelect(3);
|
||||
aChrom = dSelect( pop );
|
||||
cout << "Deterministic Tournament " << aChrom << " " << aChrom.fitness() << endl;
|
||||
std::cout << "Deterministic Tournament " << aChrom << " " << aChrom.fitness() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue