Basic onemax
Aller à la navigation
Aller à la recherche
/*_________________________________________________________
onemax.ez // Evolve individuals containing 111111111111111111...
__________________________________________________________*/
\User declarations :
#define SIZE 1000
float pMutPerGene=1.0/SIZE; // Good probability of mutation per gene on an unknown problem
\end
\User functions:
\end
\User CUDA:
\end
\Before everything else function:
// read some input file here
\end
\After everything else function:
// save the results in a file here
\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 { // Reserved class name
int x[SIZE];
}
\end
\GenomeClass::display:
\end
\GenomeClass::initialiser : // "initializer" is also accepted
for(int i=0; i<SIZE; i++ )
Genome.x[i] = random(0,2); // random function returns a value in [x,y[
\end
\GenomeClass::crossover : // Reserved variable child is a clone of parent1
int nLocus=random(1,SIZE); // It is only needed to insert values from parent 2
for (int i=nLocus;i<SIZE;i++) // into the child
child.x[i]=parent2.x[i];
\end
\GenomeClass::mutator : // Must return a value (for historical reasons)
for (int i=0;i<SIZE;i++)
if (tossCoin(pMutPerGene)) // tosscoin(p) will return 1 with p probability
Genome.x[i]=(Genome.x[i]+1)%2;
return 3; // Any value will do
\end
\GenomeClass::evaluator : // Returns the score
float fScore=0;
for (int i=0;i<SIZE;i++)
fScore+=Genome.x[i]; // for a onemax, the score is the sum of the genes
return fScore;
\end
\User Makefile options:
\end
\Default run parameters : // Many of these parameters are command line parameters
Number of generations : 100 // NB_GEN global variable in the code
Time limit: 0 // In seconds, 0 to deactivate
Population size : 100 // POP_SIZE global variable in the code
Offspring size : 100 // percentage (with %) or absolute (without)
Mutation probability : 1 // MUT_PROB global variable in the code
Crossover probability : 1 // XOVER_PROB global variable in the code
Evaluator goal : maximise // or minimise
Surviving parents: 100% // selection of breeders
Reduce parents operator: Tournament 2
Selection operator: Tournament 2 // parents selection to create offspring population
Surviving offspring: 100% // selection of offspring for populating next generation
Reduce offspring operator: Tournament 2
Final reduce operator: Tournament 2 // selection from parents and offspring to create next generation
Elitism: Strong // or Weak
Elite: 1
Print stats: true // or false
Generate csv stats file: false
Generate gnuplot script: false
Generate R script:false
Plot stats:true // Default false
Remote island model: false
IP file: ip.txt // File containing all the remote island's IP
Server port : 2929
Migration probability: 0.3
Save population: false
Start from file:false
\end