*** empty log message ***
This commit is contained in:
parent
aec83a0014
commit
6afc695dce
9 changed files with 315 additions and 0 deletions
88
eo/tutorial/ParadisEO/Lesson1/IslandBitEA1.cpp
Normal file
88
eo/tutorial/ParadisEO/Lesson1/IslandBitEA1.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#include <paradiseo>
|
||||
#include <ga.h>
|
||||
|
||||
typedef eoBit <double> Indi; // A bitstring with fitness double
|
||||
|
||||
#include "binary_value.h"
|
||||
|
||||
void main_function(int argc, char ** argv) {
|
||||
|
||||
// Some parameters ...
|
||||
const unsigned int T_SIZE = 3 ; // Size for tournament selection
|
||||
const unsigned int VEC_SIZE = 50 ; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 100 ; // Size of population
|
||||
|
||||
const unsigned int MAX_GEN = 1000 ; // Fixed number of generations
|
||||
|
||||
const double P_CROSS = 0.8 ; // Crossover probability
|
||||
const double P_MUT = 1.0 ; // Mutation probability
|
||||
|
||||
const double P_MUT_PER_BIT = 0.01 ; // Internal probability for bit-flip mutation
|
||||
const double onePointRate = 0.5 ; // Rate for 1-pt Xover
|
||||
const double bitFlipRate = 0.5 ; // Rate for bit-flip mutation
|
||||
|
||||
eoEvalFuncPtr <Indi, double, const vector <bool> & > eval (binary_value) ;
|
||||
eoUniformGenerator <bool> uGen ;
|
||||
eoInitFixedLength <Indi> random (VEC_SIZE, uGen) ;
|
||||
|
||||
eoPop <Indi> pop (POP_SIZE, random) ;
|
||||
|
||||
apply <Indi> (eval, pop) ; // A first evaluation of the population
|
||||
|
||||
eoDetTournamentSelect <Indi> selectOne(T_SIZE) ;
|
||||
eoSelectPerc <Indi> select (selectOne) ; // The selection operator
|
||||
|
||||
eoGenerationalReplacement<Indi> replace ; // The replacement operator
|
||||
|
||||
eo1PtBitXover <Indi> xover1 ;
|
||||
eoPropCombinedQuadOp <Indi> xover (xover1, onePointRate) ;
|
||||
eoBitMutation <Indi> mutationBitFlip (P_MUT_PER_BIT) ;
|
||||
eoPropCombinedMonOp <Indi> mutation (mutationBitFlip, bitFlipRate) ;
|
||||
|
||||
eoSGATransform <Indi> transform (xover, P_CROSS, mutation, P_MUT) ;
|
||||
|
||||
eoGenContinue<Indi> genCont (MAX_GEN) ; // The continuation criteria
|
||||
|
||||
// First evolutionnary algorithm
|
||||
eoEasyEA <Indi> gga (genCont, eval, select, transform, replace) ;
|
||||
|
||||
// What's new ?
|
||||
eoListener <Indi> listen (argc, argv) ;
|
||||
rng.reseed (listen.here ().number ()) ;
|
||||
|
||||
vector <string> v ;
|
||||
v.push_back ("Mars1") ;
|
||||
v.push_back ("Mars2") ;
|
||||
eoRingConnectivity <Indi> conn (listen, v) ; // The ring topology used
|
||||
|
||||
eoCyclicGenContinue <Indi> cycl_cont (300) ; // Immigration step all 300 evolutions
|
||||
eoRandomSelect <Indi> sel_rand ; // Random selection of emigrants
|
||||
eoSelectMany <Indi> sel (sel_rand, 0.1) ; /* How many individuals should be selected
|
||||
to be sent ? */
|
||||
eoPlusReplacement <Indi> repl ; // How to integrate new individuals ?
|
||||
// A island esay evolutionnary named "Mars"
|
||||
eoIslandsEasyEA <Indi> islgga ("Mars1", listen, conn, gga, cycl_cont, sel, repl) ;
|
||||
islgga (pop) ;
|
||||
pop.sort () ;
|
||||
cout << "The final population is now ..." << endl ;
|
||||
cout << pop << endl ;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
#ifdef _MSC_VER
|
||||
|
||||
int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
|
||||
flag |= _CRTDBG_LEAK_CHECK_DF;
|
||||
_CrtSetDbgFlag(flag);
|
||||
|
||||
#endif
|
||||
|
||||
try {
|
||||
main_function(argc, argv) ;
|
||||
}
|
||||
catch(exception& e) {
|
||||
cout << "Exception: " << e.what () << '\n' ;
|
||||
}
|
||||
|
||||
return 1 ;
|
||||
}
|
||||
96
eo/tutorial/ParadisEO/Lesson1/IslandBitEA2.cpp
Normal file
96
eo/tutorial/ParadisEO/Lesson1/IslandBitEA2.cpp
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#include <paradiseo>
|
||||
#include <ga.h>
|
||||
|
||||
typedef eoBit <double> Indi; // A bitstring with fitness double
|
||||
|
||||
#include "binary_value.h"
|
||||
|
||||
void main_function(int argc, char ** argv) {
|
||||
|
||||
// Some parameters ...
|
||||
const unsigned int T_SIZE = 3 ; // Size for tournament selection
|
||||
const unsigned int VEC_SIZE = 50 ; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 100 ; // Size of population
|
||||
|
||||
const unsigned int MAX_GEN = 1000 ; // Fixed number of generations
|
||||
|
||||
const double P_CROSS = 0.8 ; // Crossover probability
|
||||
const double P_MUT = 1.0 ; // Mutation probability
|
||||
|
||||
const double P_MUT_PER_BIT = 0.01 ; // Internal probability for bit-flip mutation
|
||||
//const double onePointRate = 0.5 ; // Rate for 1-pt Xover
|
||||
const double URate = 0.5 ; // Rate for Uniform Xover
|
||||
//const double bitFlipRate = 0.5 ; // Rate for bit-flip mutation
|
||||
const double oneBitRate = 0.5 ; // Rate for one-bit mutation
|
||||
|
||||
eoEvalFuncPtr <Indi, double, const vector <bool> & > eval (binary_value) ;
|
||||
eoUniformGenerator <bool> uGen ;
|
||||
eoInitFixedLength <Indi> random (VEC_SIZE, uGen) ;
|
||||
|
||||
eoPop <Indi> pop (POP_SIZE, random) ;
|
||||
|
||||
apply <Indi> (eval, pop) ; // A first evaluation of the population
|
||||
|
||||
eoDetTournamentSelect <Indi> selectOne(T_SIZE) ;
|
||||
eoSelectPerc <Indi> select (selectOne) ; // The selection operator
|
||||
|
||||
eoGenerationalReplacement<Indi> replace ; // The replacement operator
|
||||
|
||||
// Uniform crossover for bitstring
|
||||
eoUBitXover<Indi> xoverU ;
|
||||
eoPropCombinedQuadOp <Indi> xover (xoverU, URate) ;
|
||||
|
||||
// eoBitMutation <Indi> mutationBitFlip (P_MUT_PER_BIT) ;
|
||||
|
||||
eoDetBitFlip<Indi> mutationOneBit ;
|
||||
|
||||
eoPropCombinedMonOp <Indi> mutation (mutationOneBit, oneBitRate) ;
|
||||
|
||||
eoSGATransform <Indi> transform (xover, P_CROSS, mutation, P_MUT) ;
|
||||
|
||||
eoGenContinue<Indi> genCont (MAX_GEN) ; // The continuation criteria
|
||||
|
||||
// First evolutionnary algorithm
|
||||
eoEasyEA <Indi> gga (genCont, eval, select, transform, replace) ;
|
||||
|
||||
// What's new ?
|
||||
eoListener <Indi> listen (argc, argv) ;
|
||||
rng.reseed (listen.here ().number ()) ;
|
||||
|
||||
vector <string> v ;
|
||||
v.push_back ("Mars1") ;
|
||||
v.push_back ("Mars2") ; // Algos named "Mars1" or "Mars2" are considered ...
|
||||
|
||||
eoRingConnectivity <Indi> conn (listen, v) ; // The ring topology used
|
||||
|
||||
eoCyclicGenContinue <Indi> cycl_cont (300) ; // Immigration step all 300 evolutions
|
||||
eoRandomSelect <Indi> sel_rand ; // Random selection of emigrants
|
||||
eoSelectMany <Indi> sel (sel_rand, 0.1) ; /* How many individuals should be selected
|
||||
to be sent ? */
|
||||
eoPlusReplacement <Indi> repl ; // How to integrate new individuals ?
|
||||
// A island esay evolutionnary named "Mars2"
|
||||
eoIslandsEasyEA <Indi> islgga ("Mars2", listen, conn, gga, cycl_cont, sel, repl) ;
|
||||
islgga (pop) ;
|
||||
pop.sort () ;
|
||||
cout << "The final population is now ..." << endl ;
|
||||
cout << pop << endl ;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
#ifdef _MSC_VER
|
||||
|
||||
int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
|
||||
flag |= _CRTDBG_LEAK_CHECK_DF;
|
||||
_CrtSetDbgFlag(flag);
|
||||
|
||||
#endif
|
||||
|
||||
try {
|
||||
main_function(argc, argv) ;
|
||||
}
|
||||
catch(exception& e) {
|
||||
cout << "Exception: " << e.what () << '\n' ;
|
||||
}
|
||||
|
||||
return 1 ;
|
||||
}
|
||||
27
eo/tutorial/ParadisEO/Lesson1/Makefile
Normal file
27
eo/tutorial/ParadisEO/Lesson1/Makefile
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
ALL = IslandBitEA IslandBitEA2 IslandBitEA1
|
||||
|
||||
lesson2 : IslandBitEA IslandBitEA2 IslandBitEA1
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
clean :
|
||||
@/bin/rm $(ALL) *.o *~
|
||||
|
||||
IslandBitEA : IslandBitEA.o
|
||||
mpiCC -DPACKAGE=\"eo\" -o IslandBitEA IslandBitEA.o ../../../src/utils/libeoutils.a ../../../src/libeo.a
|
||||
|
||||
IslandBitEA.o : IslandBitEA.cpp binary_value.h
|
||||
mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c IslandBitEA.cpp
|
||||
|
||||
IslandBitEA1 : IslandBitEA1.o
|
||||
mpiCC -DPACKAGE=\"eo\" -o IslandBitEA1 IslandBitEA1.o ../../../src/utils/libeoutils.a ../../../src/libeo.a
|
||||
|
||||
IslandBitEA1.o : IslandBitEA1.cpp binary_value.h
|
||||
mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c IslandBitEA1.cpp
|
||||
|
||||
IslandBitEA2 : IslandBitEA2.o
|
||||
mpiCC -DPACKAGE=\"eo\" -o IslandBitEA2 IslandBitEA2.o ../../../src/utils/libeoutils.a ../../../src/libeo.a
|
||||
|
||||
IslandBitEA2.o : IslandBitEA2.cpp binary_value.h
|
||||
mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c IslandBitEA2.cpp
|
||||
|
||||
17
eo/tutorial/ParadisEO/Lesson1/binary_value.h
Normal file
17
eo/tutorial/ParadisEO/Lesson1/binary_value.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <eo>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Just a simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
// INIT
|
||||
double binary_value(const vector<bool>& _chrom)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _chrom.size(); i++)
|
||||
sum += _chrom[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
4
eo/tutorial/ParadisEO/Lesson1/paradiseo.config
Normal file
4
eo/tutorial/ParadisEO/Lesson1/paradiseo.config
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
127.0.0.1 0 ${HOME}/eo/tutorial/ParadisEO/Lesson1/IslandBitEA1
|
||||
127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson1/IslandBitEA1
|
||||
127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson1/IslandBitEA2
|
||||
127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson1/IslandBitEA2
|
||||
21
eo/tutorial/ParadisEO/Lesson2/Makefile
Normal file
21
eo/tutorial/ParadisEO/Lesson2/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
ALL = MasterDistEvalBitEA SlaveDistEvalBitEA
|
||||
|
||||
lesson2 : MasterDistEvalBitEA SlaveDistEvalBitEA
|
||||
|
||||
all : $(ALL)
|
||||
|
||||
clean :
|
||||
@/bin/rm $(ALL) *.o *~
|
||||
|
||||
MasterDistEvalBitEA : MasterDistEvalBitEA.o
|
||||
mpiCC -DPACKAGE=\"eo\" -o MasterDistEvalBitEA MasterDistEvalBitEA.o ../../../src/utils/libeoutils.a ../../../src/libeo.a
|
||||
|
||||
MasterDistEvalBitEA.o : MasterDistEvalBitEA.cpp binary_value.h
|
||||
mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c MasterDistEvalBitEA.cpp
|
||||
|
||||
SlaveDistEvalBitEA : SlaveDistEvalBitEA.o
|
||||
mpiCC -DPACKAGE=\"eo\" -o SlaveDistEvalBitEA SlaveDistEvalBitEA.o ../../../src/utils/libeoutils.a ../../../src/libeo.a
|
||||
|
||||
SlaveDistEvalBitEA.o : SlaveDistEvalBitEA.cpp binary_value.h
|
||||
mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c SlaveDistEvalBitEA.cpp
|
||||
|
||||
41
eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA.cpp
Normal file
41
eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
|
||||
#include <paradiseo>
|
||||
#include <ga.h>
|
||||
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
#include "binary_value.h"
|
||||
|
||||
void main_function(int argc, char **argv) {
|
||||
|
||||
eoEvalFuncPtr <Indi, double, const vector <bool> & > eval (binary_value) ;
|
||||
|
||||
eoListener <Indi> listen (argc, argv) ;
|
||||
|
||||
eoEvaluator <Indi> evaluator ("Mars",
|
||||
listen,
|
||||
eval) ;
|
||||
|
||||
// Runs
|
||||
evaluator () ;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
17
eo/tutorial/ParadisEO/Lesson2/binary_value.h
Normal file
17
eo/tutorial/ParadisEO/Lesson2/binary_value.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <eo>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Just a simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
// INIT
|
||||
double binary_value(const vector<bool>& _chrom)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _chrom.size(); i++)
|
||||
sum += _chrom[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
4
eo/tutorial/ParadisEO/Lesson2/paradiseo.config
Normal file
4
eo/tutorial/ParadisEO/Lesson2/paradiseo.config
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
127.0.0.1 0 ${HOME}/eo/tutorial/ParadisEO/Lesson2/MasterDistEvalBitEA
|
||||
127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA
|
||||
127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA
|
||||
127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA
|
||||
Loading…
Add table
Add a link
Reference in a new issue