Ejemplo n.º 1
0
// this function returns an int from a binary string
unsigned int getIntFrom2DBinaryString(const GA2DBinaryStringGenome &genome,unsigned int row)
{
     unsigned int intval = 0;
     for(int i=0; i<genome.width(); i++){
        intval <<= 1;
        intval  |= genome.gene(i, row) & 1;
     }
     return intval;
}
Ejemplo n.º 2
0
// This objective function just tries to match the genome to the pattern in the
// user data.
float
objective(GAGenome & c)
{
    GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)c;
    GA2DBinaryStringGenome * pattern =
        (GA2DBinaryStringGenome *)c.userData();

    float value = 0.0;
    for(int i = 0; i < genome.width(); i++)
        for(int j = 0; j < genome.height(); j++)
        {
            value += (float)(genome.gene(i, j) == pattern->gene(i, j));
        }
    return(value);
}