* New tree configuration of the project:

.../
   ...           + -- EO
   |             |
   |             |
   +-- src ----- + -- EDO
   |             |
   |             |
   +-- test      + -- MO
   |             |
   |             |
   +-- tutorial  + -- MOEO
   |             |
   |             |
   +-- doc       + -- SMP
   |             |
   |             |
   ...           + -- EOMPI
                 |
                 |
                 + -- EOSERIAL

Question for current maintainers: ./README: new release?

Also:

* Moving out eompi & eoserial modules (issue #2).

* Correction of the errors when executing "make doc" command.

* Adding a solution for the conflicting headers problem (see the two CMake Cache
 Values: PROJECT_TAG & PROJECT_HRS_INSTALL_SUBPATH) (issue #1)

* Header inclusions:
        ** src: changing absolute paths into relative paths ('#include <...>' -> '#include "..."')
        ** test, tutorial: changing relative paths into absolute paths ('#include "..."' -> '#include <...>')

* Moving out some scripts from EDO -> to the root

* Add a new script for compilation and installation (see build_gcc_linux_install)

* Compilation with uBLAS library or EDO module: now ok

* Minor modifications on README & INSTALL files

* Comment eompi failed tests with no end

*** TODO: CPack (debian (DEB) & RedHat (RPM) packages) (issues #6 & #7) ***
This commit is contained in:
Adèle Harrissart 2014-08-04 13:40:28 +02:00
commit 490e837f7a
2359 changed files with 7688 additions and 16329 deletions

182
tutorial/eo/Lesson6/BinaryPSO.cpp Executable file
View file

@ -0,0 +1,182 @@
//-----------------------------------------------------------------------------
// BinaryPSO.cpp
//-----------------------------------------------------------------------------
//*
// An instance of a VERY simple Real-coded binary Particle Swarm Optimization Algorithm
//
//-----------------------------------------------------------------------------
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <paradiseo/eo.h>
// Use functions from namespace std
using namespace std;
//-----------------------------------------------------------------------------
typedef eoMinimizingFitness FitT;
typedef eoBitParticle < FitT > Particle;
//-----------------------------------------------------------------------------
// EVALFUNC
//-----------------------------------------------------------------------------
// Just a simple function that takes binary value of a chromosome and sets
// the fitness
double binary_value (const Particle & _particle)
{
double sum = 0;
for (unsigned i = 0; i < _particle.size(); i++)
sum +=_particle[i];
return (sum);
}
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;
const unsigned int NEIGHBORHOOD_SIZE= 3;
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;
//////////////////////////
// RANDOM SEED
//////////////////////////
//reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run
rng.reseed(SEED);
/// SWARM
// population <=> swarm
eoPop<Particle> pop;
/// EVALUATION
// Evaluation: from a plain C++ fn to an EvalFunc Object
eoEvalFuncPtr<Particle, double, const Particle& > eval( binary_value );
///////////////
/// TOPOLOGY
//////////////
// ring topology
eoRingTopology<Particle> topology(NEIGHBORHOOD_SIZE);
/////////////////////
// INITIALIZATION
////////////////////
// position initialization
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);
// first best position initialization component
eoFirstIsBestInit < Particle > localInit;
// Create an eoInitialier that:
// - performs a first evaluation of the particles
// - initializes the velocities
// - 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;
///////////////
/// VELOCITY
//////////////
// Create the bounds for the velocity not go to far away
eoRealVectorBounds bnds(VEC_SIZE,VELOCITY_MIN,VELOCITY_MAX);
// the velocity itself that needs the topology and a few constants
eoStandardVelocity <Particle> velocity (topology,INERTIA,LEARNING_FACTOR1,LEARNING_FACTOR2,bnds);
///////////////
/// FLIGHT
//////////////
// Binary flight based on sigmoid function
eoSigBinaryFlight <Particle> flight;
////////////////////////
/// STOPPING CRITERIA
///////////////////////
// the algo will run for MAX_GEN iterations
eoGenContinue <Particle> genCont (MAX_GEN);
// GENERATION
/////////////////////////////////////////
// the algorithm
////////////////////////////////////////
// standard PSO requires
// stopping criteria, evaluation,velocity, flight
eoEasyPSO<Particle> pso(genCont, eval, velocity, flight);
// Apply the algo to the swarm - that's it!
pso(pop);
// OUTPUT
// Print (sorted) intial population
pop.sort();
cout << "FINAL POPULATION:" << endl;
for (unsigned i = 0; i < pop.size(); ++i)
cout << "\t best fit=" << pop[i] << endl;
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try
{
main_function(argc, argv);
}
catch(exception& e)
{
cout << "Exception: " << e.what() << '\n';
}
return 1;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,51 @@
######################################################################################
### 1) Include the sources
######################################################################################
#include_directories(${EO_SRC_DIR}/src)
######################################################################################
### 2) Specify where CMake can find the libraries
######################################################################################
if(NOT WIN32 OR CYGWIN)
link_directories(${EO_BIN_DIR}/lib)
endif(NOT WIN32 OR CYGWIN)
# especially for Visual Studio
if(WIN32 AND NOT CYGWIN)
link_directories(${EO_BIN_DIR}\\lib\\${CMAKE_BUILD_TYPE})
endif(WIN32 AND NOT CYGWIN)
######################################################################################
### 3) Define your targets
######################################################################################
add_executable(BinaryPSO BinaryPSO.cpp)
add_executable(RealPSO RealPSO.cpp)
######################################################################################
### 4) Optionnal
######################################################################################
set(BINARYPSO_VERSION ${GLOBAL_VERSION})
set_target_properties(BinaryPSO PROPERTIES VERSION "${BINARYPSO_VERSION}")
set(REALPSO_VERSION ${GLOBAL_VERSION})
set_target_properties(RealPSO PROPERTIES VERSION "${REALPSO_VERSION}")
######################################################################################
### 5) Link the librairies for the targets
######################################################################################
target_link_libraries(BinaryPSO eo eoutils)
target_link_libraries(RealPSO eo eoutils)
######################################################################################
### 6) Configure project installation paths
######################################################################################
install(TARGETS BinaryPSO RUNTIME DESTINATION share/${PROJECT_TAG}/eo/examples/Lesson6 COMPONENT examples)
install(TARGETS RealPSO RUNTIME DESTINATION share/${PROJECT_TAG}/eo/examples/Lesson6 COMPONENT examples)
######################################################################################

View file

@ -0,0 +1,31 @@
### This Makefile is part of the tutorial of the EO library
# 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
# if you use this Makefile as a starting point for another application
# you might need to modify the following
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,
# 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.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c -pg $*.cpp
PSO = BinaryPSO RealPSO
ALL = $(PSO)
lesson6 : $(PSO)
all : $(ALL)
clean :
@/bin/rm $(ALL) *.o *.sav *.xg *.status *~

183
tutorial/eo/Lesson6/RealPSO.cpp Executable file
View file

@ -0,0 +1,183 @@
//-----------------------------------------------------------------------------
// RealPSO.cpp
//-----------------------------------------------------------------------------
//*
// An instance of a VERY simple Real-coded Particle Swarm Optimization Algorithm
//
//-----------------------------------------------------------------------------
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <paradiseo/eo.h>
// Use functions from namespace std
using namespace std;
//-----------------------------------------------------------------------------
typedef eoMinimizingFitness FitT;
typedef eoRealParticle < FitT > Particle;
//-----------------------------------------------------------------------------
// EVALFUNC
//-----------------------------------------------------------------------------
// a simple fitness function that computes the euclidian norm of a real vector
FitT real_value (const Particle & _particle)
{
double sum = 0;
for (unsigned i = 0; i < _particle.size(); i++)
sum += pow(_particle[i],2);
return (sqrt(sum));
}
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;
//////////////////////////
// RANDOM SEED
//////////////////////////
//reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run
rng.reseed(SEED);
/// SWARM
// population <=> swarm
eoPop<Particle> pop;
/// EVALUATION
// Evaluation: from a plain C++ fn to an EvalFunc Object
eoEvalFuncPtr<Particle, FitT, const Particle& > eval( real_value );
///////////////
/// TOPOLOGY
//////////////
// linear topology
eoLinearTopology<Particle> topology(NEIGHBORHOOD_SIZE);
/////////////////////
// INITIALIZATION
////////////////////
// position initialization
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);
// first best position initialization component
eoFirstIsBestInit < Particle > localInit;
// Create an eoInitialier that:
// - performs a first evaluation of the particles
// - initializes the velocities
// - 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;
///////////////
/// VELOCITY
//////////////
// Create the bounds for the velocity not go to far away
eoRealVectorBounds bnds(VEC_SIZE,VELOCITY_MIN,VELOCITY_MAX);
// the velocity itself that needs the topology and a few constants
eoStandardVelocity <Particle> velocity (topology,INERTIA,LEARNING_FACTOR1,LEARNING_FACTOR2,bnds);
///////////////
/// FLIGHT
//////////////
// flight
eoStandardFlight <Particle> flight;
////////////////////////
/// STOPPING CRITERIA
///////////////////////
// the algo will run for MAX_GEN iterations
eoGenContinue <Particle> genCont (MAX_GEN);
// GENERATION
/////////////////////////////////////////
// the algorithm
////////////////////////////////////////
// standard PSO requires
// stopping criteria, evaluation,velocity, flight
eoEasyPSO<Particle> pso(genCont, eval, velocity, flight);
// Apply the algo to the swarm - that's it!
pso(pop);
// OUTPUT
// Print (sorted) intial population
pop.sort();
cout << "FINAL POPULATION:" << endl;
for (unsigned i = 0; i < pop.size(); ++i)
cout << "\t best fit=" << pop[i] << endl;
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try
{
main_function(argc, argv);
}
catch(exception& e)
{
cout << "Exception: " << e.what() << '\n';
}
return 1;
}
//-----------------------------------------------------------------------------