Added new lesson (6) dedicated to the PSO. Also changed a few things into the PSO-dedicated components (constructors)

This commit is contained in:
tlegrand 2008-03-04 14:01:29 +00:00
commit 4ad79a9148
17 changed files with 771 additions and 115 deletions

View file

@ -48,23 +48,17 @@ int main()
// local best init
eoFirstIsBestInit < Particle > localInit;
// perform initialization
// perform position initialization
pop.append (POP_SIZE, random);
apply < Particle > (eval, pop);
apply < Particle > (veloRandom, pop);
apply < Particle > (localInit, pop);
std::cout << "population:" << std::endl;
for (i = 0; i < pop.size(); ++i)
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
// topology
eoLinearTopology<Particle> topology(NEIGHBORHOOD_SIZE);
topology.setup(pop);
// the full initializer
eoInitializer <Particle> init(eval,veloRandom,localInit,topology,pop);
init();
// bounds
eoRealVectorBounds bnds(VEC_SIZE,-1.5,1.5);
@ -75,19 +69,26 @@ int main()
eoStandardFlight <Particle> flight;
// Terminators
eoGenContinue <Particle> genCont (50);
// the full initializer
eoInitializer <Particle> init(eval,veloRandom,localInit,topology,pop);
eoGenContinue <Particle> genCont1 (50);
eoGenContinue <Particle> genCont2 (50);
// PS flight
eoEasyPSO<Particle> pso(init,genCont, eval, velocity, flight);
eoEasyPSO<Particle> pso1(genCont1, eval, velocity, flight);
eoEasyPSO<Particle> pso2(init,genCont2, eval, velocity, flight);
// flight
try
{
pso(pop);
pso1(pop);
std::cout << "FINAL POPULATION AFTER PSO n°1:" << std::endl;
for (i = 0; i < pop.size(); ++i)
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
pso2(pop);
std::cout << "FINAL POPULATION AFTER PSO n°2:" << std::endl;
for (i = 0; i < pop.size(); ++i)
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
}
catch (std::exception& e)
{
@ -95,9 +96,7 @@ int main()
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;
return 0;
}