Style for PEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@906 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2008-01-25 16:14:06 +00:00
commit b74a446baa
82 changed files with 1946 additions and 1663 deletions

View file

@ -78,7 +78,7 @@ int main (int __argc, char *__argv[])
eoCheckPoint<Indi> checkpoint(continuatorPara);
// For a parallel evaluation
peoEvalFunc<Indi> plainEval(f);
peoPopEval <Indi> eval(plainEval);
@ -95,26 +95,26 @@ int main (int __argc, char *__argv[])
eoSegmentCrossover<Indi> crossover; // Crossover
eoUniformMutation<Indi> mutation(EPSILON); // Mutation
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
// Replacement
eoPlusReplacement<Indi> replace;
// Creation of the population
eoPop < Indi > pop;
pop.append (POP_SIZE, random);
// Algorithm
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
//Parallel algorithm
peoWrapper parallelEA( eaAlg, pop);
eval.setOwner(parallelEA);
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
}

View file

@ -71,11 +71,11 @@ int main (int __argc, char *__argv[])
const double INIT_POSITION_MIN = -2.0; // For initialize x
const double INIT_POSITION_MAX = 2.0; // In the case of the Rosenbrock function : -2 < x[i] < 2
const double INIT_VELOCITY_MIN = -1.;
const double INIT_VELOCITY_MAX = 1.;
const double INIT_VELOCITY_MIN = -1.;
const double INIT_VELOCITY_MAX = 1.;
const double weight = 1;
const double C1 = 0.5;
const double C2 = 2.;
const double C1 = 0.5;
const double C2 = 2.;
rng.reseed (time(0));
// Stopping
@ -92,14 +92,14 @@ int main (int __argc, char *__argv[])
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
// Velocity
// Velocity
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
// Initializing the best
// Initializing the best
eoFirstIsBestInit < Indi > localInit;
// Flight
// Flight
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
eoStandardFlight < Indi > flight(bndsFlight);
@ -111,20 +111,20 @@ int main (int __argc, char *__argv[])
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
eoStandardVelocity < Indi > velocity (topology,weight,C1,C2,bnds);
// Initialization
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
//Parallel algorithm
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
peoWrapper parallelPSO( psa, pop);
eval.setOwner(parallelPSO);
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
}

View file

