Chromosome class for genetic algorithm. More...
#include <GA/GAChromosome.H>
Public Member Functions | |
Constructor, destructor and initialization. | |
GAChromosome () | |
Uninitialized constructor. Need to call resize() later. | |
GAChromosome (const int N, const int *a) | |
Construct from C array. | |
GAChromosome (const int N) | |
Construct random chromosome. | |
GAChromosome (const GAChromosome &c) | |
Copy constructor. | |
void | resize (const int N) |
Change size, do not initialize. | |
void | init (const int N, const int *a) |
Initialize from C array. | |
void | init (const int N) |
Initialize randomly. | |
~GAChromosome () | |
Destructor. | |
Acces functions | |
int | get_size () const |
Return the size of the chromosome. | |
void | set_gene (const int i, const int a) |
Set the gene i to a. | |
int | get_gene (const int i) const |
Return the gene i. | |
void | set_fitness (const float a) |
Set the fitness to a. | |
float | get_fitness () const |
Return the fitness. | |
void | set_linear_fitness (const float a) |
Set the linear fitness to a. | |
float | get_linear_fitness () const |
Return the linear fitness. | |
void | set_breedings (const int a) |
Set breedings to a. | |
int | get_breedings () const |
Return the breedings. | |
Operators overloading | |
GAChromosome & | operator= (const GAChromosome &c) |
Overload of assignment operator. | |
bool | operator< (const GAChromosome &c) const |
Overload of less-than operator. | |
Evolve functions | |
void | mutation () |
Change one gene randomly. | |
void | add_breeding () |
Add one breeding. | |
void | use_breeding () |
Use one breeding. | |
Friends | |
std::istream & | operator>> (std::istream &in, GAChromosome &c) |
<< overloading. | |
std::ostream & | operator<< (std::ostream &in, GAChromosome &c) |
>> overloading. |
Chromosome class for genetic algorithm.
This is a chromosome class for genetic algorithm, which is an array of genes (int with value of -1, 0 or 1).
Definition at line 47 of file GAChromosome.H.
GAChromosome::GAChromosome | ( | ) |
Uninitialized constructor. Need to call resize() later.
Definition at line 48 of file GAChromosome.C.
GAChromosome::GAChromosome | ( | const int | N, | |
const int * | a | |||
) |
GAChromosome::GAChromosome | ( | const int | N | ) |
GAChromosome::GAChromosome | ( | const GAChromosome & | c | ) |
GAChromosome::~GAChromosome | ( | ) |
Destructor.
Definition at line 91 of file GAChromosome.C.
void GAChromosome::add_breeding | ( | ) |
Add one breeding.
Definition at line 166 of file GAChromosome.C.
Referenced by GAPopulation::selection().
int GAChromosome::get_breedings | ( | ) | const |
Return the breedings.
Definition at line 141 of file GAChromosome.C.
Referenced by GAPopulation::crossover().
float GAChromosome::get_fitness | ( | ) | const |
Return the fitness.
Definition at line 119 of file GAChromosome.C.
Referenced by GAPopulation::compute_sigma(), and GAPopulation::linear_scaling().
int GAChromosome::get_gene | ( | const int | i | ) | const |
float GAChromosome::get_linear_fitness | ( | ) | const |
Return the linear fitness.
Definition at line 130 of file GAChromosome.C.
Referenced by GAPopulation::selection().
int GAChromosome::get_size | ( | ) | const |
Return the size of the chromosome.
Definition at line 96 of file GAChromosome.C.
Referenced by GAPopulation::set_chromosome().
void GAChromosome::init | ( | const int | N | ) |
void GAChromosome::init | ( | const int | N, | |
const int * | a | |||
) |
Initialize from C array.
Definition at line 78 of file GAChromosome.C.
References resize().
Referenced by GAChromosome(), GAPopulation::init(), and operator=().
void GAChromosome::mutation | ( | ) |
Change one gene randomly.
Definition at line 160 of file GAChromosome.C.
Referenced by GAPopulation::mutate().
bool GAChromosome::operator< | ( | const GAChromosome & | c | ) | const |
Overload of less-than operator.
c1 < c2 if c1 as less breedings than c2
Definition at line 155 of file GAChromosome.C.
GAChromosome & GAChromosome::operator= | ( | const GAChromosome & | c | ) |
void GAChromosome::resize | ( | const int | N | ) |
Change size, do not initialize.
Definition at line 71 of file GAChromosome.C.
Referenced by init(), and operator>>().
void GAChromosome::set_breedings | ( | const int | a | ) |
void GAChromosome::set_fitness | ( | const float | a | ) |
void GAChromosome::set_gene | ( | const int | i, | |
const int | a | |||
) |
Set the gene i to a.
Definition at line 101 of file GAChromosome.C.
Referenced by GAPopulation::crossover().
void GAChromosome::set_linear_fitness | ( | const float | a | ) |
Set the linear fitness to a.
Definition at line 124 of file GAChromosome.C.
References ASSERT.
Referenced by GAPopulation::linear_scaling().
void GAChromosome::use_breeding | ( | ) |
Use one breeding.
Definition at line 171 of file GAChromosome.C.
References ASSERT.
Referenced by GAPopulation::crossover().
std::ostream& operator<< | ( | std::ostream & | in, | |
GAChromosome & | c | |||
) | [friend] |
>> overloading.
Definition at line 196 of file GAChromosome.C.
std::istream& operator>> | ( | std::istream & | in, | |
GAChromosome & | c | |||
) | [friend] |
<< overloading.
Definition at line 177 of file GAChromosome.C.