EASEA defined sections

Aller à : navigation, rechercher

Genome specific fields

Genome Initialiser

Description

Uses the Genome EASEA variable to access the individual's genome.

EASEA syntax

\GenomeClass::initialiser :
     ...
\end

Example

\GenomeClass::initialiser :
  for(int i=0; i<SIZE; i++ ) {
    Genome.x[i] = (float)random(X_MIN,X_MAX);
    Genome.sigma[i]=(float)random(0.,0.5);
  }
\end

Genome Crossover

Description

Binary crossover that results in the production of a single child.

The child is initialized by cloning the first parent.

Uses parent1 and parent 2 EASEA variables to access the parents genome.

Uses the child EASEA variable to access the child's genome.

EASEA syntax

\GenomeClass::crossover :
     ...
\end

Example

\GenomeClass::crossover :
  for (int i=0; i<SIZE; i++)
  {
    float alpha = (float)random(0.,1.); // barycentric crossover
    child.x[i] = alpha*parent1.x[i] + (1.-alpha)*parent2.x[i];
  }
\end

Genome mutator

Description

Must return the number of mutations.

Uses the Genome variable to access the individual's genome.

EASEA syntax

\GenomeClass::mutator :
     ...
\end

Example

\GenomeClass::mutator : // Must return the number of mutations
  int NbMut=0; 
  float pond = (float)random(0.,1.);
  for (int i=0; i<SIZE; i++) {
    if (tossCoin(pMutPerGene)){
      NbMut++;
      Genome[i] += pond;
     }
  }
  return NbMut;
\end

Genome Evaluator

The evaluation function is expected to be autonomous and independent from the rest of the code, for correct parallelization.

Description

Must return the fitness of the individual.

Uses the Genome defined variable to access the individual's genome.

EASEA syntax

\GenomeClass::evaluator :
     ...
\end

Example

\GenomeClass::evaluator :
 float Score= 0.0;
 Score= Weierstrass(Genome.x, SIZE);
 return Score;
\end

Genome Display

Description

Uses the Genome variable to access the individual's genome.

EASEA syntax

\GenomeClass::display :
     ...
\end

Example

\GenomeClass::display :
  for( size_t i=0 ; i<SIZE ; i++){
    cout << Genome.x[i] << ":" <<  "|";
  }
  cout << Genome.fitness <<< "\n";
\end

User definition fields

User Declarations

Description

This is the section where the user can declare some global variables and some global function.

EASEA syntax

\User declarations :
     ...
\end

Example

\User declarations :
  #define SIZE 100                              //Problem size
  #define Abs(x) ((x) < 0 ? -(x) : (x))   //Definition of the Abs global function
  #define MAX(x,y) ((x)>(y)?(x):(y))     //Definition of the MAX global function
  #define MIN(x,y) ((x)<(y)?(x):(y))      //Definition of the MIN global function
  #define PI 3.141592654                 //Definition of the PI global variable
\end

User functions

Description

This is the section where the user can declare the different functions he will need.

EASEA syntax

\User functions :
     ...
\end

Example

\User functions :
  float gauss()
  /* Generates a normally distributed random value with variance 1 and 0 mean.
      Algorithm based on "gasdev" from Numerical recipes' pg. 203. */
  {
    int iset = 0;
    float gset = 0.0;
    float v1 = 0.0, v2 = 0.0, r = 0.0;
    float factor = 0.0;
    if (iset) {
      iset = 0;
      return gset;
    }
    else {    
      do {
         v1 = (float)random(0.,1.) * 2.0 - 1.0;
         v2 = (float)random(0.,1.) * 2.0 - 1.0;
         r = v1 * v1 + v2 * v2;
      } 
      while (r > 1.0);
      factor = sqrt (-2.0 * log (r) / r);
      gset = v1 * factor;
      iset = 1;
      return (v2 * factor);
    }
  }
\end

User Classes

Description

This is the section where the user will be able to declare:

  1. The genome of the individuals trough the GenomeClass class
  2. Different classes that will be needed.

The GenomeClass field has to be present and ideally not empty. All the variables defined in this field (the genome) will be accessible in several other fields using the 'Genome' variable. Other "hidden" variables can be accessed such as:

    1. The fitness (variable: fitness. Ex: Genome.fitness)

