Onemax.ez code

De
Révision datée du 10 avril 2020 à 22:57 par Collet (discussion | contributions)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à la navigation Aller à la recherche
/*___________________________________________________________________

onemax.ez // Evolve individuals containing 111111111111111111...
You can use C or C++ syntax colouring in your preferred editor
Code by Pierre Collet, 10/04/2020
_____________________________________________________________________*/

\User declarations :               // section inserted at the very beginning of the object source code
#define SIZE 1000                  // meaning that you can use macros or define global variables
float fPROB_MUT_PER_GENE=1/(float)SIZE;
\end

\User functions:
\end

\User CUDA:
\end

\Before everything else function:
\end

\After everything else function:
\end

\At the beginning of each generation function:
\end

\At the end of each generation function:
\end

\At each generation before reduce function:
\end

\User classes :
GenomeClass { 
  int x[SIZE];                     // an integer array of 1000 integers we will use as bits
}
\end

\GenomeClass::display:
\end

\GenomeClass::initialiser :        // "initializer" is also accepted
  for (int i=0; i<SIZE; i++)       // The easea random function yields back values
    Genome.x[i] = random(0,2);     // of the same type as its parameters in a range
                                   // excluding the second boundary (here // [0,2[)
\end

\GenomeClass::crossover :          // uses parent1, parent2 and child, already initialized to parent1
  int nLocus=random(1,SIZE);       // single point crossover
  for (int i=nLocus;i<SIZE;i++) child.x[i]=parent2.x[i]; // only need to take the values from parent 2
\end

\GenomeClass::mutator :             // The individual to be mutated is called Genome
                                    // We go through each gene and decide whether it should be mutated or not
  for (int i=0;i<SIZE;i++)          // using an easea-provided "tosscoin" function
    if (tossCoin(fPROB_MUT_PER_GENE)) Genome.x[i]=(Genome.x[i]+1)%2;
\end

\GenomeClass::evaluator :
  float fScore=0;                   // A standard score for the onemax is the sum of the bits
  for (int i=0;i<SIZE;i++) fScore+=Genome.x[i];
  return fScore;
\end

\User Makefile options: 
\end

\Default run parameters :
  Number of generations : 100      // NB_GEN
  Time limit: 0 		               // In seconds, 0 to deactivate
  Population size : 100			       // can be accessed as POP_SIZE variable in the code
  Offspring size : 99              // a percentage can also be specified: 99%
  Mutation probability : 1         // MUT_PROB can be used in the code
  Crossover probability : 1        // XOVER_PROB can be used in the code
  Evaluator goal : maximise        // or minimise, depending on the problem
  Selection operator: Tournament 2 // how to select parents to create offspring
  Surviving parents: 1             // how many parents should compete with offspring for the next generation
  Surviving offspring: 100%        // competing offspring for the next generation
  Reduce parents operator: Tournament 2   // how to select breeders
  Reduce offspring operator: Tournament 2 // how to select competing offspring
  Final reduce operator: Tournament 2     // how to select individuals for the next
                                          // generation from parents + offspring

  Elitism: Strong		               // Weak (from parents + offspring) or Strong (from parents only)
  Elite: 1                         // how many individuals in the elite
  Print stats: true				         // print out the generations
  Generate csv stats file:false		 // self explanatory
  Generate gnuplot script:false    // self explanatory
  Generate R script:false          // self explanatory
  Plot stats:true                  // for a dynamic plot of the execution 

  Remote island model: false       // for activating individual exchanges between islands
  IP file: ip.txt 			           // File containing a list of remote island's IPs and ports
  Server port : 2929               // default server port
  Migration probability: 0.3       // probability to send an individual at each generation

  Save population: false           // for restarts
  Start from file:false            // for restarts
\end