@ -52,14 +52,14 @@ int main (int __argc, char *__argv[])
{
peo :: init( __argc, __argv );
const unsigned int VEC_SIZE = 2;
const unsigned int POP_SIZE = 20;
const unsigned int MAX_GEN = 300;
const unsigned int VEC_SIZE = 2;
const unsigned int POP_SIZE = 20;
const unsigned int MAX_GEN = 300;
const double INIT_POSITION_MIN = -2.0;
const double INIT_POSITION_MAX = 2.0;
const float CROSS_RATE = 0.8;
const double EPSILON = 0.01;
const float MUT_RATE = 0.3;
const double INIT_POSITION_MAX = 2.0;
const float CROSS_RATE = 0.8;
const double EPSILON = 0.01;
const float MUT_RATE = 0.3;
rng.reseed (time(0));
eoGenContinue < Indi > genContPara (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara (genContPara);
@ -70,9 +70,9 @@ int main (int __argc, char *__argv[])
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
eoRankingSelect<Indi> selectionStrategy;
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
eoSegmentCrossover<Indi> crossover;
eoSegmentCrossover<Indi> crossover;
eoUniformMutation<Indi> mutation(EPSILON);
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
eoPlusReplacement<Indi> replace;
@ -81,14 +81,14 @@ int main (int __argc, char *__argv[])
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
peoWrapper parallelEA( eaAlg, pop);
eval.setOwner(parallelEA);
transform.setOwner (parallelEA);
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
}

View file

@ -71,7 +71,7 @@ int main (int __argc, char *__argv[])
// First algorithm
/*****************************************************************************************/
eoGenContinue < Indi > genContPara (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara (genContPara);
eoCheckPoint<Indi> checkpoint(continuatorPara);
@ -82,10 +82,10 @@ int main (int __argc, char *__argv[])
eoRankingSelect<Indi> selectionStrategy;
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
eoSegmentCrossover<Indi> crossover;
eoUniformMutation<Indi> mutation(EPSILON);
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
eoUniformMutation<Indi> mutation(EPSILON);
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
peoPop < Indi > pop;
pop.append (POP_SIZE, random);
pop.append (POP_SIZE, random);
eoPlusReplacement<Indi> replace;
eoRandomSelect<Indi> mig_select_one;
eoSelector <Indi, peoPop<Indi> > mig_select (mig_select_one,MIG_SIZE,pop);
@ -102,7 +102,7 @@ int main (int __argc, char *__argv[])
// Second algorithm (on the same model but with others names)
/*****************************************************************************************/
eoGenContinue < Indi > genContPara2 (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
@ -113,10 +113,10 @@ int main (int __argc, char *__argv[])
eoRankingSelect<Indi> selectionStrategy2;
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
eoSegmentCrossover<Indi> crossover2;
eoUniformMutation<Indi> mutation2(EPSILON);
peoTransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
eoUniformMutation<Indi> mutation2(EPSILON);
peoTransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
peoPop < Indi > pop2;
pop2.append (POP_SIZE, random2);
pop2.append (POP_SIZE, random2);
eoPlusReplacement<Indi> replace2;
eoRandomSelect<Indi> mig_select_one2;
eoSelector <Indi, peoPop<Indi> > mig_select2 (mig_select_one2,MIG_SIZE,pop2);

View file

@ -50,24 +50,24 @@ double f (const Indi & _indi)
int main (int __argc, char *__argv[])
{
peo :: init( __argc, __argv );
const unsigned int VEC_SIZE = 2;
const unsigned int POP_SIZE = 20;
const unsigned int VEC_SIZE = 2;
const unsigned int POP_SIZE = 20;
const unsigned int NEIGHBORHOOD_SIZE= 6;
const unsigned int MAX_GEN = 100;
const unsigned int MAX_GEN = 100;
const double INIT_POSITION_MIN = -2.0;
const double INIT_POSITION_MAX = 2.0;
const double INIT_POSITION_MAX = 2.0;
const double INIT_VELOCITY_MIN = -1.;
const double INIT_VELOCITY_MAX = 1.;
const unsigned int MIG_FREQ = 10;
const double omega = 1;
const double C1 = 0.5;
const double C2 = 2.;
const double C2 = 2.;
rng.reseed (time(0));
// Island model
RingTopology topologyMig;
// First
eoGenContinue < Indi > genContPara (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara (genContPara);
@ -93,9 +93,9 @@ int main (int __argc, char *__argv[])
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
peoPSOSelect<Indi> mig_selec(topology);
peoWorstPositionReplacement<Indi> mig_replac;
// Specific implementation (peoData.h)
// Specific implementation (peoData.h)
eoContinuator<Indi> cont(mig_cont, pop);
eoSelector <Indi, peoPop<Indi> > mig_select (mig_selec,1,pop);
eoReplace <Indi, peoPop<Indi> > mig_replace (mig_replac,pop);
@ -121,7 +121,7 @@ int main (int __argc, char *__argv[])
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
eoStandardVelocity < Indi > velocity2 (topology2,omega,C1,C2,bnds2);
eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2);
// Island model
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
@ -133,15 +133,15 @@ int main (int __argc, char *__argv[])
eoContinuator<Indi> cont2(mig_cont2,pop2);
eoSelector <Indi, peoPop<Indi> > mig_select2 (mig_selec2,1,pop2);
eoReplace <Indi, peoPop<Indi> > mig_replace2 (mig_replac2,pop2);
// Island model
peoAsyncIslandMig< Indi, peoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig, pop, pop);
checkpoint.add( mig );
peoAsyncIslandMig< Indi, peoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2);
checkpoint2.add( mig2 );
// Parallel algorithm
@ -156,10 +156,10 @@ int main (int __argc, char *__argv[])
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
pop2.sort();
std::cout << "Final population :\n" << pop << std::endl;
std::cout << "Final population :\n" << pop2 << std::endl;
}
{
pop.sort();
pop2.sort();
std::cout << "Final population :\n" << pop << std::endl;
std::cout << "Final population :\n" << pop2 << std::endl;
}
}

View file

