added t-eoEasyPSO test
This commit is contained in:
parent
12dacbe7de
commit
967b6b7741
3 changed files with 117 additions and 7 deletions
|
|
@ -1,10 +1,10 @@
|
|||
2006-12-04 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
2006-12-04 Jochen Kpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* Makefile.am: Add t-eoRNG
|
||||
|
||||
* t-eoRNG.cpp: Start test for random number generator.
|
||||
|
||||
2006-12-02 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
2006-12-02 Jochen Kpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* t-MGE1bit.cpp: Change float to double.
|
||||
|
||||
|
|
@ -14,8 +14,14 @@
|
|||
|
||||
* test/t-eoSymreg.cpp (SymregNode::operator()): Initialize r1 and r2 to
|
||||
avoid compiler warnings.
|
||||
|
||||
|
||||
2006-07-02 Thomas Legrand <thomas.legrand@lifl.fr>
|
||||
|
||||
|
||||
* test/t-eoEasyPSO.cpp: add PSO test
|
||||
|
||||
* test/Makefile.am: add PSO test
|
||||
|
||||
* Local Variables:
|
||||
* coding: iso-8859-1
|
||||
* mode: flyspell
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ check_PROGRAMS = t-eoParetoFitness \
|
|||
t-eoRoulette \
|
||||
t-eoSharing \
|
||||
t-eoCMAES \
|
||||
t-eoRNG
|
||||
|
||||
|
||||
t-eoRNG \
|
||||
t-eoEasyPSO
|
||||
|
||||
TESTS = $(check_PROGRAMS) \
|
||||
run_tests # This script can be used to check command-line arguments
|
||||
|
||||
|
|
@ -93,3 +93,4 @@ t_eoRoulette_SOURCES = t-eoRoulette.cpp
|
|||
t_eoSharing_SOURCES = t-eoSharing.cpp
|
||||
t_eoCMAES_SOURCES = t-eoCMAES.cpp
|
||||
t_eoRNG_SOURCES = t-eoRNG.cpp
|
||||
t_eoEasyPSO_SOURCES = t-eoEasyPSO.cpp
|
||||
103
eo/test/t-eoEasyPSO.cpp
Normal file
103
eo/test/t-eoEasyPSO.cpp
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eoEasyPSO.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <eo>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoMinimizingFitness FitT;
|
||||
typedef eoRealParticle < FitT > Particle;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// the objective function
|
||||
double real_value (const Particle & _particle)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _particle.size ()-1; i++)
|
||||
sum += pow(_particle[i],2);
|
||||
return (sum);
|
||||
}
|
||||
|
||||
|
||||
main()
|
||||
{
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||
unsigned i;
|
||||
|
||||
// the population:
|
||||
eoPop<Particle> pop;
|
||||
|
||||
// Evaluation
|
||||
eoEvalFuncPtr<Particle, double, const Particle& > eval( real_value );
|
||||
|
||||
// position init
|
||||
eoUniformGenerator < double >uGen (-3, 3);
|
||||
eoInitFixedLength < Particle > random (VEC_SIZE, uGen);
|
||||
|
||||
// velocity init
|
||||
eoUniformGenerator < double >sGen (-2, 2);
|
||||
eoVelocityInitFixedLength < Particle > veloRandom (VEC_SIZE, sGen);
|
||||
|
||||
// local best init
|
||||
eoFirstIsBestInit < Particle > localInit;
|
||||
|
||||
|
||||
// perform 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);
|
||||
|
||||
// bounds
|
||||
eoRealVectorBounds bnds(VEC_SIZE,-1.5,1.5);
|
||||
|
||||
// velocity
|
||||
eoStandardVelocity <Particle> velocity (topology,1.6,2,bnds);
|
||||
|
||||
// flight
|
||||
eoStandardFlight <Particle> flight;
|
||||
|
||||
// Terminators
|
||||
eoGenContinue <Particle> genCont (50);
|
||||
|
||||
|
||||
// PS flight
|
||||
eoEasyPSO<Particle> pso(genCont, eval, velocity, flight);
|
||||
|
||||
|
||||
// flight
|
||||
try
|
||||
{
|
||||
pso(pop);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "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;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Reference in a new issue