#include <Individual.h>
Collaboration diagram for Individual:
Public Member Functions | |
Individual (std::string name, int id, Individual *p1=0, Individual *p2=0) | |
constructor Create the individual with the name "name" | |
virtual | ~Individual () |
default destructor | |
int | getID (void) const |
return the ID of the individual | |
std::string | getName (void) const |
return the name of the individual | |
int | getSize (void) const |
return the size of the individual. | |
Gen * | getGen (int x) const |
return a gen of the individual | |
void | addGen (Gen *gen) |
add a gen to the individual. | |
const std::vector< Gen * > & | getGene (void) const |
returns all gens of the individual | |
void | removeGen (Gen *gen) |
remove a specified gen from the individual | |
void | removeGen (int x) |
remove a specified gen from the individual | |
double | getFitness () |
this function calculate the fitness value of the individual | |
double | getFitnessC () const |
this function calculate the fitness value of the individual (const) | |
void | setMutated (void) |
this select the individual as a product of mutation. | |
const Individual * | getParent1 (void) const |
returns parent 1 of the individual | |
const Individual * | getParent2 (void) const |
returns parent 2 of the individual | |
bool | isMutated (void) const |
test if the individual a product of mutation | |
std::string | IndividualToString (void) const |
returns a string, which repesent the individual (for logging) | |
std::string | RootToString (bool withMutation=true) const |
returns a string with the parents and a mark for mutation | |
bool | isFitnessCalculated () const |
returns the m_fitnessCalculated flag, which represent, that the fitness value was calculated before. | |
bool | store (FILE *f) const |
store the individual in a file | |
Static Public Member Functions | |
static bool | restore (int numberIndividuals, std::map< int, std::string > &nameSet, std::map< int, RESTORE_GA_INDIVIDUAL * > &individualSet, std::map< int, std::vector< int > > &linkSet) |
restore all individual from a restore structure | |
static bool | restoreParent (int numberIndividuals, std::map< int, RESTORE_GA_INDIVIDUAL * > &individualSet) |
restore the parent links from a restore structure | |
Protected Attributes | |
std::string | m_name |
the name of the individual | |
int | m_ID |
the ID of the individual | |
std::vector< Gen * > | m_gene |
the gens inside the individual | |
Individual * | m_parent1 |
parent 1 | |
Individual * | m_parent2 |
parent 2 | |
bool | m_mutated |
remember if the individual a product of mutation | |
bool | m_fitnessCalculated |
remember if the fitness value was calculated | |
double | m_fitness |
save the calculated fitness value |
alg. It have some gens and a fitness.
Individual | ( | std::string | name, | |
int | id, | |||
Individual * | p1 = 0 , |
|||
Individual * | p2 = 0 | |||
) |
constructor Create the individual with the name "name"
name | (sting) the name of the new individual | |
id | (int) an unique ID | |
p1 | (Individual*) parent 1 or zero if it random generate | |
p2 | (Individual*) parent 2 or zero if it random generate |
~Individual | ( | ) | [virtual] |
default destructor
void addGen | ( | Gen * | gen | ) | [inline] |
add a gen to the individual.
gen | (Gen*) the new gen |
double getFitness | ( | ) |
this function calculate the fitness value of the individual
double getFitnessC | ( | ) | const |
this function calculate the fitness value of the individual (const)
Gen* getGen | ( | int | x | ) | const [inline] |
return a gen of the individual
x | (the index of the gen |
const std::vector<Gen*>& getGene | ( | void | ) | const [inline] |
returns all gens of the individual
int getID | ( | void | ) | const [inline] |
return the ID of the individual
std::string getName | ( | void | ) | const [inline] |
return the name of the individual
const Individual* getParent1 | ( | void | ) | const [inline] |
returns parent 1 of the individual
const Individual* getParent2 | ( | void | ) | const [inline] |
returns parent 2 of the individual
int getSize | ( | void | ) | const [inline] |
return the size of the individual.
This mean the number of gens inside the individual.
std::string IndividualToString | ( | void | ) | const |
returns a string, which repesent the individual (for logging)
bool isFitnessCalculated | ( | ) | const [inline] |
returns the m_fitnessCalculated flag, which represent, that the fitness value was calculated before.
bool isMutated | ( | void | ) | const [inline] |
test if the individual a product of mutation
void removeGen | ( | int | x | ) |
remove a specified gen from the individual
x | (the index of the gen, which should b removed. |
void removeGen | ( | Gen * | gen | ) |
remove a specified gen from the individual
gen | (Gen*) the gen which should removed from the individual |
bool restore | ( | int | numberIndividuals, | |
std::map< int, std::string > & | nameSet, | |||
std::map< int, RESTORE_GA_INDIVIDUAL * > & | individualSet, | |||
std::map< int, std::vector< int > > & | linkSet | |||
) | [static] |
restore all individual from a restore structure
numberIndividuals | (int) number of individuals which should be restored | |
nameSet | (map<int,string>) names of the individuals | |
individualSet | (map<int,RESTORE_GA_INDIVIDUAL*> the structures which should be restored | |
linkSet | (map<int,vector<int>>) the linkings between the individual and the genes |
bool restoreParent | ( | int | numberIndividuals, | |
std::map< int, RESTORE_GA_INDIVIDUAL * > & | individualSet | |||
) | [static] |
restore the parent links from a restore structure
numberIndividuals | (int) number of individuals which should be restored | |
individualSet | (map<int,RESTORE_GA_INDIVIDUAL*> the structures which should be restored |
std::string RootToString | ( | bool | withMutation = true |
) | const |
returns a string with the parents and a mark for mutation
withMutation | (bool) should mutation part of the string |
void setMutated | ( | void | ) | [inline] |
this select the individual as a product of mutation.
bool store | ( | FILE * | f | ) | const |
store the individual in a file
f | (FILE) the file to store in |
double m_fitness [protected] |
save the calculated fitness value
bool m_fitnessCalculated [protected] |
remember if the fitness value was calculated
int m_ID [protected] |
the ID of the individual
bool m_mutated [protected] |
remember if the individual a product of mutation
std::string m_name [protected] |
the name of the individual
Individual* m_parent1 [protected] |
parent 1
Individual* m_parent2 [protected] |
parent 2