@ -59,13 +59,13 @@ int main (int __argc, char * * __argv)
{
peo :: init (__argc, __argv);
loadParameters (__argc, __argv);
loadParameters (__argc, __argv);
RouteInit route_init;
RouteEval full_eval;
OrderXover order_cross;
OrderXover order_cross;
PartialMappedXover pm_cross;
EdgeXover edge_cross;
CitySwap city_swap_mut;
CitySwap city_swap_mut;
// Initialization of the local search
TwoOptInit pmx_two_opt_init;
@ -76,7 +76,7 @@ int main (int __argc, char * * __argv)
// EA
eoPop <Route> pop (POP_SIZE, route_init);
eoGenContinue <Route> cont (NUM_GEN);
eoGenContinue <Route> cont (NUM_GEN);
eoCheckPoint <Route> checkpoint (cont);
eoEvalFuncCounter< Route > eval(full_eval);
eoStochTournamentSelect <Route> select_one;
@ -86,16 +86,16 @@ int main (int __argc, char * * __argv)
eoEasyEA< Route > eaAlg( checkpoint, eval, select, transform, replace );
peoWrapper parallelEA( eaAlg, pop);
peo :: run ();
peo :: finalize ();
peo :: finalize ();
if (getNodeRank()==1)
{
pop.sort();
std :: cout << "\nResult before the local search\n";
for(unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
}
{
pop.sort();
std :: cout << "\nResult before the local search\n";
for (unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
}
// Local search
peo :: init (__argc, __argv);
peoMultiStart <Route> initParallelHC (hc);
@ -105,10 +105,10 @@ int main (int __argc, char * * __argv)
peo :: finalize( );
if (getNodeRank()==1)
{
std :: cout << "\nResult after the local search\n";
pop.sort();
for(unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
}
{
std :: cout << "\nResult after the local search\n";
pop.sort();
for (unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
}
}

View file

@ -58,13 +58,13 @@ int main (int __argc, char * * __argv)
{
peo :: init (__argc, __argv);
loadParameters (__argc, __argv);
loadParameters (__argc, __argv);
RouteInit route_init;
RouteEval full_eval;
OrderXover order_cross;
OrderXover order_cross;
PartialMappedXover pm_cross;
EdgeXover edge_cross;
CitySwap city_swap_mut;
CitySwap city_swap_mut;
// Local search
TwoOptInit pmx_two_opt_init;
@ -80,17 +80,17 @@ int main (int __argc, char * * __argv)
peo :: finalize( );
if (getNodeRank()==1)
{
std :: cout << "\nResult before the EA\n";
pop.sort();
for(unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
std :: cout << "\n\n";
}
{
std :: cout << "\nResult before the EA\n";
pop.sort();
for (unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
std :: cout << "\n\n";
}
// EA
peo :: init (__argc, __argv);
eoGenContinue <Route> cont (NUM_GEN);
eoGenContinue <Route> cont (NUM_GEN);
eoCheckPoint <Route> checkpoint (cont);
eoEvalFuncCounter< Route > eval(full_eval);
eoStochTournamentSelect <Route> select_one;
@ -100,14 +100,14 @@ int main (int __argc, char * * __argv)
eoEasyEA< Route > eaAlg( checkpoint, eval, select, transform, replace );
peoWrapper parallelEA( eaAlg, pop);
peo :: run ();
peo :: finalize ();
peo :: finalize ();
if (getNodeRank()==1)
{
std :: cout << "\nResult after the EA\n";
pop.sort();
for(unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
std :: cout << "\n\n";
}
{
std :: cout << "\nResult after the EA\n";
pop.sort();
for (unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
std :: cout << "\n\n";
}
}

View file

@ -50,39 +50,40 @@ double f (const Indi & _indi)
template <class EOT>
class eoResizerInit: public eoInit<EOT>
{
public:
{
public:
typedef typename EOT::AtomType AtomType;
eoResizerInit(unsigned _size)
: size(_size){}
eoResizerInit(unsigned _size)
: size(_size)
{}
virtual void operator()(EOT& chrom)
{
chrom.resize(size);
chrom.invalidate();
}
private :
unsigned size;
};
virtual void operator()(EOT& chrom)
{
chrom.resize(size);
chrom.invalidate();
}
private :
unsigned size;
};
int main( int __argc, char** __argv )
{
peo :: init( __argc, __argv );
const unsigned int VEC_SIZE = 2;
const unsigned int POP_SIZE = 20;
const unsigned int VEC_SIZE = 2;
const unsigned int POP_SIZE = 20;
const unsigned int NEIGHBORHOOD_SIZE= 6;
const unsigned int MAX_GEN = 300;
const unsigned int MAX_GEN = 300;
const double INIT_POSITION_MIN = -2.0;
const double INIT_POSITION_MAX = 2.0;
const double INIT_POSITION_MAX = 2.0;
const double INIT_VELOCITY_MIN = -1.;
const double INIT_VELOCITY_MAX = 1.;
const double omega = 1;
const double omega = 1;
const double C1 = 0.5;
const double C2 = 2.;
const double C2 = 2.;
rng.reseed (time(0));
eoGenContinue < Indi > genContPara (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara (genContPara);
@ -96,7 +97,7 @@ int main( int __argc, char** __argv )
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
eoStandardVelocity < Indi > velocity (topology,omega,C1,C2,bnds);
eoResizerInit<Indi> sizeInit(VEC_SIZE);
// need at least a size initialization
eoPop < Indi > pop(POP_SIZE,sizeInit);
@ -105,7 +106,7 @@ int main( int __argc, char** __argv )
peoWrapper random (initRandom,pop);
initRandom.setOwner(random);
peo :: run( );
peo :: finalize( );
peo :: finalize( );
// Parallel algorithm
@ -119,8 +120,8 @@ int main( int __argc, char** __argv )
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
}

View file

@ -44,24 +44,24 @@
int main(int argc, char* argv[])
{
peo :: init( argc,argv );
eoParser parser(argc, argv);
eoState state;
peoMoeoPopEval<FlowShop>& eval = do_make_para_eval(parser, state);
eoInit<FlowShop>& init = do_make_genotype(parser, state);
eoGenOp<FlowShop>& op = do_make_op(parser, state);
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
moeoArchive<FlowShop> arch;
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
peoWrapper parallelMOEO( algo, pop);
eval.setOwner(parallelMOEO);
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
peo :: init( argc,argv );
eoParser parser(argc, argv);
eoState state;
peoMoeoPopEval<FlowShop>& eval = do_make_para_eval(parser, state);
eoInit<FlowShop>& init = do_make_genotype(parser, state);
eoGenOp<FlowShop>& op = do_make_op(parser, state);
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
moeoArchive<FlowShop> arch;
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
peoWrapper parallelMOEO( algo, pop);
eval.setOwner(parallelMOEO);
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
}
}

View file

@ -88,13 +88,13 @@ eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eo
}
// maxEval
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
/* if (maxEvalParam.value())
{
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
_state.storeFunctor(evalCont);
// and "add" to combined
continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
}*/
/* if (maxEvalParam.value())
{
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
_state.storeFunctor(evalCont);
// and "add" to combined
continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
}*/
// maxTime
eoValueParam<unsigned long>& maxTimeParam = _parser.getORcreateParam((unsigned long)(0), "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion");
if (maxTimeParam.value()) // positive: -> define and store

View file

@ -71,7 +71,7 @@ static int screen;
/*
gdk_gc_set_line_attributes (gc, 2, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER) ;
gdk_gc_set_foreground (gc, & color_green) ;
gdk_gc_set_foreground (gc, & color_green) ;
for (int i = 0 ; i < (int) numNodes ; i ++) {
@ -80,7 +80,7 @@ for (int i = 0 ; i < (int) numNodes ; i ++) {
Y_new_coord [opt_route [i]],
X_new_coord [opt_route [(i + 1) % numNodes]],
Y_new_coord [opt_route [(i + 1) % numNodes]]);
}*/
void openMainWindow (const char * __filename)

View file

@ -40,7 +40,6 @@
DisplayBestRoute :: DisplayBestRoute (eoPop <Route> & __pop
) : pop (__pop)
{
}
void DisplayBestRoute :: operator () ()

View file

@ -41,8 +41,7 @@ PartRouteEval :: PartRouteEval (float __from,
float __to
) : from (__from),
to (__to)
{
}
{}
void PartRouteEval :: operator () (Route & __route)
{