Merge branch 'dev'
This commit is contained in:
		@@ -81,6 +81,9 @@ namespace BitEvolver
 | 
				
			|||||||
		//	Reset kiddo's fitness
 | 
							//	Reset kiddo's fitness
 | 
				
			||||||
		kiddo->ResetFitness();
 | 
							kiddo->ResetFitness();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							//	Increment kiddo's generation number
 | 
				
			||||||
 | 
							kiddo->IncrementGenerationNumber();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		return kiddo;
 | 
							return kiddo;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,6 +26,11 @@ namespace BitEvolver
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		//
 | 
							//
 | 
				
			||||||
		this->random = _random;
 | 
							this->random = _random;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//
 | 
				
			||||||
 | 
							this->generation_number = 1;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//
 | 
				
			||||||
		this->SetBitCount(_bits);
 | 
							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)
 | 
						void Chromosome::SetBitCount(int count)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -122,6 +148,36 @@ namespace BitEvolver
 | 
				
			|||||||
		this->bits[index] = b;
 | 
							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()
 | 
						void Chromosome::ResetFitness()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -210,6 +266,7 @@ namespace BitEvolver
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		//
 | 
							//
 | 
				
			||||||
		this->random = other.random;
 | 
							this->random = other.random;
 | 
				
			||||||
 | 
							this->generation_number = other.generation_number;
 | 
				
			||||||
		this->bits = other.bits;
 | 
							this->bits = other.bits;
 | 
				
			||||||
		this->bits_count_desired = other.bits_count_desired;
 | 
							this->bits_count_desired = other.bits_count_desired;
 | 
				
			||||||
		this->fitness = other.fitness;
 | 
							this->fitness = other.fitness;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								Chromosome.h
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Chromosome.h
									
									
									
									
									
								
							@@ -19,6 +19,9 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
namespace BitEvolver
 | 
					namespace BitEvolver
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						using std::string;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
	class Chromosome
 | 
						class Chromosome
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -32,6 +35,11 @@ namespace BitEvolver
 | 
				
			|||||||
			void Reset();
 | 
								void Reset();
 | 
				
			||||||
			void Randomize();
 | 
								void Randomize();
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
 | 
								//
 | 
				
			||||||
 | 
								void SetGenerationNumber(int g);
 | 
				
			||||||
 | 
								void IncrementGenerationNumber();
 | 
				
			||||||
 | 
								int GetGenerationNumber();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
			//
 | 
								//
 | 
				
			||||||
			void SetBitCount(int count);
 | 
								void SetBitCount(int count);
 | 
				
			||||||
			int GetBitCount();
 | 
								int GetBitCount();
 | 
				
			||||||
@@ -42,6 +50,7 @@ namespace BitEvolver
 | 
				
			|||||||
			//
 | 
								//
 | 
				
			||||||
			bool GetBit(int index);
 | 
								bool GetBit(int index);
 | 
				
			||||||
			void SetBit(int index, bool b);
 | 
								void SetBit(int index, bool b);
 | 
				
			||||||
 | 
								void SetBits(string s);
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			//
 | 
								//
 | 
				
			||||||
			void ResetFitness();
 | 
								void ResetFitness();
 | 
				
			||||||
@@ -69,6 +78,9 @@ namespace BitEvolver
 | 
				
			|||||||
			//	Random number generator
 | 
								//	Random number generator
 | 
				
			||||||
			std::shared_ptr<class Random> random;
 | 
								std::shared_ptr<class Random> random;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
 | 
								//
 | 
				
			||||||
 | 
								int generation_number;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
			//
 | 
								//
 | 
				
			||||||
			std::vector<bool> bits;
 | 
								std::vector<bool> bits;
 | 
				
			||||||
			int bits_count_desired;
 | 
								int bits_count_desired;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user