Beispiel #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;
}
Beispiel #2
0
GAGenome *
GA2DBinaryStringGenome::clone(GAGenome::CloneMethod flag) const {
  GA2DBinaryStringGenome *cpy = new GA2DBinaryStringGenome(nx,ny);
  if(flag == CONTENTS){
    cpy->copy(*this);
  }
  else{
    cpy->GAGenome::copy(*this);
    cpy->minX = minX; cpy->minY = minY; 
    cpy->maxX = maxX; cpy->maxY = maxY; 
  }
  return cpy;
}
Beispiel #3
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);
}