EASEA syntax

\User Class :
     ...
  GenomeClass{
     ...
  }
\end

Example

\User classes:
  Element     { 
    int     Value;
    Element *pNext; }
  GenomeClass { 
    Element *pList; 
    int     Size;   }
\end

User Makefile

Description

This section allows the user to add some flags to the compiler typically to include some custom libraries.

Two flags of the Makefile are accessible to the user in this section:

  1. CPPFLAGS
  2. LDFLAGS

EASEA syntax

\User Makefile options :
     ...
\end

Example

\User Makefile options :
  CPPLAGS += -llibrary
  LDFLAGS += -I/path/to/include
\end

Miscellaneous fields

Before everything else function

Description

This function will be called at the start of the algorithm before the parent initialization.

EASEA syntax

\Before everything else function :
     ...
\end

After everything else function

Description

This function will be called once the last generation has finished.

The population can be accessed.

EASEA syntax

\After everything else function :
     ...
\end

At the beginning of each generation function

Description

This function will be called every generation before the reproduction phase.

The population can be accessed.

EASEA syntax

\At the  beginning of each generation function :
     ...
\end

At the end of each generation function

Description

This function will be called at every generation after the printing of generation statistics.

The population can be accessed.

EASEA syntax

\At the end of each generation function :
     ...
\end

At each generation before reduce function

Description

This function will be called at every generation before performing the different population reductions.

The parent population AND the offspring population can be accessed (merged into a single population).

EASEA syntax

\At every generation before reduce function :
     ...
\end

Memetic specific field

Genome Optimiser

Description

The optimiser field is a Genome specific field. It is meant to contain the function defining the way an individual will be locally optimized n times. The function will hence be called sequentially as many times as the user desires for each individual.

EASEA gives the user two possibilities when designing their local optimization function :

  1. The user can choose to design the function that will enhance the genome of their individuals only in which case the rest of the local optimizer (i.e. creating the local optimizing loop, checking if an individual has improved or not, storing temporary individuals, calling of the evaluation function, etc ...) will be taken care of by the EASEA memetic algorithm. The function will have to be called as many times as specified by the Number of optimisation iterations parameter.
  2. The user can choose to write the complete local optimizer. This way, he will have the complete freedom to design a more complex and specific optimizer, but he will also have to deal with the creation of the local optimization loop, the management of temporary individuals, the calling of the evaluation function etc... The Number of optimisation iterations parameter will have to be set to 1 as the function desigend by the user will contain it's own optimization loop requiring it's own specific number of optimization iterations.

EASEA syntax

\GenomeClass::optimiser :
     ...
\end

Examples

The two following examples will expose the two different ways the optimizer field can be used. The first example will show a simple mutation function. The second example will show the design of a complete local optimizer. Both examples are GPU compatible.

Genome optimization only
\GenomeClass::optimiser :
 float pas = 0.001;
 Genome.x[currentIteration%SIZE]+=pas;
\end

This example shows a simple mutation function that will add a small variation to one of the genes of an individual. The call to this function will be followed by a call to the evaluation function, and a replacement process. If the modification of the genome has improved the individual, it will replace the original one. This is being taken care of by the EASEA memetic algorithm.

Complete local optimizer
\GenomeClass : : optimiser	:	//	Optimises	the	Genome 
 float pas=0.001;
 float fitnesstmp = Genome.fitness ; 
 float tmp[SIZE]; 
 int index = 0;
 for(int i=0; i<SIZE; i++) 
  tmp[ i ] = Genome.x[ i ];
 for(int i=0; i<100; i++){ 
  tmp[index] += pas;
  fitnesstmp = Weierstrass(tmp, SIZE);
  if(fitnesstmp < Genome.fitness){ 
   Genome. fitness = fitnesstmp ;
   Genome.x[ index ] = tmp[ index ];
  }
  else {
   fitnesstmp = Genome.fitness;
   tmp[ index ] = Genome.x[ index ];
  
   if( pas < 0 )
    index = ( index + 1)%SIZE;
    
   pas *= -1;
  }
 }
\ end

This example shows how to design a complete local optimization function. The genome is almost being changed in the same way as in the first example.