Adjust code to perform to C++ standard according to gcc-3.4
interpretation... (Have not compiled/checked/changed paradisEO.) That is, the current code compiles with gcc-3.4 and the checks (besides t-MGE1bit) all pass.
This commit is contained in:
parent
faaadf7599
commit
85a326c5e4
35 changed files with 1057 additions and 864 deletions
|
|
@ -29,25 +29,25 @@ int main()
|
|||
unsigned i;
|
||||
eoBooleanGenerator gen;
|
||||
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Evaluation
|
||||
RoyalRoad<Chrom> rr( 8 );
|
||||
RoyalRoad<Chrom> rr( 8 );
|
||||
eoEvalFuncCounter<Chrom> eval( rr );
|
||||
|
||||
eoInitVirus1bit<float> random(CHROM_SIZE, gen);
|
||||
eoInitVirus1bit<float> random(CHROM_SIZE, gen);
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
Chrom chrom;
|
||||
random(chrom);
|
||||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
||||
|
|
@ -62,14 +62,14 @@ int main()
|
|||
propSel.add(vf, 0.05);
|
||||
propSel.add(vt, 0.05);
|
||||
propSel.add(xover, 0.1);
|
||||
|
||||
|
||||
// Replace a single one
|
||||
eoCommaReplacement<Chrom> replace;
|
||||
|
||||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
|
|
@ -83,22 +83,26 @@ int main()
|
|||
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace);
|
||||
|
||||
// evolution
|
||||
try
|
||||
{
|
||||
try {
|
||||
ea(pop);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
// c-file-style: "Stroustrup"
|
||||
// End:
|
||||
|
|
|
|||
|
|
@ -79,17 +79,27 @@ class Init : public eoInit<eoDouble>
|
|||
}
|
||||
};
|
||||
|
||||
// Trying out an elitist non-dominated sorted replacement scheme
|
||||
/** @brief An elitist non-dominated sorted replacement scheme.
|
||||
|
||||
Trying out an elitist non-dominated sorted replacement scheme.
|
||||
*/
|
||||
template <class EOT, class WorthT = double>
|
||||
class eoNDPlusReplacement : public eoReplacement<EOT>
|
||||
{
|
||||
public:
|
||||
eoNDPlusReplacement(eoPerf2Worth<EOT, WorthT>& _perf2worth) : perf2worth(_perf2worth) {}
|
||||
|
||||
struct WorthPair : public pair<WorthT, const EOT*>
|
||||
{
|
||||
bool operator<(const WorthPair& other) const { return other.first < first; }
|
||||
};
|
||||
// using eoNDPlusReplacement< EOT, WorthT >::first;
|
||||
|
||||
eoNDPlusReplacement(eoPerf2Worth<EOT, WorthT>& _perf2worth)
|
||||
: perf2worth(_perf2worth)
|
||||
{}
|
||||
|
||||
struct WorthPair : public pair<WorthT, const EOT*>
|
||||
{
|
||||
bool operator<(const WorthPair& other) const
|
||||
{ return other.first < this->first; }
|
||||
};
|
||||
|
||||
|
||||
void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
|
||||
{
|
||||
|
|
@ -106,7 +116,7 @@ public:
|
|||
}
|
||||
|
||||
private :
|
||||
eoPerf2Worth<EOT, WorthT>& perf2worth;
|
||||
eoPerf2Worth<EOT, WorthT>& perf2worth;
|
||||
};
|
||||
|
||||
template <class EOT>
|
||||
|
|
@ -232,3 +242,9 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
// c-file-style: "Stroustrup"
|
||||
// End:
|
||||
|
|
|
|||
Reference in a new issue