Remember Chromosome's generation; Allow set bits by string

This commit is contained in:
2018-05-02 03:12:40 -07:00
parent b635429aff
commit 020c9e458d
2 changed files with 69 additions and 0 deletions

View File

@ -26,6 +26,11 @@ namespace BitEvolver
{
//
this->random = _random;
//
this->generation_number = 1;
//
this->SetBitCount(_bits);
//
@ -55,6 +60,27 @@ namespace BitEvolver
}
}
//
void Chromosome::SetGenerationNumber(int g)
{
//
this->generation_number = g;
}
//
void Chromosome::IncrementGenerationNumber()
{
//
this->generation_number++;
}
//
int Chromosome::GetGenerationNumber()
{
//
return this->generation_number;
}
//
void Chromosome::SetBitCount(int count)
{
@ -122,6 +148,36 @@ namespace BitEvolver
this->bits[index] = b;
}
//
void Chromosome::SetBits(string s)
{
//
std::unique_lock<std::recursive_mutex> lock(this->modification_mutex);
size_t i;
char c;
//
this->SetBitCount( (int) s.size() );
//
for ( i=0; i<s.size(); i++ ) {
//
c = s[i];
if ( c == '1' ) {
this->bits[i] = true;
}
else if ( c == '0' ) {
this->bits[i] = false;
}
else{
stringstream ss;
ss << "Chromosome::SetBits() - Invalid character '" << c << "' (" << (int)c << ") in bit string input";
throw std::runtime_error( ss.str() );
}
}
}
//
void Chromosome::ResetFitness()
{
@ -210,6 +266,7 @@ namespace BitEvolver
//
this->random = other.random;
this->generation_number = other.generation_number;
this->bits = other.bits;
this->bits_count_desired = other.bits_count_desired;
this->fitness = other.fitness;