New style for PEO
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@789 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
39709d3d12
commit
9c87b3b0c0
132 changed files with 3781 additions and 3396 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, INRIA, 2007
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <peo>
|
||||
|
|
@ -42,15 +42,15 @@ typedef eoReal<double> Indi;
|
|||
//Evaluation function
|
||||
|
||||
double f (const Indi & _indi)
|
||||
{
|
||||
// Rosenbrock function f(x) = 100*(x[1]-x[0]^2)^2+(1-x[0])^2
|
||||
// => optimal : f* = 0 , with x* =(1,1)
|
||||
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
{
|
||||
// Rosenbrock function f(x) = 100*(x[1]-x[0]^2)^2+(1-x[0])^2
|
||||
// => optimal : f* = 0 , with x* =(1,1)
|
||||
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
}
|
||||
|
||||
int main (int __argc, char *__argv[])
|
||||
|
|
@ -58,68 +58,68 @@ int main (int __argc, char *__argv[])
|
|||
|
||||
|
||||
// Initialization of the parallel environment : thanks this instruction, ParadisEO-PEO can initialize himself
|
||||
peo :: init( __argc, __argv );
|
||||
peo :: init( __argc, __argv );
|
||||
|
||||
//Parameters
|
||||
|
||||
const unsigned int VEC_SIZE = 2; // Don't change this parameter when you are resolving the Rosenbrock function
|
||||
const unsigned int POP_SIZE = 20; // As with a sequential algorithm, you change the size of the population
|
||||
const unsigned int MAX_GEN = 300; // Define the number of maximal generation
|
||||
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 float CROSS_RATE = 0.8; // Crossover rate
|
||||
const double EPSILON = 0.01; // Range for real uniform mutation
|
||||
const float MUT_RATE = 0.3; // Mutation rate
|
||||
rng.reseed (time(0));
|
||||
|
||||
const unsigned int VEC_SIZE = 2; // Don't change this parameter when you are resolving the Rosenbrock function
|
||||
const unsigned int POP_SIZE = 20; // As with a sequential algorithm, you change the size of the population
|
||||
const unsigned int MAX_GEN = 300; // Define the number of maximal generation
|
||||
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 float CROSS_RATE = 0.8; // Crossover rate
|
||||
const double EPSILON = 0.01; // Range for real uniform mutation
|
||||
const float MUT_RATE = 0.3; // Mutation rate
|
||||
rng.reseed (time(0));
|
||||
|
||||
// Stopping
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
|
||||
|
||||
/* In this lesson, you should define a peoEvalFunc witch will allow to initialize :
|
||||
*
|
||||
* - peoSeqPopEval : using to the sequential evaluation
|
||||
*
|
||||
* OR
|
||||
*
|
||||
* - peoParaPopEval : using to the parallel evaluation
|
||||
*
|
||||
*/
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
|
||||
|
||||
/* In this lesson, you should define a peoEvalFunc witch will allow to initialize :
|
||||
*
|
||||
* - peoSeqPopEval : using to the sequential evaluation
|
||||
*
|
||||
* OR
|
||||
*
|
||||
* - peoParaPopEval : using to the parallel evaluation
|
||||
*
|
||||
*/
|
||||
|
||||
// For a parallel evaluation
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoParaPopEval< Indi > eval(plainEval);
|
||||
|
||||
|
||||
// Initialization
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoParaPopEval< Indi > eval(plainEval);
|
||||
|
||||
|
||||
// Initialization
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
|
||||
// Selection
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
|
||||
// Transformation
|
||||
eoSegmentCrossover<Indi> crossover; // Crossover
|
||||
eoUniformMutation<Indi> mutation(EPSILON); // Mutation
|
||||
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
peoSeqTransform<Indi> eaTransform(transform);
|
||||
|
||||
eoSegmentCrossover<Indi> crossover; // Crossover
|
||||
eoUniformMutation<Indi> mutation(EPSILON); // Mutation
|
||||
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
peoSeqTransform<Indi> eaTransform(transform);
|
||||
|
||||
// Replacement
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
// Creation of the population
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
//Parallel algorithm
|
||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||
Algo(pop);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if(getNodeRank()==1)
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||
Algo(pop);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, INRIA, 2007
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <peo>
|
||||
|
|
@ -41,15 +41,15 @@ typedef eoRealParticle < double >Indi;
|
|||
//Evaluation function
|
||||
|
||||
double f (const Indi & _indi)
|
||||
{
|
||||
// Rosenbrock function f(x) = 100*(x[1]-x[0]^2)^2+(1-x[0])^2
|
||||
// => optimal : f* = 0 , with x* =(1,1)
|
||||
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
{
|
||||
// Rosenbrock function f(x) = 100*(x[1]-x[0]^2)^2+(1-x[0])^2
|
||||
// => optimal : f* = 0 , with x* =(1,1)
|
||||
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
}
|
||||
|
||||
int main (int __argc, char *__argv[])
|
||||
|
|
@ -57,86 +57,86 @@ int main (int __argc, char *__argv[])
|
|||
|
||||
|
||||
// Initialization of the parallel environment : thanks this instruction, ParadisEO-PEO can initialize himself
|
||||
peo :: init( __argc, __argv );
|
||||
peo :: init( __argc, __argv );
|
||||
|
||||
//Parameters
|
||||
|
||||
const unsigned int VEC_SIZE = 2; // Don't change this parameter when you are resolving the Rosenbrock function
|
||||
|
||||
const unsigned int POP_SIZE = 20; // As with a sequential algorithm, you change the size of the population
|
||||
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 6; // This parameter define the neighborhoods in the PSO's topology
|
||||
|
||||
const unsigned int MAX_GEN = 150; // Define the number of maximal generation
|
||||
|
||||
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.; // For initialize PSO's velocity
|
||||
const double INIT_VELOCITY_MAX = 1.; // ie Lesson 6 of ParadisEO-EO
|
||||
|
||||
const double C1 = 0.5; // For calculate the velocity
|
||||
const double C2 = 2.; // ie Lesson 6 of ParadisEO-EO
|
||||
rng.reseed (time(0));
|
||||
|
||||
const unsigned int VEC_SIZE = 2; // Don't change this parameter when you are resolving the Rosenbrock function
|
||||
|
||||
const unsigned int POP_SIZE = 20; // As with a sequential algorithm, you change the size of the population
|
||||
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 6; // This parameter define the neighborhoods in the PSO's topology
|
||||
|
||||
const unsigned int MAX_GEN = 150; // Define the number of maximal generation
|
||||
|
||||
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.; // For initialize PSO's velocity
|
||||
const double INIT_VELOCITY_MAX = 1.; // ie Lesson 6 of ParadisEO-EO
|
||||
|
||||
const double C1 = 0.5; // For calculate the velocity
|
||||
const double C2 = 2.; // ie Lesson 6 of ParadisEO-EO
|
||||
rng.reseed (time(0));
|
||||
|
||||
// Stopping
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
|
||||
|
||||
|
||||
|
||||
/* In this lesson, you should define a peoEvalFuncPSO witch will allow to initialize :
|
||||
*
|
||||
* - peoSeqPopEval : using to the sequential evaluation
|
||||
*
|
||||
* OR
|
||||
*
|
||||
* - peoParaPopEval : using to the parallel evaluation
|
||||
*
|
||||
*/
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
|
||||
|
||||
|
||||
|
||||
/* In this lesson, you should define a peoEvalFuncPSO witch will allow to initialize :
|
||||
*
|
||||
* - peoSeqPopEval : using to the sequential evaluation
|
||||
*
|
||||
* OR
|
||||
*
|
||||
* - peoParaPopEval : using to the parallel evaluation
|
||||
*
|
||||
*/
|
||||
|
||||
// For a parallel evaluation
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||
peoParaPopEval< Indi > eval(plainEval);
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||
peoParaPopEval< Indi > eval(plainEval);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Initialization
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
|
||||
// Velocity (ie Lesson 6 of ParadisEO-PEO)
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
|
||||
// Initializing the best (ie Lesson 6 of ParadisEO-PEO)
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
|
||||
// Flight (ie Lesson 6 of ParadisEO-PEO)
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
|
||||
// Creation of the population
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
// Initialization
|
||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
|
||||
// Velocity (ie Lesson 6 of ParadisEO-PEO)
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
|
||||
// Initializing the best (ie Lesson 6 of ParadisEO-PEO)
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
|
||||
// Flight (ie Lesson 6 of ParadisEO-PEO)
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
|
||||
// Creation of the population
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
// Initialization
|
||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||
|
||||
// Topology (ie Lesson 6 of ParadisEO-PEO)
|
||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||
|
||||
//Parallel algorithm
|
||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||
psa(pop);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if(getNodeRank()==1)
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||
psa(pop);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, INRIA, 2007
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <peo>
|
||||
|
|
@ -40,66 +40,66 @@
|
|||
typedef eoReal<double> Indi;
|
||||
|
||||
double f (const Indi & _indi)
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
}
|
||||
|
||||
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 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;
|
||||
rng.reseed (time(0));
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
|
||||
/******************************************************************************************/
|
||||
|
||||
/* In this lesson, you can choose between :
|
||||
*
|
||||
* - A sequential transformation (crossover + mutation) : eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
* peoSeqTransform<Indi> eaTransform(transform);
|
||||
*
|
||||
* OR
|
||||
*
|
||||
* - A parallel transformation (crossover + mutation) : peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
*
|
||||
* Unfortunately, if you don't use a crossover which creates two children with two parents,
|
||||
* you can't use this operator.
|
||||
* In this case, you should send a mail to : paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
|
||||
/******************************************************************************************/
|
||||
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||
Algo(pop);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if(getNodeRank()==1)
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
peo :: init( __argc, __argv );
|
||||
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;
|
||||
rng.reseed (time(0));
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
|
||||
/******************************************************************************************/
|
||||
|
||||
/* In this lesson, you can choose between :
|
||||
*
|
||||
* - A sequential transformation (crossover + mutation) : eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
* peoSeqTransform<Indi> eaTransform(transform);
|
||||
*
|
||||
* OR
|
||||
*
|
||||
* - A parallel transformation (crossover + mutation) : peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
*
|
||||
* Unfortunately, if you don't use a crossover which creates two children with two parents,
|
||||
* you can't use this operator.
|
||||
* In this case, you should send a mail to : paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
|
||||
/******************************************************************************************/
|
||||
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||
Algo(pop);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, INRIA, 2007
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <peo>
|
||||
|
|
@ -40,109 +40,109 @@
|
|||
typedef eoReal<double> Indi;
|
||||
|
||||
double f (const Indi & _indi)
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
}
|
||||
|
||||
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 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;
|
||||
// MIG_FREQ define the frequency of the migration.
|
||||
const unsigned int MIG_FREQ = 10;
|
||||
// MIG_SIZE define the size of each migration.
|
||||
const unsigned int MIG_SIZE = 5;
|
||||
rng.reseed (time(0));
|
||||
|
||||
// Define the topology of your island model
|
||||
RingTopology topology;
|
||||
|
||||
// First algorithm
|
||||
/*****************************************************************************************/
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
peoSeqTransform<Indi> eaTransform(transform); // Here, the transformation is sequential
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
eoPeriodicContinue <Indi> mig_cont( MIG_FREQ ); // Migration occurs periodically
|
||||
eoRandomSelect<Indi> mig_select_one; // Emigrants are randomly selected
|
||||
eoSelectNumber<Indi> mig_select (mig_select_one,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace; // Immigrants replace the worse individuals
|
||||
peo :: init( __argc, __argv );
|
||||
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;
|
||||
// MIG_FREQ define the frequency of the migration.
|
||||
const unsigned int MIG_FREQ = 10;
|
||||
// MIG_SIZE define the size of each migration.
|
||||
const unsigned int MIG_SIZE = 5;
|
||||
rng.reseed (time(0));
|
||||
|
||||
/*****************************************************************************************/
|
||||
// Define the topology of your island model
|
||||
RingTopology topology;
|
||||
|
||||
// Second algorithm (on the same model but with others names)
|
||||
/*****************************************************************************************/
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||
peoEvalFunc<Indi> plainEval2(f);
|
||||
peoSeqPopEval< Indi > eval2(plainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoRankingSelect<Indi> selectionStrategy2;
|
||||
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover2;
|
||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||
eoSGATransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||
peoSeqTransform<Indi> eaTransform2(transform2);
|
||||
eoPlusReplacement<Indi> replace2;
|
||||
eoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
eoPeriodicContinue <Indi> mig_cont2( MIG_FREQ );
|
||||
eoRandomSelect<Indi> mig_select_one2;
|
||||
eoSelectNumber<Indi> mig_select2 (mig_select_one2,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace2;
|
||||
// First algorithm
|
||||
/*****************************************************************************************/
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
peoSeqTransform<Indi> eaTransform(transform); // Here, the transformation is sequential
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
/*****************************************************************************************/
|
||||
eoPeriodicContinue <Indi> mig_cont( MIG_FREQ ); // Migration occurs periodically
|
||||
eoRandomSelect<Indi> mig_select_one; // Emigrants are randomly selected
|
||||
eoSelectNumber<Indi> mig_select (mig_select_one,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace; // Immigrants replace the worse individuals
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
// Second algorithm (on the same model but with others names)
|
||||
/*****************************************************************************************/
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||
peoEvalFunc<Indi> plainEval2(f);
|
||||
peoSeqPopEval< Indi > eval2(plainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoRankingSelect<Indi> selectionStrategy2;
|
||||
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover2;
|
||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||
eoSGATransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||
peoSeqTransform<Indi> eaTransform2(transform2);
|
||||
eoPlusReplacement<Indi> replace2;
|
||||
eoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
eoPeriodicContinue <Indi> mig_cont2( MIG_FREQ );
|
||||
eoRandomSelect<Indi> mig_select_one2;
|
||||
eoSelectNumber<Indi> mig_select2 (mig_select_one2,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace2;
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
// You can choose between :
|
||||
//
|
||||
// - Synchronous communication : peoSyncIslandMig<Indi> mig(MIG_FREQ,mig_select,mig_replace,topology,pop,pop);
|
||||
// - Asynchronous communication : peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop);
|
||||
// With a grid, you should use an asynchronous communication
|
||||
peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop2);
|
||||
checkpoint.add(mig);
|
||||
peoAsyncIslandMig<Indi> mig2(mig_cont2,mig_select2,mig_replace2,topology,pop2,pop);
|
||||
checkpoint2.add(mig2);
|
||||
|
||||
// Initialization of the algorithms
|
||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||
mig.setOwner(Algo);
|
||||
Algo(pop);
|
||||
peoEA<Indi> Algo2(checkpoint2,eval2,select2,eaTransform2,replace2);
|
||||
mig2.setOwner(Algo2);
|
||||
Algo2(pop2);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if(getNodeRank()==1)
|
||||
peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop2);
|
||||
checkpoint.add(mig);
|
||||
peoAsyncIslandMig<Indi> mig2(mig_cont2,mig_select2,mig_replace2,topology,pop2,pop);
|
||||
checkpoint2.add(mig2);
|
||||
|
||||
// Initialization of the algorithms
|
||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||
mig.setOwner(Algo);
|
||||
Algo(pop);
|
||||
peoEA<Indi> Algo2(checkpoint2,eval2,select2,eaTransform2,replace2);
|
||||
mig2.setOwner(Algo2);
|
||||
Algo2(pop2);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std::cout << "Final population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
||||
std::cout << "Final population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, INRIA, 2007
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <peo>
|
||||
|
|
@ -39,114 +39,114 @@
|
|||
typedef eoRealParticle < double >Indi;
|
||||
|
||||
double f (const Indi & _indi)
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
}
|
||||
|
||||
int main (int __argc, char *__argv[])
|
||||
{
|
||||
|
||||
// In this lesson, we define two algorithms of the PSO witch represents two islands.
|
||||
// Obviously, you can define more algorithms.
|
||||
|
||||
// The parameters are common between the two algorithms.
|
||||
/*****************************************************************************************/
|
||||
peo :: init( __argc, __argv );
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||
const unsigned int MAX_GEN = 150;
|
||||
const double INIT_POSITION_MIN = -2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const double INIT_VELOCITY_MIN = -1.;
|
||||
const double INIT_VELOCITY_MAX = 1.;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2.;
|
||||
// C3 is used for the calculation of one of the strategies of the island model.
|
||||
const double C3 = 2.;
|
||||
// MIG_FREQ define the frequency of the migration.
|
||||
const unsigned int MIG_FREQ = 10; // The optimal value is 1 or 2 for the component peoPSOVelocity.
|
||||
rng.reseed (time(0));
|
||||
/*****************************************************************************************/
|
||||
|
||||
// Define the topology of your island model
|
||||
RingTopology topologyMig;
|
||||
|
||||
// First algorithm
|
||||
/*****************************************************************************************/
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential !
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint(genContPara);
|
||||
// Specific implementation for the island model
|
||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec(topology);
|
||||
eoSelectNumber< Indi > mig_select(mig_selec);
|
||||
// If you want to use a replacement stategy : peoPSOReplacement<Indi> mig_replace;
|
||||
// If you want to use a consideration of the migration in the calculation of the velocity : peoPSOVelocity<Indi> mig_replace(C3,velocity);
|
||||
peoPSOReplacement<Indi> mig_replace;
|
||||
/*****************************************************************************************/
|
||||
|
||||
// Second algorithm (on the same model but with others names)
|
||||
/*****************************************************************************************/
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
||||
peoSeqPopEval< Indi > eval2(plainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
||||
eoFirstIsBestInit < Indi > localInit2;
|
||||
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight2(bndsFlight2);
|
||||
eoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
peoInitializer <Indi> init2(eval2,veloRandom2,localInit2,pop2);
|
||||
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
||||
peoPSOReplacement<Indi> mig_replace2;
|
||||
/*****************************************************************************************/
|
||||
// Obviously, you can define more algorithms.
|
||||
|
||||
// Define the communication between the islands
|
||||
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop);
|
||||
checkpoint.add( mig );
|
||||
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop2);
|
||||
checkpoint2.add( mig2 );
|
||||
// Initialization of the algorithms
|
||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||
mig.setOwner( psa );
|
||||
psa(pop);
|
||||
peoPSO < Indi > psa2(init2,checkpoint2, eval2, velocity2, flight2);
|
||||
mig2.setOwner( psa2 );
|
||||
psa2(pop2);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if(getNodeRank()==1)
|
||||
// The parameters are common between the two algorithms.
|
||||
/*****************************************************************************************/
|
||||
peo :: init( __argc, __argv );
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||
const unsigned int MAX_GEN = 150;
|
||||
const double INIT_POSITION_MIN = -2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const double INIT_VELOCITY_MIN = -1.;
|
||||
const double INIT_VELOCITY_MAX = 1.;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2.;
|
||||
// C3 is used for the calculation of one of the strategies of the island model.
|
||||
const double C3 = 2.;
|
||||
// MIG_FREQ define the frequency of the migration.
|
||||
const unsigned int MIG_FREQ = 10; // The optimal value is 1 or 2 for the component peoPSOVelocity.
|
||||
rng.reseed (time(0));
|
||||
/*****************************************************************************************/
|
||||
|
||||
// Define the topology of your island model
|
||||
RingTopology topologyMig;
|
||||
|
||||
// First algorithm
|
||||
/*****************************************************************************************/
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential !
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint(genContPara);
|
||||
// Specific implementation for the island model
|
||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec(topology);
|
||||
eoSelectNumber< Indi > mig_select(mig_selec);
|
||||
// If you want to use a replacement stategy : peoPSOReplacement<Indi> mig_replace;
|
||||
// If you want to use a consideration of the migration in the calculation of the velocity : peoPSOVelocity<Indi> mig_replace(C3,velocity);
|
||||
peoPSOReplacement<Indi> mig_replace;
|
||||
/*****************************************************************************************/
|
||||
|
||||
// Second algorithm (on the same model but with others names)
|
||||
/*****************************************************************************************/
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
||||
peoSeqPopEval< Indi > eval2(plainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
||||
eoFirstIsBestInit < Indi > localInit2;
|
||||
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight2(bndsFlight2);
|
||||
eoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
peoInitializer <Indi> init2(eval2,veloRandom2,localInit2,pop2);
|
||||
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
||||
peoPSOReplacement<Indi> mig_replace2;
|
||||
/*****************************************************************************************/
|
||||
|
||||
// Define the communication between the islands
|
||||
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop);
|
||||
checkpoint.add( mig );
|
||||
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop2);
|
||||
checkpoint2.add( mig2 );
|
||||
// Initialization of the algorithms
|
||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||
mig.setOwner( psa );
|
||||
psa(pop);
|
||||
peoPSO < Indi > psa2(init2,checkpoint2, eval2, velocity2, flight2);
|
||||
mig2.setOwner( psa2 );
|
||||
psa2(pop2);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std::cout << "Population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Population 2 :\n" << pop2 << std::endl;
|
||||
std::cout << "Population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Population 2 :\n" << pop2 << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, INRIA, 2007
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <peo>
|
||||
|
|
@ -40,12 +40,12 @@
|
|||
typedef eoReal<double> Indi;
|
||||
|
||||
double f (const Indi & _indi)
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
}
|
||||
|
||||
int main (int __argc, char *__argv[])
|
||||
|
|
@ -55,98 +55,98 @@ int main (int __argc, char *__argv[])
|
|||
// The evaluation is parallel.
|
||||
// The transformation is parallel.
|
||||
|
||||
peo :: init( __argc, __argv );
|
||||
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 unsigned int MIG_FREQ = 10;
|
||||
const unsigned int MIG_SIZE = 5;
|
||||
rng.reseed (time(0));
|
||||
RingTopology topology;
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoParaPopEval< Indi > eval(plainEval);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
eoPeriodicContinue <Indi> mig_cont( MIG_FREQ );
|
||||
eoRandomSelect<Indi> mig_select_one;
|
||||
eoSelectNumber<Indi> mig_select (mig_select_one,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace;
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||
peoEvalFunc<Indi> plainEval2(f);
|
||||
peoParaPopEval< Indi > eval2(plainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoRankingSelect<Indi> selectionStrategy2;
|
||||
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover2;
|
||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||
peoParaSGATransform <Indi> eaTransform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||
eoPlusReplacement<Indi> replace2;
|
||||
eoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
eoPeriodicContinue <Indi> mig_cont2( MIG_FREQ );
|
||||
eoRandomSelect<Indi> mig_select_one2;
|
||||
eoSelectNumber<Indi> mig_select2 (mig_select_one2,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace2;
|
||||
eoGenContinue < Indi > genContPara3 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara3 (genContPara3);
|
||||
eoCheckPoint<Indi> checkpoint3(continuatorPara3);
|
||||
peoEvalFunc<Indi> plainEval3(f);
|
||||
peoParaPopEval< Indi > eval3(plainEval3);
|
||||
eoUniformGenerator < double >uGen3 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random3 (VEC_SIZE, uGen3);
|
||||
eoRankingSelect<Indi> selectionStrategy3;
|
||||
eoSelectNumber<Indi> select3(selectionStrategy3,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover3;
|
||||
eoUniformMutation<Indi> mutation3(EPSILON);
|
||||
peoParaSGATransform <Indi> eaTransform3(crossover3,CROSS_RATE,mutation3,MUT_RATE);
|
||||
eoPlusReplacement<Indi> replace3;
|
||||
eoPop < Indi > pop3;
|
||||
pop3.append (POP_SIZE, random3);
|
||||
eoPeriodicContinue <Indi> mig_cont3( MIG_FREQ );
|
||||
eoRandomSelect<Indi> mig_select_one3;
|
||||
eoSelectNumber<Indi> mig_select3 (mig_select_one3,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace3;
|
||||
peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop2);
|
||||
checkpoint.add(mig);
|
||||
peoAsyncIslandMig<Indi> mig2(mig_cont2,mig_select2,mig_replace2,topology,pop2,pop);
|
||||
checkpoint2.add(mig2);
|
||||
peoAsyncIslandMig<Indi> mig3(mig_cont3,mig_select3,mig_replace3,topology,pop3,pop);
|
||||
checkpoint3.add(mig3);
|
||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||
mig.setOwner(Algo);
|
||||
Algo(pop);
|
||||
peoEA<Indi> Algo2(checkpoint2,eval2,select2,eaTransform2,replace2);
|
||||
mig2.setOwner(Algo2);
|
||||
Algo2(pop2);
|
||||
peoEA<Indi> Algo3(checkpoint3,eval3,select3,eaTransform3,replace3);
|
||||
mig3.setOwner(Algo3);
|
||||
Algo3(pop3);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if(getNodeRank()==1)
|
||||
peo :: init( __argc, __argv );
|
||||
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 unsigned int MIG_FREQ = 10;
|
||||
const unsigned int MIG_SIZE = 5;
|
||||
rng.reseed (time(0));
|
||||
RingTopology topology;
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoParaPopEval< Indi > eval(plainEval);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
eoPeriodicContinue <Indi> mig_cont( MIG_FREQ );
|
||||
eoRandomSelect<Indi> mig_select_one;
|
||||
eoSelectNumber<Indi> mig_select (mig_select_one,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace;
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||
peoEvalFunc<Indi> plainEval2(f);
|
||||
peoParaPopEval< Indi > eval2(plainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoRankingSelect<Indi> selectionStrategy2;
|
||||
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover2;
|
||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||
peoParaSGATransform <Indi> eaTransform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||
eoPlusReplacement<Indi> replace2;
|
||||
eoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
eoPeriodicContinue <Indi> mig_cont2( MIG_FREQ );
|
||||
eoRandomSelect<Indi> mig_select_one2;
|
||||
eoSelectNumber<Indi> mig_select2 (mig_select_one2,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace2;
|
||||
eoGenContinue < Indi > genContPara3 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara3 (genContPara3);
|
||||
eoCheckPoint<Indi> checkpoint3(continuatorPara3);
|
||||
peoEvalFunc<Indi> plainEval3(f);
|
||||
peoParaPopEval< Indi > eval3(plainEval3);
|
||||
eoUniformGenerator < double >uGen3 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random3 (VEC_SIZE, uGen3);
|
||||
eoRankingSelect<Indi> selectionStrategy3;
|
||||
eoSelectNumber<Indi> select3(selectionStrategy3,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover3;
|
||||
eoUniformMutation<Indi> mutation3(EPSILON);
|
||||
peoParaSGATransform <Indi> eaTransform3(crossover3,CROSS_RATE,mutation3,MUT_RATE);
|
||||
eoPlusReplacement<Indi> replace3;
|
||||
eoPop < Indi > pop3;
|
||||
pop3.append (POP_SIZE, random3);
|
||||
eoPeriodicContinue <Indi> mig_cont3( MIG_FREQ );
|
||||
eoRandomSelect<Indi> mig_select_one3;
|
||||
eoSelectNumber<Indi> mig_select3 (mig_select_one3,MIG_SIZE);
|
||||
eoPlusReplacement<Indi> mig_replace3;
|
||||
peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop2);
|
||||
checkpoint.add(mig);
|
||||
peoAsyncIslandMig<Indi> mig2(mig_cont2,mig_select2,mig_replace2,topology,pop2,pop);
|
||||
checkpoint2.add(mig2);
|
||||
peoAsyncIslandMig<Indi> mig3(mig_cont3,mig_select3,mig_replace3,topology,pop3,pop);
|
||||
checkpoint3.add(mig3);
|
||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||
mig.setOwner(Algo);
|
||||
Algo(pop);
|
||||
peoEA<Indi> Algo2(checkpoint2,eval2,select2,eaTransform2,replace2);
|
||||
mig2.setOwner(Algo2);
|
||||
Algo2(pop2);
|
||||
peoEA<Indi> Algo3(checkpoint3,eval3,select3,eaTransform3,replace3);
|
||||
mig3.setOwner(Algo3);
|
||||
Algo3(pop3);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std::cout << "Final population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
||||
std::cout << "Final population 3 :\n" << pop3 << std::endl;
|
||||
std::cout << "Final population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
||||
std::cout << "Final population 3 :\n" << pop3 << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, INRIA, 2007
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <peo>
|
||||
|
|
@ -39,12 +39,12 @@
|
|||
typedef eoRealParticle < double >Indi;
|
||||
|
||||
double f (const Indi & _indi)
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
{
|
||||
double sum;
|
||||
sum=_indi[1]-pow(_indi[0],2);
|
||||
sum=100*pow(sum,2);
|
||||
sum+=pow((1-_indi[0]),2);
|
||||
return (-sum);
|
||||
}
|
||||
|
||||
int main (int __argc, char *__argv[])
|
||||
|
|
@ -52,108 +52,108 @@ int main (int __argc, char *__argv[])
|
|||
|
||||
// In this lesson, we can see an example of a PSO with three islands.
|
||||
// The strategy of migration is the replacement.
|
||||
// The evaluation is parallel.
|
||||
|
||||
peo :: init( __argc, __argv );
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||
const unsigned int MAX_GEN = 150;
|
||||
const double INIT_POSITION_MIN = -2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const double INIT_VELOCITY_MIN = -1.;
|
||||
const double INIT_VELOCITY_MAX = 1.;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2.;
|
||||
const double C3 = 2.;
|
||||
const unsigned int MIG_FREQ = 10;
|
||||
rng.reseed (time(0));
|
||||
RingTopology topologyMig;
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||
peoParaPopEval< Indi > eval(plainEval);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint(genContPara);
|
||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec(topology);
|
||||
eoSelectNumber< Indi > mig_select(mig_selec);
|
||||
peoPSOReplacement<Indi> mig_replace;
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
||||
peoParaPopEval< Indi > eval2(plainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
||||
eoFirstIsBestInit < Indi > localInit2;
|
||||
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight2(bndsFlight2);
|
||||
eoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
peoInitializer <Indi> init2(eval2,veloRandom2,localInit2,pop2);
|
||||
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
||||
peoPSOReplacement<Indi> mig_replace2;
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval3(f);
|
||||
peoParaPopEval< Indi > eval3(plainEval3);
|
||||
eoUniformGenerator < double >uGen3 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random3 (VEC_SIZE, uGen3);
|
||||
eoUniformGenerator < double >sGen3 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom3 (VEC_SIZE, sGen3);
|
||||
eoFirstIsBestInit < Indi > localInit3;
|
||||
eoRealVectorBounds bndsFlight3(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight3(bndsFlight3);
|
||||
eoPop < Indi > pop3;
|
||||
pop3.append (POP_SIZE, random3);
|
||||
peoInitializer <Indi> init3(eval3,veloRandom3,localInit3,pop3);
|
||||
eoLinearTopology<Indi> topology3(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds3(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity3 (topology3,C1,C2,bnds3);
|
||||
eoGenContinue < Indi > genContPara3 (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint3(genContPara3);
|
||||
eoPeriodicContinue< Indi > mig_cont3( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec3(topology3);
|
||||
eoSelectNumber< Indi > mig_select3(mig_selec3);
|
||||
peoPSOReplacement<Indi> mig_replace3;
|
||||
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop2);
|
||||
checkpoint.add( mig );
|
||||
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop3);
|
||||
checkpoint2.add( mig2 );
|
||||
peoAsyncIslandMig< Indi > mig3( mig_cont3, mig_select3, mig_replace3, topologyMig, pop3, pop);
|
||||
checkpoint3.add( mig3 );
|
||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||
mig.setOwner( psa );
|
||||
psa(pop);
|
||||
peoPSO < Indi > psa2(init2,checkpoint2, eval2, velocity2, flight2);
|
||||
mig2.setOwner( psa2 );
|
||||
psa2(pop2);
|
||||
peoPSO < Indi > psa3(init3,checkpoint3, eval3, velocity3, flight3);
|
||||
mig3.setOwner( psa3 );
|
||||
psa3(pop3);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if(getNodeRank()==1)
|
||||
// The evaluation is parallel.
|
||||
|
||||
peo :: init( __argc, __argv );
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||
const unsigned int MAX_GEN = 150;
|
||||
const double INIT_POSITION_MIN = -2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const double INIT_VELOCITY_MIN = -1.;
|
||||
const double INIT_VELOCITY_MAX = 1.;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2.;
|
||||
const double C3 = 2.;
|
||||
const unsigned int MIG_FREQ = 10;
|
||||
rng.reseed (time(0));
|
||||
RingTopology topologyMig;
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||
peoParaPopEval< Indi > eval(plainEval);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint(genContPara);
|
||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec(topology);
|
||||
eoSelectNumber< Indi > mig_select(mig_selec);
|
||||
peoPSOReplacement<Indi> mig_replace;
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
||||
peoParaPopEval< Indi > eval2(plainEval2);
|
||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
||||
eoFirstIsBestInit < Indi > localInit2;
|
||||
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight2(bndsFlight2);
|
||||
eoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
peoInitializer <Indi> init2(eval2,veloRandom2,localInit2,pop2);
|
||||
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
||||
peoPSOReplacement<Indi> mig_replace2;
|
||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval3(f);
|
||||
peoParaPopEval< Indi > eval3(plainEval3);
|
||||
eoUniformGenerator < double >uGen3 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random3 (VEC_SIZE, uGen3);
|
||||
eoUniformGenerator < double >sGen3 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom3 (VEC_SIZE, sGen3);
|
||||
eoFirstIsBestInit < Indi > localInit3;
|
||||
eoRealVectorBounds bndsFlight3(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight3(bndsFlight3);
|
||||
eoPop < Indi > pop3;
|
||||
pop3.append (POP_SIZE, random3);
|
||||
peoInitializer <Indi> init3(eval3,veloRandom3,localInit3,pop3);
|
||||
eoLinearTopology<Indi> topology3(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds3(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity3 (topology3,C1,C2,bnds3);
|
||||
eoGenContinue < Indi > genContPara3 (MAX_GEN);
|
||||
eoCheckPoint<Indi> checkpoint3(genContPara3);
|
||||
eoPeriodicContinue< Indi > mig_cont3( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec3(topology3);
|
||||
eoSelectNumber< Indi > mig_select3(mig_selec3);
|
||||
peoPSOReplacement<Indi> mig_replace3;
|
||||
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop2);
|
||||
checkpoint.add( mig );
|
||||
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop3);
|
||||
checkpoint2.add( mig2 );
|
||||
peoAsyncIslandMig< Indi > mig3( mig_cont3, mig_select3, mig_replace3, topologyMig, pop3, pop);
|
||||
checkpoint3.add( mig3 );
|
||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||
mig.setOwner( psa );
|
||||
psa(pop);
|
||||
peoPSO < Indi > psa2(init2,checkpoint2, eval2, velocity2, flight2);
|
||||
mig2.setOwner( psa2 );
|
||||
psa2(pop2);
|
||||
peoPSO < Indi > psa3(init3,checkpoint3, eval3, velocity3, flight3);
|
||||
mig3.setOwner( psa3 );
|
||||
psa3(pop3);
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std::cout << "Population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Population 2 :\n" << pop2 << std::endl;
|
||||
std::cout << "Population 3 :\n" << pop3 << std::endl;
|
||||
std::cout << "Population 1 :\n" << pop << std::endl;
|
||||
std::cout << "Population 2 :\n" << pop2 << std::endl;
|
||||
std::cout << "Population 3 :\n" << pop3 << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <example.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -59,20 +59,21 @@
|
|||
#define MUT_RATE 0.01
|
||||
|
||||
|
||||
int main (int __argc, char * * __argv) {
|
||||
|
||||
// Example of a problem (TSP) with an hybridization
|
||||
int main (int __argc, char * * __argv)
|
||||
{
|
||||
|
||||
// Example of a problem (TSP) with an hybridization
|
||||
|
||||
peo :: init (__argc, __argv);
|
||||
|
||||
|
||||
loadParameters (__argc, __argv); /* Processing some parameters relative to the tackled
|
||||
problem (TSP) */
|
||||
|
||||
RouteInit route_init; /* Its builds random routes */
|
||||
loadParameters (__argc, __argv); /* Processing some parameters relative to the tackled
|
||||
problem (TSP) */
|
||||
|
||||
RouteInit route_init; /* Its builds random routes */
|
||||
RouteEval full_eval; /* Full route evaluator */
|
||||
|
||||
|
||||
|
||||
OrderXover order_cross; /* Recombination */
|
||||
PartialMappedXover pm_cross;
|
||||
EdgeXover edge_cross;
|
||||
|
|
@ -88,30 +89,30 @@ int main (int __argc, char * * __argv) {
|
|||
|
||||
/** The EA */
|
||||
eoPop <Route> ox_pop (POP_SIZE, route_init); /* Population */
|
||||
|
||||
eoGenContinue <Route> ox_cont (NUM_GEN); /* A fixed number of iterations */
|
||||
|
||||
eoGenContinue <Route> ox_cont (NUM_GEN); /* A fixed number of iterations */
|
||||
eoCheckPoint <Route> ox_checkpoint (ox_cont); /* Checkpoint */
|
||||
peoSeqPopEval <Route> ox_pop_eval (full_eval);
|
||||
peoSeqPopEval <Route> ox_pop_eval (full_eval);
|
||||
eoStochTournamentSelect <Route> ox_select_one;
|
||||
eoSelectNumber <Route> ox_select (ox_select_one, POP_SIZE);
|
||||
eoSGATransform <Route> ox_transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
|
||||
peoSeqTransform <Route> ox_para_transform (ox_transform);
|
||||
peoSeqTransform <Route> ox_para_transform (ox_transform);
|
||||
eoEPReplacement <Route> ox_replace (2);
|
||||
|
||||
peoEA <Route> ox_ea (ox_checkpoint, ox_pop_eval, ox_select, ox_para_transform, ox_replace);
|
||||
|
||||
|
||||
ox_ea (ox_pop); /* Application to the given population */
|
||||
|
||||
|
||||
|
||||
|
||||
peo :: run ();
|
||||
peo :: finalize (); /* Termination */
|
||||
|
||||
if(getNodeRank()==1)
|
||||
std :: cout << "\nResult : "<<ox_pop[ 0 ].fitness();
|
||||
hc( ox_pop[ 0 ] );
|
||||
if(getNodeRank()==1)
|
||||
std :: cout << "\n\nAfter an hybridization : " << ox_pop[ 0 ].fitness() << std :: endl;
|
||||
|
||||
|
||||
if (getNodeRank()==1)
|
||||
std :: cout << "\nResult : "<<ox_pop[ 0 ].fitness();
|
||||
hc( ox_pop[ 0 ] );
|
||||
if (getNodeRank()==1)
|
||||
std :: cout << "\n\nAfter an hybridization : " << ox_pop[ 0 ].fitness() << std :: endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, INRIA, 2007
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -50,56 +50,56 @@
|
|||
|
||||
int main( int __argc, char** __argv )
|
||||
{
|
||||
|
||||
/* In this lesson you will learn to use a multi-start.
|
||||
*
|
||||
* Thanks to this method, you can use several local searches together !!!
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* In this lesson you will learn to use a multi-start.
|
||||
*
|
||||
* Thanks to this method, you can use several local searches together !!!
|
||||
*
|
||||
*/
|
||||
|
||||
// Parameter
|
||||
const unsigned int POP_SIZE = 10;
|
||||
srand( time(NULL) );
|
||||
const unsigned int POP_SIZE = 10;
|
||||
srand( time(NULL) );
|
||||
|
||||
// Initializing the ParadisEO-PEO environment
|
||||
peo :: init( __argc, __argv );
|
||||
peo :: init( __argc, __argv );
|
||||
// Processing the command line specified parameters
|
||||
loadParameters( __argc, __argv );
|
||||
loadParameters( __argc, __argv );
|
||||
|
||||
// Define a Hill Climbing (you can choose an other local search)
|
||||
// ie Lessons of ParadisEO - MO
|
||||
Route route;
|
||||
RouteInit init;
|
||||
init(route);
|
||||
RouteEval eval;
|
||||
eval(route);
|
||||
TwoOptInit initHC;
|
||||
TwoOptNext nextHC;
|
||||
TwoOptIncrEval incrHC;
|
||||
moBestImprSelect< TwoOpt > selectHC;
|
||||
moHC< TwoOpt > hc(initHC, nextHC, incrHC, selectHC, eval);
|
||||
Route route;
|
||||
RouteInit init;
|
||||
init(route);
|
||||
RouteEval eval;
|
||||
eval(route);
|
||||
TwoOptInit initHC;
|
||||
TwoOptNext nextHC;
|
||||
TwoOptIncrEval incrHC;
|
||||
moBestImprSelect< TwoOpt > selectHC;
|
||||
moHC< TwoOpt > hc(initHC, nextHC, incrHC, selectHC, eval);
|
||||
|
||||
// Define a population
|
||||
RouteInit initPop; // Creates random Route objects
|
||||
RouteEval evalPop; // Offers a fitness value for a specified Route object
|
||||
eoPop < Route > pop(POP_SIZE, initPop);
|
||||
for ( unsigned int index = 0; index < POP_SIZE; index++ )
|
||||
evalPop( pop[ index ] );
|
||||
RouteInit initPop; // Creates random Route objects
|
||||
RouteEval evalPop; // Offers a fitness value for a specified Route object
|
||||
eoPop < Route > pop(POP_SIZE, initPop);
|
||||
for ( unsigned int index = 0; index < POP_SIZE; index++ )
|
||||
evalPop( pop[ index ] );
|
||||
|
||||
// Setting up the parallel wrapper
|
||||
peoSynchronousMultiStart< Route > parallelHC(hc);
|
||||
peoParallelAlgorithmWrapper WrapHC (parallelHC, pop);
|
||||
parallelHC.setOwner( WrapHC );
|
||||
peoSynchronousMultiStart< Route > parallelHC(hc);
|
||||
peoParallelAlgorithmWrapper WrapHC (parallelHC, pop);
|
||||
parallelHC.setOwner( WrapHC );
|
||||
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
if ( getNodeRank() == 1 )
|
||||
{
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
if ( getNodeRank() == 1 )
|
||||
{
|
||||
|
||||
std :: cout << "\n\nBefore : \n" << route;
|
||||
std :: cout << "\n\nWith the synchronous Multi-Start HCs:";
|
||||
for ( unsigned int index = 0; index < POP_SIZE; index++ )
|
||||
std::cout <<"\n"<< pop[ index ];
|
||||
}
|
||||
std :: cout << "\n\nBefore : \n" << route;
|
||||
std :: cout << "\n\nWith the synchronous Multi-Start HCs:";
|
||||
for ( unsigned int index = 0; index < POP_SIZE; index++ )
|
||||
std::cout <<"\n"<< pop[ index ];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <city_swap.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -38,12 +38,13 @@
|
|||
|
||||
#include "city_swap.h"
|
||||
|
||||
bool CitySwap :: operator () (Route & __route) {
|
||||
|
||||
bool CitySwap :: operator () (Route & __route)
|
||||
{
|
||||
|
||||
std :: swap (__route [rng.random (__route.size ())],
|
||||
__route [rng.random (__route.size ())]) ;
|
||||
|
||||
__route [rng.random (__route.size ())]) ;
|
||||
|
||||
__route.invalidate () ;
|
||||
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <city_swap.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,12 +43,13 @@
|
|||
|
||||
/** Its swaps two vertices
|
||||
randomly choosen */
|
||||
class CitySwap : public eoMonOp <Route> {
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route) ;
|
||||
|
||||
} ;
|
||||
class CitySwap : public eoMonOp <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <data.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,78 +48,84 @@
|
|||
#define MAX_FIELD_LENGTH 1000
|
||||
#define MAX_LINE_LENGTH 1000
|
||||
|
||||
static void getNextField (FILE * __f, char * __buff) {
|
||||
|
||||
char trash [MAX_TRASH_LENGTH];
|
||||
static void getNextField (FILE * __f, char * __buff)
|
||||
{
|
||||
|
||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||
char trash [MAX_TRASH_LENGTH];
|
||||
|
||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||
fscanf (__f, "%[^:\n]", __buff); /* Reading the field */
|
||||
fgetc (__f);
|
||||
}
|
||||
|
||||
static void getLine (FILE * __f, char * __buff) {
|
||||
static void getLine (FILE * __f, char * __buff)
|
||||
{
|
||||
|
||||
char trash [MAX_TRASH_LENGTH];
|
||||
char trash [MAX_TRASH_LENGTH];
|
||||
|
||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||
fscanf (__f, "%[^\n]", __buff); /* Reading the line */
|
||||
}
|
||||
|
||||
void loadData (const char * __filename) {
|
||||
void loadData (const char * __filename)
|
||||
{
|
||||
|
||||
FILE * f = fopen (__filename, "r");
|
||||
|
||||
if (f) {
|
||||
if (f)
|
||||
{
|
||||
|
||||
printf ("Loading '%s'.\n", __filename);
|
||||
|
||||
char field [MAX_FIELD_LENGTH];
|
||||
|
||||
getNextField (f, field); /* Name */
|
||||
assert (strstr (field, "NAME"));
|
||||
getNextField (f, field);
|
||||
printf ("NAME: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Comment */
|
||||
assert (strstr (field, "COMMENT"));
|
||||
getLine (f, field);
|
||||
printf ("COMMENT: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Type */
|
||||
assert (strstr (field, "TYPE"));
|
||||
getNextField (f, field);
|
||||
printf ("TYPE: %s.\n", field);
|
||||
printf ("Loading '%s'.\n", __filename);
|
||||
|
||||
getNextField (f, field); /* Dimension */
|
||||
assert (strstr (field, "DIMENSION"));
|
||||
getNextField (f, field);
|
||||
printf ("DIMENSION: %s.\n", field);
|
||||
numNodes = atoi (field);
|
||||
char field [MAX_FIELD_LENGTH];
|
||||
|
||||
getNextField (f, field); /* Edge weight type */
|
||||
assert (strstr (field, "EDGE_WEIGHT_TYPE"));
|
||||
getNextField (f, field);
|
||||
printf ("EDGE_WEIGHT_TYPE: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Node coord section */
|
||||
assert (strstr (field, "NODE_COORD_SECTION"));
|
||||
loadNodes (f);
|
||||
|
||||
getNextField (f, field); /* End of file */
|
||||
assert (strstr (field, "EOF"));
|
||||
printf ("EOF.\n");
|
||||
}
|
||||
else {
|
||||
|
||||
fprintf (stderr, "Can't open '%s'.\n", __filename);
|
||||
exit (1);
|
||||
}
|
||||
getNextField (f, field); /* Name */
|
||||
assert (strstr (field, "NAME"));
|
||||
getNextField (f, field);
|
||||
printf ("NAME: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Comment */
|
||||
assert (strstr (field, "COMMENT"));
|
||||
getLine (f, field);
|
||||
printf ("COMMENT: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Type */
|
||||
assert (strstr (field, "TYPE"));
|
||||
getNextField (f, field);
|
||||
printf ("TYPE: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Dimension */
|
||||
assert (strstr (field, "DIMENSION"));
|
||||
getNextField (f, field);
|
||||
printf ("DIMENSION: %s.\n", field);
|
||||
numNodes = atoi (field);
|
||||
|
||||
getNextField (f, field); /* Edge weight type */
|
||||
assert (strstr (field, "EDGE_WEIGHT_TYPE"));
|
||||
getNextField (f, field);
|
||||
printf ("EDGE_WEIGHT_TYPE: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Node coord section */
|
||||
assert (strstr (field, "NODE_COORD_SECTION"));
|
||||
loadNodes (f);
|
||||
|
||||
getNextField (f, field); /* End of file */
|
||||
assert (strstr (field, "EOF"));
|
||||
printf ("EOF.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
fprintf (stderr, "Can't open '%s'.\n", __filename);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
void loadData (eoParser & __parser) {
|
||||
|
||||
void loadData (eoParser & __parser)
|
||||
{
|
||||
|
||||
/* Getting the path of the instance */
|
||||
|
||||
|
||||
eoValueParam <std :: string> param ("", "inst", "Path of the instance") ;
|
||||
__parser.processParam (param) ;
|
||||
loadData (param.value ().c_str ());
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <data.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <display.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -56,7 +56,7 @@ static unsigned * X_new_coord, * Y_new_coord ;
|
|||
|
||||
/* this variable will contain the handle to the returned graphics context. */
|
||||
static GC gc;
|
||||
|
||||
|
||||
/* this variable will contain the pointer to the Display structure */
|
||||
static Display* disp;
|
||||
|
||||
|
|
@ -67,23 +67,24 @@ static int screen;
|
|||
|
||||
/* Create a new backing pixmap of the appropriate size */
|
||||
|
||||
/* Best tour */
|
||||
/*
|
||||
gdk_gc_set_line_attributes (gc, 2, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER) ;
|
||||
/* Best tour */
|
||||
/*
|
||||
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 ++) {
|
||||
for (int i = 0 ; i < (int) numNodes ; i ++) {
|
||||
|
||||
gdk_draw_line (pixmap, gc,
|
||||
X_new_coord [opt_route [i]],
|
||||
Y_new_coord [opt_route [i]],
|
||||
X_new_coord [opt_route [(i + 1) % numNodes]],
|
||||
Y_new_coord [opt_route [(i + 1) % numNodes]]);
|
||||
|
||||
}*/
|
||||
gdk_draw_line (pixmap, gc,
|
||||
X_new_coord [opt_route [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) {
|
||||
void openMainWindow (const char * __filename)
|
||||
{
|
||||
|
||||
filename = __filename;
|
||||
|
||||
|
|
@ -91,7 +92,7 @@ void openMainWindow (const char * __filename) {
|
|||
int map_width = (int) (X_max - X_min);
|
||||
int map_height = (int) (Y_max - Y_min);
|
||||
int map_side = std :: max (map_width, map_height);
|
||||
|
||||
|
||||
/* Calculate the window's width and height. */
|
||||
int win_width = (int) (screen_width * RATIO * map_width / map_side);
|
||||
int win_height = (int) (screen_height * RATIO * map_height / map_side);
|
||||
|
|
@ -100,46 +101,49 @@ void openMainWindow (const char * __filename) {
|
|||
X_new_coord = new unsigned [numNodes];
|
||||
Y_new_coord = new unsigned [numNodes];
|
||||
|
||||
for (unsigned i = 0; i < numNodes; i ++) {
|
||||
X_new_coord [i] = (unsigned) (win_width * (1.0 - (X_coord [i] - X_min) / map_width) + BORDER);
|
||||
Y_new_coord [i] = (unsigned) (win_height * (1.0 - (Y_coord [i] - Y_min) / map_height) + BORDER);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < numNodes; i ++)
|
||||
{
|
||||
X_new_coord [i] = (unsigned) (win_width * (1.0 - (X_coord [i] - X_min) / map_width) + BORDER);
|
||||
Y_new_coord [i] = (unsigned) (win_height * (1.0 - (Y_coord [i] - Y_min) / map_height) + BORDER);
|
||||
}
|
||||
|
||||
/* Initialisation */
|
||||
XGCValues val ;
|
||||
|
||||
|
||||
disp = XOpenDisplay (NULL) ;
|
||||
screen = DefaultScreen (disp) ;
|
||||
win = XCreateSimpleWindow (disp, RootWindow (disp, screen), 0, 0, win_width + 2 * BORDER, win_height + 2 * BORDER, 2, BlackPixel (disp, screen), WhitePixel (disp, screen)) ;
|
||||
val.foreground = BlackPixel(disp, screen) ;
|
||||
val.background = WhitePixel(disp, screen) ;
|
||||
gc = XCreateGC (disp, win, GCForeground | GCBackground, & val) ;
|
||||
gc = XCreateGC (disp, win, GCForeground | GCBackground, & val) ;
|
||||
|
||||
XMapWindow (disp, win) ;
|
||||
XFlush (disp) ;
|
||||
|
||||
while (true) {
|
||||
XClearWindow (disp, win) ;
|
||||
while (true)
|
||||
{
|
||||
XClearWindow (disp, win) ;
|
||||
|
||||
/* Vertices as circles */
|
||||
for (unsigned i = 1 ; i < numNodes ; i ++)
|
||||
XDrawArc (disp, win, gc, X_new_coord [i] - 1, Y_new_coord [i] - 1, 3, 3, 0, 364 * 64) ;
|
||||
|
||||
/* New tour */
|
||||
std :: ifstream f (filename);
|
||||
if (f) {
|
||||
Route route;
|
||||
f >> route;
|
||||
f.close ();
|
||||
|
||||
for (int i = 0; i < (int) numNodes; i ++)
|
||||
XDrawLine (disp, win, gc,
|
||||
X_new_coord [route [i]],
|
||||
Y_new_coord [route [i]],
|
||||
X_new_coord [route [(i + 1) % numNodes]],
|
||||
Y_new_coord [route [(i + 1) % numNodes]]);
|
||||
/* Vertices as circles */
|
||||
for (unsigned i = 1 ; i < numNodes ; i ++)
|
||||
XDrawArc (disp, win, gc, X_new_coord [i] - 1, Y_new_coord [i] - 1, 3, 3, 0, 364 * 64) ;
|
||||
|
||||
/* New tour */
|
||||
std :: ifstream f (filename);
|
||||
if (f)
|
||||
{
|
||||
Route route;
|
||||
f >> route;
|
||||
f.close ();
|
||||
|
||||
for (int i = 0; i < (int) numNodes; i ++)
|
||||
XDrawLine (disp, win, gc,
|
||||
X_new_coord [route [i]],
|
||||
Y_new_coord [route [i]],
|
||||
X_new_coord [route [(i + 1) % numNodes]],
|
||||
Y_new_coord [route [(i + 1) % numNodes]]);
|
||||
}
|
||||
XFlush (disp) ;
|
||||
sleep (1) ;
|
||||
}
|
||||
XFlush (disp) ;
|
||||
sleep (1) ;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <display.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <display_best_route.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -38,13 +38,14 @@
|
|||
#include "display.h"
|
||||
|
||||
DisplayBestRoute :: DisplayBestRoute (eoPop <Route> & __pop
|
||||
) : pop (__pop) {
|
||||
|
||||
|
||||
) : pop (__pop)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DisplayBestRoute :: operator () () {
|
||||
|
||||
|
||||
void DisplayBestRoute :: operator () ()
|
||||
{
|
||||
|
||||
displayRoute (pop.best_element ());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <display_best_route.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,18 +43,19 @@
|
|||
|
||||
#include "route.h"
|
||||
|
||||
class DisplayBestRoute : public eoUpdater {
|
||||
|
||||
public :
|
||||
class DisplayBestRoute : public eoUpdater
|
||||
{
|
||||
|
||||
DisplayBestRoute (eoPop <Route> & __pop);
|
||||
|
||||
void operator () ();
|
||||
public :
|
||||
|
||||
private :
|
||||
|
||||
eoPop <Route> & pop;
|
||||
DisplayBestRoute (eoPop <Route> & __pop);
|
||||
|
||||
};
|
||||
void operator () ();
|
||||
|
||||
private :
|
||||
|
||||
eoPop <Route> & pop;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <edge_xover.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,104 +41,114 @@
|
|||
|
||||
#include "edge_xover.h"
|
||||
|
||||
void EdgeXover :: build_map (const Route & __par1, const Route & __par2) {
|
||||
|
||||
void EdgeXover :: build_map (const Route & __par1, const Route & __par2)
|
||||
{
|
||||
|
||||
unsigned len = __par1.size () ;
|
||||
|
||||
|
||||
/* Initialization */
|
||||
_map.clear () ;
|
||||
_map.resize (len) ;
|
||||
|
||||
for (unsigned i = 0 ; i < len ; i ++) {
|
||||
_map [__par1 [i]].insert (__par1 [(i + 1) % len]) ;
|
||||
_map [__par2 [i]].insert (__par2 [(i + 1) % len]) ;
|
||||
_map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ;
|
||||
_map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ;
|
||||
}
|
||||
|
||||
|
||||
for (unsigned i = 0 ; i < len ; i ++)
|
||||
{
|
||||
_map [__par1 [i]].insert (__par1 [(i + 1) % len]) ;
|
||||
_map [__par2 [i]].insert (__par2 [(i + 1) % len]) ;
|
||||
_map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ;
|
||||
_map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ;
|
||||
}
|
||||
|
||||
visited.clear () ;
|
||||
visited.resize (len, false) ;
|
||||
}
|
||||
|
||||
void EdgeXover :: remove_entry (unsigned __vertex, std :: vector <std :: set <unsigned> > & __map) {
|
||||
|
||||
std :: set <unsigned> & neigh = __map [__vertex] ;
|
||||
void EdgeXover :: remove_entry (unsigned __vertex, std :: vector <std :: set <unsigned> > & __map)
|
||||
{
|
||||
|
||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||
it != neigh.end () ;
|
||||
it ++)
|
||||
__map [* it].erase (__vertex) ;
|
||||
|
||||
}
|
||||
std :: set <unsigned> & neigh = __map [__vertex] ;
|
||||
|
||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||
it != neigh.end () ;
|
||||
it ++)
|
||||
__map [* it].erase (__vertex) ;
|
||||
|
||||
}
|
||||
|
||||
void EdgeXover :: add_vertex (unsigned __vertex, Route & __child)
|
||||
{
|
||||
|
||||
void EdgeXover :: add_vertex (unsigned __vertex, Route & __child) {
|
||||
|
||||
visited [__vertex] = true ;
|
||||
__child.push_back (__vertex) ;
|
||||
remove_entry (__vertex, _map) ; /* Removing entries */
|
||||
__child.push_back (__vertex) ;
|
||||
remove_entry (__vertex, _map) ; /* Removing entries */
|
||||
}
|
||||
|
||||
void EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child) {
|
||||
|
||||
void EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
|
||||
{
|
||||
|
||||
build_map (__par1, __par2) ;
|
||||
|
||||
|
||||
unsigned len = __par1.size () ;
|
||||
|
||||
|
||||
/* Go ! */
|
||||
__child.clear () ;
|
||||
|
||||
|
||||
unsigned cur_vertex = rng.random (len) ;
|
||||
|
||||
|
||||
add_vertex (cur_vertex, __child) ;
|
||||
|
||||
for (unsigned i = 1 ; i < len ; i ++) {
|
||||
|
||||
unsigned len_min_entry = MAXINT ;
|
||||
|
||||
std :: set <unsigned> & neigh = _map [cur_vertex] ;
|
||||
|
||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||
it != neigh.end () ;
|
||||
it ++) {
|
||||
unsigned l = _map [* it].size () ;
|
||||
if (len_min_entry > l)
|
||||
len_min_entry = l ;
|
||||
}
|
||||
|
||||
std :: vector <unsigned> cand ; /* Candidates */
|
||||
|
||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||
it != neigh.end () ;
|
||||
it ++) {
|
||||
unsigned l = _map [* it].size () ;
|
||||
if (len_min_entry == l)
|
||||
cand.push_back (* it) ;
|
||||
}
|
||||
|
||||
if (! cand.size ()) {
|
||||
|
||||
/* Oh no ! Implicit mutation */
|
||||
for (unsigned j = 0 ; j < len ; j ++)
|
||||
if (! visited [j])
|
||||
cand.push_back (j) ;
|
||||
}
|
||||
for (unsigned i = 1 ; i < len ; i ++)
|
||||
{
|
||||
|
||||
cur_vertex = cand [rng.random (cand.size ())] ;
|
||||
|
||||
add_vertex (cur_vertex, __child) ;
|
||||
}
|
||||
unsigned len_min_entry = MAXINT ;
|
||||
|
||||
std :: set <unsigned> & neigh = _map [cur_vertex] ;
|
||||
|
||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||
it != neigh.end () ;
|
||||
it ++)
|
||||
{
|
||||
unsigned l = _map [* it].size () ;
|
||||
if (len_min_entry > l)
|
||||
len_min_entry = l ;
|
||||
}
|
||||
|
||||
std :: vector <unsigned> cand ; /* Candidates */
|
||||
|
||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||
it != neigh.end () ;
|
||||
it ++)
|
||||
{
|
||||
unsigned l = _map [* it].size () ;
|
||||
if (len_min_entry == l)
|
||||
cand.push_back (* it) ;
|
||||
}
|
||||
|
||||
if (! cand.size ())
|
||||
{
|
||||
|
||||
/* Oh no ! Implicit mutation */
|
||||
for (unsigned j = 0 ; j < len ; j ++)
|
||||
if (! visited [j])
|
||||
cand.push_back (j) ;
|
||||
}
|
||||
|
||||
cur_vertex = cand [rng.random (cand.size ())] ;
|
||||
|
||||
add_vertex (cur_vertex, __child) ;
|
||||
}
|
||||
}
|
||||
|
||||
bool EdgeXover :: operator () (Route & __route1, Route & __route2) {
|
||||
|
||||
bool EdgeXover :: operator () (Route & __route1, Route & __route2)
|
||||
{
|
||||
|
||||
// Init. copy
|
||||
Route par [2] ;
|
||||
par [0] = __route1 ;
|
||||
par [1] = __route2 ;
|
||||
|
||||
|
||||
cross (par [0], par [1], __route1) ;
|
||||
cross (par [1], par [0], __route2) ;
|
||||
|
||||
|
||||
__route1.invalidate () ;
|
||||
__route2.invalidate () ;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <edge_xover.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,27 +45,28 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Edge Crossover */
|
||||
class EdgeXover : public eoQuadOp <Route> {
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
class EdgeXover : public eoQuadOp <Route>
|
||||
{
|
||||
|
||||
private :
|
||||
|
||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */
|
||||
public :
|
||||
|
||||
void remove_entry (unsigned __vertex, std :: vector <std :: set <unsigned> > & __map) ;
|
||||
/* Updating the map of entries */
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
|
||||
void build_map (const Route & __par1, const Route & __par2) ;
|
||||
private :
|
||||
|
||||
void add_vertex (unsigned __vertex, Route & __child) ;
|
||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */
|
||||
|
||||
std :: vector <std :: set <unsigned> > _map ; /* The handled map */
|
||||
void remove_entry (unsigned __vertex, std :: vector <std :: set <unsigned> > & __map) ;
|
||||
/* Updating the map of entries */
|
||||
|
||||
std :: vector <bool> visited ; /* Vertices that are already visited */
|
||||
void build_map (const Route & __par1, const Route & __par2) ;
|
||||
|
||||
} ;
|
||||
void add_vertex (unsigned __vertex, Route & __child) ;
|
||||
|
||||
std :: vector <std :: set <unsigned> > _map ; /* The handled map */
|
||||
|
||||
std :: vector <bool> visited ; /* Vertices that are already visited */
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <merge_route_eval.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,10 +36,11 @@
|
|||
|
||||
#include "merge_route_eval.h"
|
||||
|
||||
void MergeRouteEval :: operator () (Route & __route, const int & __part_fit) {
|
||||
void MergeRouteEval :: operator () (Route & __route, const int & __part_fit)
|
||||
{
|
||||
|
||||
int len = __route.fitness ();
|
||||
len += __part_fit;
|
||||
__route.fitness (len);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <merge_route_eval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,12 +41,13 @@
|
|||
|
||||
#include "route.h"
|
||||
|
||||
class MergeRouteEval : public peoAggEvalFunc <Route> {
|
||||
|
||||
public :
|
||||
class MergeRouteEval : public peoAggEvalFunc <Route>
|
||||
{
|
||||
|
||||
void operator () (Route & __route, const int & __part_fit) ;
|
||||
|
||||
};
|
||||
public :
|
||||
|
||||
void operator () (Route & __route, const int & __part_fit) ;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <mix.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,8 +41,9 @@
|
|||
|
||||
#include <utils/eoRNG.h>
|
||||
|
||||
template <class T> void mix (std :: vector <T> & __v) {
|
||||
|
||||
template <class T> void mix (std :: vector <T> & __v)
|
||||
{
|
||||
|
||||
unsigned len = __v.size () ;
|
||||
|
||||
for (unsigned i = 0 ; i < len ; i ++)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <node.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,59 +47,62 @@ double * X_coord, * Y_coord;
|
|||
|
||||
double X_min = MAXDOUBLE, X_max = MINDOUBLE, Y_min = MAXDOUBLE, Y_max = MINDOUBLE;
|
||||
|
||||
void loadNodes (FILE * __f) {
|
||||
void loadNodes (FILE * __f)
|
||||
{
|
||||
|
||||
/* Coord */
|
||||
|
||||
|
||||
X_coord = new double [numNodes];
|
||||
|
||||
|
||||
Y_coord = new double [numNodes];
|
||||
|
||||
|
||||
unsigned num;
|
||||
|
||||
for (unsigned i = 0; i < numNodes; i ++) {
|
||||
|
||||
fscanf (__f, "%u%lf%lf", & num, X_coord + i, Y_coord + i);
|
||||
|
||||
if (X_coord [i] < X_min)
|
||||
X_min = X_coord [i];
|
||||
if (X_coord [i] > X_max)
|
||||
X_max = X_coord [i];
|
||||
if (Y_coord [i] < Y_min)
|
||||
Y_min = Y_coord [i];
|
||||
if (Y_coord [i] > Y_max)
|
||||
Y_max = Y_coord [i];
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < numNodes; i ++)
|
||||
{
|
||||
|
||||
fscanf (__f, "%u%lf%lf", & num, X_coord + i, Y_coord + i);
|
||||
|
||||
if (X_coord [i] < X_min)
|
||||
X_min = X_coord [i];
|
||||
if (X_coord [i] > X_max)
|
||||
X_max = X_coord [i];
|
||||
if (Y_coord [i] < Y_min)
|
||||
Y_min = Y_coord [i];
|
||||
if (Y_coord [i] > Y_max)
|
||||
Y_max = Y_coord [i];
|
||||
}
|
||||
|
||||
/* Allocation */
|
||||
/*
|
||||
dist = new unsigned * [numNodes];
|
||||
|
||||
|
||||
for (unsigned i = 0; i < numNodes; i ++)
|
||||
dist [i] = new unsigned [numNodes];
|
||||
*/
|
||||
/* Computation of the distances */
|
||||
|
||||
|
||||
/*
|
||||
for (unsigned i = 0; i < numNodes; i ++) {
|
||||
|
||||
dist [i] [i] = 0;
|
||||
|
||||
for (unsigned j = 0; j < numNodes; j ++) {
|
||||
|
||||
|
||||
double dx = X_coord [i] - X_coord [j], dy = Y_coord [i] - Y_coord [j];
|
||||
|
||||
|
||||
dist [i] [j] = dist [j] [i] = (unsigned) (sqrt (dx * dx + dy * dy) + 0.5) ;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
unsigned distance (Node __from, Node __to) {
|
||||
unsigned distance (Node __from, Node __to)
|
||||
{
|
||||
|
||||
// return dist [__from] [__to];
|
||||
|
||||
double dx = X_coord [__from] - X_coord [__to], dy = Y_coord [__from] - Y_coord [__to];
|
||||
|
||||
|
||||
return (unsigned) (sqrt (dx * dx + dy * dy) + 0.5) ;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <node.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned Node;
|
||||
typedef unsigned Node;
|
||||
|
||||
extern double X_min, X_max, Y_min, Y_max;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <opt_route.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,88 +40,96 @@
|
|||
#define MAX_FIELD_LENGTH 1000
|
||||
#define MAX_LINE_LENGTH 1000
|
||||
|
||||
static void getNextField (FILE * __f, char * __buff) {
|
||||
|
||||
char trash [MAX_TRASH_LENGTH];
|
||||
static void getNextField (FILE * __f, char * __buff)
|
||||
{
|
||||
|
||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||
char trash [MAX_TRASH_LENGTH];
|
||||
|
||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||
fscanf (__f, "%[^:\n]", __buff); /* Reading the field */
|
||||
fgetc (__f);
|
||||
}
|
||||
|
||||
static void getLine (FILE * __f, char * __buff) {
|
||||
static void getLine (FILE * __f, char * __buff)
|
||||
{
|
||||
|
||||
char trash [MAX_TRASH_LENGTH];
|
||||
char trash [MAX_TRASH_LENGTH];
|
||||
|
||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||
fscanf (__f, "%[^\n]", __buff); /* Reading the line */
|
||||
}
|
||||
|
||||
static void loadBestRoute (FILE * __f) {
|
||||
static void loadBestRoute (FILE * __f)
|
||||
{
|
||||
|
||||
opt_route.clear ();
|
||||
|
||||
for (unsigned i = 0; i < numNodes; i ++) {
|
||||
Node node;
|
||||
fscanf (__f, "%u", & node);
|
||||
opt_route.push_back (node - 1);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < numNodes; i ++)
|
||||
{
|
||||
Node node;
|
||||
fscanf (__f, "%u", & node);
|
||||
opt_route.push_back (node - 1);
|
||||
}
|
||||
int d; /* -1 ! */
|
||||
fscanf (__f, "%d", & d);
|
||||
}
|
||||
|
||||
void loadOptimumRoute (const char * __filename) {
|
||||
void loadOptimumRoute (const char * __filename)
|
||||
{
|
||||
|
||||
FILE * f = fopen (__filename, "r");
|
||||
|
||||
if (f) {
|
||||
|
||||
printf ("Loading '%s'.\n", __filename);
|
||||
|
||||
char field [MAX_FIELD_LENGTH];
|
||||
|
||||
getNextField (f, field); /* Name */
|
||||
assert (strstr (field, "NAME"));
|
||||
getNextField (f, field);
|
||||
//printf ("NAME: %s.\n", field);
|
||||
if (f)
|
||||
{
|
||||
|
||||
getNextField (f, field); /* Comment */
|
||||
assert (strstr (field, "COMMENT"));
|
||||
getLine (f, field);
|
||||
// printf ("COMMENT: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Type */
|
||||
assert (strstr (field, "TYPE"));
|
||||
getNextField (f, field);
|
||||
//printf ("TYPE: %s.\n", field);
|
||||
printf ("Loading '%s'.\n", __filename);
|
||||
|
||||
getNextField (f, field); /* Dimension */
|
||||
assert (strstr (field, "DIMENSION"));
|
||||
getNextField (f, field);
|
||||
// printf ("DIMENSION: %s.\n", field);
|
||||
numNodes = atoi (field);
|
||||
char field [MAX_FIELD_LENGTH];
|
||||
|
||||
getNextField (f, field); /* Tour section */
|
||||
assert (strstr (field, "TOUR_SECTION"));
|
||||
loadBestRoute (f);
|
||||
|
||||
getNextField (f, field); /* End of file */
|
||||
assert (strstr (field, "EOF"));
|
||||
//printf ("EOF.\n");
|
||||
|
||||
printf ("The length of the best route is %u.\n", length (opt_route));
|
||||
}
|
||||
else {
|
||||
|
||||
fprintf (stderr, "Can't open '%s'.\n", __filename);
|
||||
exit (1);
|
||||
}
|
||||
getNextField (f, field); /* Name */
|
||||
assert (strstr (field, "NAME"));
|
||||
getNextField (f, field);
|
||||
//printf ("NAME: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Comment */
|
||||
assert (strstr (field, "COMMENT"));
|
||||
getLine (f, field);
|
||||
// printf ("COMMENT: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Type */
|
||||
assert (strstr (field, "TYPE"));
|
||||
getNextField (f, field);
|
||||
//printf ("TYPE: %s.\n", field);
|
||||
|
||||
getNextField (f, field); /* Dimension */
|
||||
assert (strstr (field, "DIMENSION"));
|
||||
getNextField (f, field);
|
||||
// printf ("DIMENSION: %s.\n", field);
|
||||
numNodes = atoi (field);
|
||||
|
||||
getNextField (f, field); /* Tour section */
|
||||
assert (strstr (field, "TOUR_SECTION"));
|
||||
loadBestRoute (f);
|
||||
|
||||
getNextField (f, field); /* End of file */
|
||||
assert (strstr (field, "EOF"));
|
||||
//printf ("EOF.\n");
|
||||
|
||||
printf ("The length of the best route is %u.\n", length (opt_route));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
fprintf (stderr, "Can't open '%s'.\n", __filename);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
void loadOptimumRoute (eoParser & __parser) {
|
||||
|
||||
void loadOptimumRoute (eoParser & __parser)
|
||||
{
|
||||
|
||||
/* Getting the path of the instance */
|
||||
|
||||
|
||||
eoValueParam <std :: string> param ("", "optimumTour", "Optimum tour") ;
|
||||
__parser.processParam (param) ;
|
||||
if (strlen (param.value ().c_str ()))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <opt_route.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <order_xover.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,51 +40,57 @@
|
|||
|
||||
#include "order_xover.h"
|
||||
|
||||
void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child) {
|
||||
void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
|
||||
{
|
||||
|
||||
unsigned cut2 = 1 + rng.random (numNodes) ;
|
||||
unsigned cut2 = 1 + rng.random (numNodes) ;
|
||||
unsigned cut1 = rng.random (cut2);
|
||||
unsigned l = 0;
|
||||
|
||||
/* To store vertices that have already been crossed */
|
||||
std :: vector <bool> v (numNodes, false);
|
||||
|
||||
/* Copy of the left partial route of the first parent */
|
||||
for (unsigned i = cut1 ; i < cut2 ; i ++) {
|
||||
__child [l ++] = __par1 [i] ;
|
||||
v [__par1 [i]] = true ;
|
||||
}
|
||||
|
||||
/* Copy of the left partial route of the first parent */
|
||||
for (unsigned i = cut1 ; i < cut2 ; i ++)
|
||||
{
|
||||
__child [l ++] = __par1 [i] ;
|
||||
v [__par1 [i]] = true ;
|
||||
}
|
||||
|
||||
/* Searching the vertex of the second path, that ended the previous first one */
|
||||
unsigned from = 0 ;
|
||||
for (unsigned i = 0; i < numNodes; i ++)
|
||||
if (__par2 [i] == __child [cut2 - 1]) {
|
||||
from = i ;
|
||||
break ;
|
||||
}
|
||||
|
||||
if (__par2 [i] == __child [cut2 - 1])
|
||||
{
|
||||
from = i ;
|
||||
break ;
|
||||
}
|
||||
|
||||
/* Selecting a direction (Left or Right) */
|
||||
char direct = rng.flip () ? 1 : -1 ;
|
||||
|
||||
for (unsigned i = 0; i < numNodes + 1; i ++) {
|
||||
unsigned bidule = (direct * i + from + numNodes) % numNodes;
|
||||
if (! v [__par2 [bidule]]) {
|
||||
__child [l ++] = __par2 [bidule] ;
|
||||
v [__par2 [bidule]] = true ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool OrderXover :: operator () (Route & __route1, Route & __route2) {
|
||||
|
||||
for (unsigned i = 0; i < numNodes + 1; i ++)
|
||||
{
|
||||
unsigned bidule = (direct * i + from + numNodes) % numNodes;
|
||||
if (! v [__par2 [bidule]])
|
||||
{
|
||||
__child [l ++] = __par2 [bidule] ;
|
||||
v [__par2 [bidule]] = true ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool OrderXover :: operator () (Route & __route1, Route & __route2)
|
||||
{
|
||||
|
||||
// Init. copy
|
||||
Route par [2] ;
|
||||
par [0] = __route1 ;
|
||||
par [1] = __route2 ;
|
||||
|
||||
|
||||
cross (par [0], par [1], __route1) ;
|
||||
cross (par [1], par [0], __route2) ;
|
||||
|
||||
|
||||
__route1.invalidate () ;
|
||||
__route2.invalidate () ;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <order_xover.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,15 +42,16 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Order Crossover */
|
||||
class OrderXover : public eoQuadOp <Route> {
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
class OrderXover : public eoQuadOp <Route>
|
||||
{
|
||||
|
||||
private :
|
||||
|
||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ;
|
||||
} ;
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
|
||||
private :
|
||||
|
||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ;
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <param.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,10 +39,11 @@
|
|||
#include "data.h"
|
||||
#include "opt_route.h"
|
||||
|
||||
void loadParameters (int __argc, char * * __argv) {
|
||||
void loadParameters (int __argc, char * * __argv)
|
||||
{
|
||||
|
||||
eoParser parser (__argc, __argv);
|
||||
|
||||
|
||||
loadData (parser);
|
||||
|
||||
loadOptimumRoute (parser);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <param.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <part_route_eval.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -38,21 +38,22 @@
|
|||
#include "node.h"
|
||||
|
||||
PartRouteEval :: PartRouteEval (float __from,
|
||||
float __to
|
||||
) : from (__from),
|
||||
to (__to) {
|
||||
|
||||
float __to
|
||||
) : from (__from),
|
||||
to (__to)
|
||||
{
|
||||
}
|
||||
|
||||
void PartRouteEval :: operator () (Route & __route) {
|
||||
|
||||
|
||||
void PartRouteEval :: operator () (Route & __route)
|
||||
{
|
||||
|
||||
|
||||
unsigned len = 0 ;
|
||||
|
||||
|
||||
for (unsigned i = (unsigned) (__route.size () * from) ;
|
||||
i < (unsigned) (__route.size () * to) ;
|
||||
i ++)
|
||||
len += distance (__route [i], __route [(i + 1) % numNodes]) ;
|
||||
|
||||
|
||||
__route.fitness (- (int) len) ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <part_route_eval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,20 +42,21 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Route Evaluator */
|
||||
class PartRouteEval : public eoEvalFunc <Route> {
|
||||
|
||||
public :
|
||||
class PartRouteEval : public eoEvalFunc <Route>
|
||||
{
|
||||
|
||||
/** Constructor */
|
||||
PartRouteEval (float __from, float __to) ;
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
private :
|
||||
public :
|
||||
|
||||
float from, to ;
|
||||
/** Constructor */
|
||||
PartRouteEval (float __from, float __to) ;
|
||||
|
||||
} ;
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
private :
|
||||
|
||||
float from, to ;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <partial_mapped_xover.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,47 +41,50 @@
|
|||
#include "partial_mapped_xover.h"
|
||||
#include "mix.h"
|
||||
|
||||
void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2) {
|
||||
|
||||
void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2)
|
||||
{
|
||||
|
||||
unsigned v [__route.size ()] ; // Number of times a cities are visited ...
|
||||
|
||||
|
||||
for (unsigned i = 0 ; i < __route.size () ; i ++)
|
||||
v [i] = 0 ;
|
||||
|
||||
|
||||
for (unsigned i = 0 ; i < __route.size () ; i ++)
|
||||
v [__route [i]] ++ ;
|
||||
|
||||
|
||||
std :: vector <unsigned> vert ;
|
||||
|
||||
for (unsigned i = 0 ; i < __route.size () ; i ++)
|
||||
if (! v [i])
|
||||
vert.push_back (i) ;
|
||||
|
||||
|
||||
mix (vert) ;
|
||||
|
||||
for (unsigned i = 0 ; i < __route.size () ; i ++)
|
||||
if (i < __cut1 || i >= __cut2)
|
||||
if (v [__route [i]] > 1) {
|
||||
__route [i] = vert.back () ;
|
||||
vert.pop_back () ;
|
||||
}
|
||||
if (v [__route [i]] > 1)
|
||||
{
|
||||
__route [i] = vert.back () ;
|
||||
vert.pop_back () ;
|
||||
}
|
||||
}
|
||||
|
||||
bool PartialMappedXover :: operator () (Route & __route1, Route & __route2) {
|
||||
|
||||
bool PartialMappedXover :: operator () (Route & __route1, Route & __route2)
|
||||
{
|
||||
|
||||
unsigned cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ;
|
||||
|
||||
|
||||
if (cut2 < cut1)
|
||||
std :: swap (cut1, cut2) ;
|
||||
|
||||
|
||||
// Between the cuts
|
||||
for (unsigned i = cut1 ; i < cut2 ; i ++)
|
||||
std :: swap (__route1 [i], __route2 [i]) ;
|
||||
|
||||
|
||||
// Outside the cuts
|
||||
repair (__route1, cut1, cut2) ;
|
||||
repair (__route2, cut1, cut2) ;
|
||||
|
||||
|
||||
__route1.invalidate () ;
|
||||
__route2.invalidate () ;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <partial_mapped_xover.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,15 +42,16 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Partial Mapped Crossover */
|
||||
class PartialMappedXover : public eoQuadOp <Route> {
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
class PartialMappedXover : public eoQuadOp <Route>
|
||||
{
|
||||
|
||||
private :
|
||||
|
||||
void repair (Route & __route, unsigned __cut1, unsigned __cut2) ;
|
||||
} ;
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
|
||||
private :
|
||||
|
||||
void repair (Route & __route, unsigned __cut1, unsigned __cut2) ;
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,13 +36,14 @@
|
|||
|
||||
#include "route.h"
|
||||
|
||||
unsigned length (const Route & __route) {
|
||||
unsigned length (const Route & __route)
|
||||
{
|
||||
|
||||
unsigned len = 0 ;
|
||||
|
||||
|
||||
for (unsigned i = 0; i < numNodes; i ++)
|
||||
len += distance (__route [i], __route [(i + 1) % numNodes]) ;
|
||||
|
||||
len += distance (__route [i], __route [(i + 1) % numNodes]) ;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,8 +41,8 @@
|
|||
|
||||
#include "node.h"
|
||||
|
||||
typedef eoVector <int, Node> Route;
|
||||
typedef eoVector <int, Node> Route;
|
||||
|
||||
unsigned length (const Route & __route);
|
||||
unsigned length (const Route & __route);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_eval.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "route_eval.h"
|
||||
|
||||
void RouteEval :: operator () (Route & __route) {
|
||||
__route.fitness (- (int) length (__route));
|
||||
void RouteEval :: operator () (Route & __route)
|
||||
{
|
||||
__route.fitness (- (int) length (__route));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_eval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,11 +41,12 @@
|
|||
|
||||
#include "route.h"
|
||||
|
||||
class RouteEval : public eoEvalFunc <Route> {
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
} ;
|
||||
class RouteEval : public eoEvalFunc <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_init.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,13 +39,14 @@
|
|||
#include "route_init.h"
|
||||
#include "node.h"
|
||||
|
||||
void RouteInit :: operator () (Route & __route) {
|
||||
void RouteInit :: operator () (Route & __route)
|
||||
{
|
||||
|
||||
__route.clear ();
|
||||
|
||||
|
||||
for (unsigned i = 0 ; i < numNodes ; i ++)
|
||||
__route.push_back (i);
|
||||
|
||||
for (unsigned i = 0 ; i < numNodes ; i ++)
|
||||
|
||||
for (unsigned i = 0 ; i < numNodes ; i ++)
|
||||
std :: swap (__route [i], __route [rng.random (numNodes)]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_init.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,11 +41,12 @@
|
|||
|
||||
#include "route.h"
|
||||
|
||||
class RouteInit : public eoInit <Route> {
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route);
|
||||
} ;
|
||||
class RouteInit : public eoInit <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route);
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,13 +36,15 @@
|
|||
|
||||
#include "two_opt.h"
|
||||
|
||||
void TwoOpt :: operator () (Route & __route) {
|
||||
|
||||
unsigned i = 0;
|
||||
void TwoOpt :: operator () (Route & __route)
|
||||
{
|
||||
|
||||
while ((2 * i) < (second - first)) {
|
||||
|
||||
std :: swap (__route [first + i], __route [second - i]);
|
||||
i ++;
|
||||
}
|
||||
unsigned i = 0;
|
||||
|
||||
while ((2 * i) < (second - first))
|
||||
{
|
||||
|
||||
std :: swap (__route [first + i], __route [second - i]);
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,12 +42,13 @@
|
|||
|
||||
#include "route.h"
|
||||
|
||||
class TwoOpt : public moMove <Route>, public std :: pair <unsigned, unsigned> {
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route);
|
||||
class TwoOpt : public moMove <Route>, public std :: pair <unsigned, unsigned>
|
||||
{
|
||||
|
||||
} ;
|
||||
public :
|
||||
|
||||
void operator () (Route & __route);
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_incr_eval.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,16 +37,17 @@
|
|||
#include "two_opt_incr_eval.h"
|
||||
#include "node.h"
|
||||
|
||||
int TwoOptIncrEval :: operator () (const TwoOpt & __move, const Route & __route) {
|
||||
|
||||
int TwoOptIncrEval :: operator () (const TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
|
||||
/* From */
|
||||
Node v1 = __route [__move.first], v1_left = __route [(__move.first - 1 + numNodes) % numNodes];
|
||||
|
||||
|
||||
/* To */
|
||||
Node v2 = __route [__move.second], v2_right = __route [(__move.second + 1) % numNodes];
|
||||
|
||||
|
||||
if (v1 == v2 || v2_right == v1)
|
||||
return __route.fitness ();
|
||||
else
|
||||
else
|
||||
return __route.fitness () - distance (v1_left, v2) - distance (v1, v2_right) + distance (v1_left, v1) + distance (v2, v2_right);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_incr_eval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,12 +40,13 @@
|
|||
#include <moMoveIncrEval.h>
|
||||
#include "two_opt.h"
|
||||
|
||||
class TwoOptIncrEval : public moMoveIncrEval <TwoOpt> {
|
||||
class TwoOptIncrEval : public moMoveIncrEval <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
int operator () (const TwoOpt & __move, const Route & __route) ;
|
||||
public :
|
||||
|
||||
} ;
|
||||
int operator () (const TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_init.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,7 +36,8 @@
|
|||
|
||||
#include "two_opt_init.h"
|
||||
|
||||
void TwoOptInit :: operator () (TwoOpt & __move, const Route & __route) {
|
||||
|
||||
void TwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
|
||||
__move.first = __move.second = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_init.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,12 +41,13 @@
|
|||
|
||||
#include "two_opt.h"
|
||||
|
||||
class TwoOptInit : public moMoveInit <TwoOpt> {
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
class TwoOptInit : public moMoveInit <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_next.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,19 +37,22 @@
|
|||
#include "two_opt_next.h"
|
||||
#include "node.h"
|
||||
|
||||
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route) {
|
||||
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
|
||||
if (__move.first == numNodes - 1 && __move.second == numNodes - 1)
|
||||
return false;
|
||||
|
||||
else {
|
||||
|
||||
__move.second ++;
|
||||
if (__move.second == numNodes) {
|
||||
|
||||
__move.first ++;
|
||||
__move.second = __move.first;
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
__move.second ++;
|
||||
if (__move.second == numNodes)
|
||||
{
|
||||
|
||||
__move.first ++;
|
||||
__move.second = __move.first;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_next.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,12 +41,13 @@
|
|||
|
||||
#include "two_opt.h"
|
||||
|
||||
class TwoOptNext : public moNextMove <TwoOpt> {
|
||||
class TwoOptNext : public moNextMove <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (TwoOpt & __move, const Route & __route);
|
||||
|
||||
};
|
||||
public :
|
||||
|
||||
bool operator () (TwoOpt & __move, const Route & __route);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_rand.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,13 +37,14 @@
|
|||
#include <utils/eoRNG.h>
|
||||
|
||||
#include "two_opt_rand.h"
|
||||
#include "node.h"
|
||||
#include "node.h"
|
||||
|
||||
void TwoOptRand :: operator () (TwoOpt & __move, const Route & __route) {
|
||||
void TwoOptRand :: operator () (TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
|
||||
__move.second = rng.random (numNodes);
|
||||
|
||||
__move.first = rng.random (__move.second);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_rand.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,12 +41,13 @@
|
|||
|
||||
#include "two_opt.h"
|
||||
|
||||
class TwoOptRand : public eoMoveRand <TwoOpt> {
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
class TwoOptRand : public eoMoveRand <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue