* whitespace cleanup
This commit is contained in:
parent
56c6edab04
commit
70e60a50d2
195 changed files with 1763 additions and 1873 deletions
|
|
@ -28,7 +28,7 @@ double binary_value (const Particle & _particle)
|
|||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _particle.size(); i++)
|
||||
sum +=_particle[i];
|
||||
sum +=_particle[i];
|
||||
return (sum);
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ void main_function(int argc, char **argv)
|
|||
// PARAMETRES
|
||||
// all parameters are hard-coded!
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
|
||||
|
||||
const unsigned int MAX_GEN=500;
|
||||
const unsigned int VEC_SIZE = 10;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
|
|
@ -47,10 +47,10 @@ void main_function(int argc, char **argv)
|
|||
|
||||
const double VELOCITY_INIT_MIN= -1;
|
||||
const double VELOCITY_INIT_MAX= 1;
|
||||
|
||||
|
||||
const double VELOCITY_MIN= -1.5;
|
||||
const double VELOCITY_MAX= 1.5;
|
||||
|
||||
|
||||
const double INERTIA= 1;
|
||||
const double LEARNING_FACTOR1= 1.7;
|
||||
const double LEARNING_FACTOR2= 2.3;
|
||||
|
|
@ -63,9 +63,9 @@ void main_function(int argc, char **argv)
|
|||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
||||
|
||||
/// SWARM
|
||||
// population <=> swarm
|
||||
// population <=> swarm
|
||||
eoPop<Particle> pop;
|
||||
|
||||
/// EVALUATION
|
||||
|
|
@ -78,8 +78,8 @@ void main_function(int argc, char **argv)
|
|||
//////////////
|
||||
// ring topology
|
||||
eoRingTopology<Particle> topology(NEIGHBORHOOD_SIZE);
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////
|
||||
// INITIALIZATION
|
||||
////////////////////
|
||||
|
|
@ -87,7 +87,7 @@ void main_function(int argc, char **argv)
|
|||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength < Particle > random (VEC_SIZE, uGen);
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
|
||||
// velocities initialization component
|
||||
eoUniformGenerator < double >sGen (VELOCITY_INIT_MIN, VELOCITY_INIT_MAX);
|
||||
eoVelocityInitFixedLength < Particle > veloRandom (VEC_SIZE, sGen);
|
||||
|
|
@ -101,23 +101,23 @@ void main_function(int argc, char **argv)
|
|||
// - the first best positions of each particle
|
||||
// - setups the topology
|
||||
eoInitializer <Particle> fullInit(eval,veloRandom,localInit,topology,pop);
|
||||
|
||||
|
||||
// Full initialization here to be able to print the initial population
|
||||
// Else: give the "init" component in the eoEasyPSO constructor
|
||||
fullInit();
|
||||
|
||||
|
||||
/////////////
|
||||
// OUTPUT
|
||||
////////////
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
|
||||
|
||||
// Print (sorted) the initial population (raw printout)
|
||||
cout << "INITIAL POPULATION:" << endl;
|
||||
for (unsigned i = 0; i < pop.size(); ++i)
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
|
||||
|
||||
|
||||
///////////////
|
||||
/// VELOCITY
|
||||
//////////////
|
||||
|
|
@ -148,7 +148,7 @@ void main_function(int argc, char **argv)
|
|||
////////////////////////////////////////
|
||||
// standard PSO requires
|
||||
// stopping criteria, evaluation,velocity, flight
|
||||
|
||||
|
||||
eoEasyPSO<Particle> pso(genCont, eval, velocity, flight);
|
||||
|
||||
// Apply the algo to the swarm - that's it!
|
||||
|
|
@ -159,7 +159,7 @@ void main_function(int argc, char **argv)
|
|||
pop.sort();
|
||||
cout << "FINAL POPULATION:" << endl;
|
||||
for (unsigned i = 0; i < pop.size(); ++i)
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -167,14 +167,14 @@ void main_function(int argc, char **argv)
|
|||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -8,21 +8,21 @@ INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
|||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
IF(NOT WIN32 OR CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
||||
ENDIF(NOT WIN32 OR CYGWIN)
|
||||
|
||||
# especially for Visual Studio
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
LINK_DIRECTORIES(${EO_BINARY_DIR}\\lib\\${CMAKE_BUILD_TYPE})
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
ENDIF(WIN32 AND NOT CYGWIN)
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(BinaryPSO BinaryPSO.cpp)
|
||||
ADD_EXECUTABLE(RealPSO RealPSO.cpp)
|
||||
ADD_EXECUTABLE(BinaryPSO BinaryPSO.cpp)
|
||||
ADD_EXECUTABLE(RealPSO RealPSO.cpp)
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal
|
||||
|
|
@ -49,4 +49,3 @@ INSTALL(TARGETS BinaryPSO RUNTIME DESTINATION share/eo/examples/Lesson6 COMPONEN
|
|||
INSTALL(TARGETS RealPSO RUNTIME DESTINATION share/eo/examples/Lesson6 COMPONENT examples)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### This Makefile is part of the tutorial of the EO library
|
||||
# Unlike other Makefiles in EO, it is not using the automake/autoconf
|
||||
# Unlike other Makefiles in EO, it is not using the automake/autoconf
|
||||
# so that it stays easy to understant (you are in the tutorial, remember!)
|
||||
# MS, Oct. 2002
|
||||
|
||||
|
|
@ -10,12 +10,12 @@ DIR_EO = ../../src
|
|||
.SUFFIXES: .cpp
|
||||
|
||||
# Warning: $(CXX) in Linux (RedHat and Mandrake at least) is g++
|
||||
# However, if you are using this Makefile within xemacs,
|
||||
# However, if you are using this Makefile within xemacs,
|
||||
# and have problems with the interpretation of the output (and its colors)
|
||||
# then you should use c++ instead (make CXX=c++ will do)
|
||||
|
||||
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -pg -o $@ $*.cpp
|
||||
#$(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -pg -o $@ $*.cpp
|
||||
#$(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
.cpp.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c -pg $*.cpp
|
||||
|
||||
|
|
@ -27,5 +27,5 @@ lesson6 : $(PSO)
|
|||
|
||||
all : $(ALL)
|
||||
|
||||
clean :
|
||||
clean :
|
||||
@/bin/rm $(ALL) *.o *.sav *.xg *.status *~
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ FitT real_value (const Particle & _particle)
|
|||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _particle.size(); i++)
|
||||
sum += pow(_particle[i],2);
|
||||
sum += pow(_particle[i],2);
|
||||
return (sqrt(sum));
|
||||
}
|
||||
|
||||
|
|
@ -38,21 +38,21 @@ void main_function(int argc, char **argv)
|
|||
// PARAMETRES
|
||||
// all parameters are hard-coded!
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
|
||||
|
||||
const unsigned int MAX_GEN=100;
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||
|
||||
|
||||
const double POS_INIT_MIN= -2;
|
||||
const double POS_INIT_MAX= 2;
|
||||
|
||||
|
||||
const double VELOCITY_INIT_MIN= -1;
|
||||
const double VELOCITY_INIT_MAX= 1;
|
||||
|
||||
|
||||
const double VELOCITY_MIN= -1.5;
|
||||
const double VELOCITY_MAX= 1.5;
|
||||
|
||||
|
||||
const double INERTIA= 1;
|
||||
const double LEARNING_FACTOR1= 1.7;
|
||||
const double LEARNING_FACTOR2= 2.3;
|
||||
|
|
@ -64,9 +64,9 @@ void main_function(int argc, char **argv)
|
|||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
||||
|
||||
/// SWARM
|
||||
// population <=> swarm
|
||||
// population <=> swarm
|
||||
eoPop<Particle> pop;
|
||||
|
||||
/// EVALUATION
|
||||
|
|
@ -79,8 +79,8 @@ void main_function(int argc, char **argv)
|
|||
//////////////
|
||||
// linear topology
|
||||
eoLinearTopology<Particle> topology(NEIGHBORHOOD_SIZE);
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////
|
||||
// INITIALIZATION
|
||||
////////////////////
|
||||
|
|
@ -88,7 +88,7 @@ void main_function(int argc, char **argv)
|
|||
eoUniformGenerator < double >uGen (POS_INIT_MIN, POS_INIT_MAX);
|
||||
eoInitFixedLength < Particle > random (VEC_SIZE, uGen);
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
|
||||
// velocities initialization component
|
||||
eoUniformGenerator < double >sGen (VELOCITY_INIT_MIN, VELOCITY_INIT_MAX);
|
||||
eoVelocityInitFixedLength < Particle > veloRandom (VEC_SIZE, sGen);
|
||||
|
|
@ -102,23 +102,23 @@ void main_function(int argc, char **argv)
|
|||
// - the first best positions of each particle
|
||||
// - setups the topology
|
||||
eoInitializer <Particle> fullInit(eval,veloRandom,localInit,topology,pop);
|
||||
|
||||
|
||||
// Full initialization here to be able to print the initial population
|
||||
// Else: give the "init" component in the eoEasyPSO constructor
|
||||
fullInit();
|
||||
|
||||
|
||||
/////////////
|
||||
// OUTPUT
|
||||
////////////
|
||||
// sort pop before printing it!
|
||||
pop.sort();
|
||||
|
||||
|
||||
// Print (sorted) the initial population (raw printout)
|
||||
cout << "INITIAL POPULATION:" << endl;
|
||||
for (unsigned i = 0; i < pop.size(); ++i)
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
|
||||
|
||||
|
||||
///////////////
|
||||
/// VELOCITY
|
||||
//////////////
|
||||
|
|
@ -149,7 +149,7 @@ void main_function(int argc, char **argv)
|
|||
////////////////////////////////////////
|
||||
// standard PSO requires
|
||||
// stopping criteria, evaluation,velocity, flight
|
||||
|
||||
|
||||
eoEasyPSO<Particle> pso(genCont, eval, velocity, flight);
|
||||
|
||||
// Apply the algo to the swarm - that's it!
|
||||
|
|
@ -160,7 +160,7 @@ void main_function(int argc, char **argv)
|
|||
pop.sort();
|
||||
cout << "FINAL POPULATION:" << endl;
|
||||
for (unsigned i = 0; i < pop.size(); ++i)
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
cout << "\t best fit=" << pop[i] << endl;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -168,14 +168,14 @@ void main_function(int argc, char **argv)
|
|||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
Reference in a new issue