Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Individual Class Reference

This class represent one individual of the complete gen. More...

#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" More...
 
virtual ~Individual ()
 default destructor More...
 
int getID (void) const
 return the ID of the individual More...
 
std::string getName (void) const
 return the name of the individual More...
 
int getSize (void) const
 return the size of the individual. More...
 
GengetGen (int x) const
 return a gen of the individual More...
 
void addGen (Gen *gen)
 add a gen to the individual. More...
 
const std::vector< Gen * > & getGene (void) const
 returns all gens of the individual More...
 
void removeGen (Gen *gen)
 remove a specified gen from the individual More...
 
void removeGen (int x)
 remove a specified gen from the individual More...
 
double getFitness ()
 this function calculate the fitness value of the individual More...
 
double getFitnessC () const
 this function calculate the fitness value of the individual (const) More...
 
void setMutated (void)
 this select the individual as a product of mutation. More...
 
const IndividualgetParent1 (void) const
 returns parent 1 of the individual More...
 
const IndividualgetParent2 (void) const
 returns parent 2 of the individual More...
 
bool isMutated (void) const
 test if the individual a product of mutation More...
 
std::string IndividualToString (void) const
 returns a string, which repesent the individual (for logging) More...
 
std::string RootToString (bool withMutation=true) const
 returns a string with the parents and a mark for mutation More...
 
bool isFitnessCalculated () const
 returns the m_fitnessCalculated flag, which represent, that the fitness value was calculated before. More...
 
bool store (FILE *f) const
 store the individual in a file More...
 

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, std::vector< Individual * > &storage)
 restore all individual from a restore structure More...
 
static bool restoreParent (int numberIndividuals, std::map< int, RESTORE_GA_INDIVIDUAL * > &individualSet)
 restore the parent links from a restore structure More...
 

Protected Attributes

std::string m_name
 the name of the individual More...
 
int m_ID
 the ID of the individual More...
 
std::vector< Gen * > m_gene
 the gens inside the individual More...
 
Individualm_parent1
 parent 1 More...
 
Individualm_parent2
 parent 2 More...
 
bool m_mutated
 remember if the individual a product of mutation More...
 
bool m_fitnessCalculated
 remember if the fitness value was calculated More...
 
double m_fitness
 save the calculated fitness value More...
 

Detailed Description

This class represent one individual of the complete gen.

alg. It have some gens and a fitness.

Constructor & Destructor Documentation

Individual ( std::string  name,
int  id,
Individual p1 = 0,
Individual p2 = 0 
)

constructor Create the individual with the name "name"

Parameters
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

Member Function Documentation

void addGen ( Gen gen)
inline

add a gen to the individual.

Parameters
gen(Gen*) the new gen
double getFitness ( )

this function calculate the fitness value of the individual

Returns
fitness value
double getFitnessC ( ) const

this function calculate the fitness value of the individual (const)

Returns
fitness value
Gen* getGen ( int  x) const
inline

return a gen of the individual

Parameters
x(the index of the gen
Returns
(Gen*) the searched gen. NULL if the index isn't right
const std::vector<Gen*>& getGene ( void  ) const
inline

returns all gens of the individual

Returns
(vector<Gen*>&) all gens
int getID ( void  ) const
inline

return the ID of the individual

Returns
(int) the ID
std::string getName ( void  ) const
inline

return the name of the individual

Returns
(string) the name
const Individual* getParent1 ( void  ) const
inline

returns parent 1 of the individual

Returns
(Individual*) parent 1 (could be zero if individual a random generation)
const Individual* getParent2 ( void  ) const
inline

returns parent 2 of the individual

Returns
(Individual*) parent 2 (could be zero if individual a random generation)
int getSize ( void  ) const
inline

return the size of the individual.

This mean the number of gens inside the individual.

Returns
(int) number of gens
std::string IndividualToString ( void  ) const

returns a string, which repesent the individual (for logging)

Returns
(string) the string representation of the individual
bool isFitnessCalculated ( ) const
inline

returns the m_fitnessCalculated flag, which represent, that the fitness value was calculated before.

Returns
(bool) the flag m_fitnessCalculated
bool isMutated ( void  ) const
inline

test if the individual a product of mutation

Returns
(bool) true if it a product of mutation
void removeGen ( Gen gen)

remove a specified gen from the individual

Parameters
gen(Gen*) the gen which should removed from the individual
void removeGen ( int  x)

remove a specified gen from the individual

Parameters
x(the index of the gen, which should b removed.
bool restore ( int  numberIndividuals,
std::map< int, std::string > &  nameSet,
std::map< int, RESTORE_GA_INDIVIDUAL * > &  individualSet,
std::map< int, std::vector< int > > &  linkSet,
std::vector< Individual * > &  storage 
)
static

restore all individual from a restore structure

Parameters
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
Returns
(bool) true if all ok
bool restoreParent ( int  numberIndividuals,
std::map< int, RESTORE_GA_INDIVIDUAL * > &  individualSet 
)
static

restore the parent links from a restore structure

Parameters
numberIndividuals(int) number of individuals which should be restored
individualSet(map<int,RESTORE_GA_INDIVIDUAL*> the structures which should be restored
Returns
(bool) true if all ok
std::string RootToString ( bool  withMutation = true) const

returns a string with the parents and a mark for mutation

Parameters
withMutation(bool) should mutation part of the string
Returns
(string) the result
void setMutated ( void  )
inline

this select the individual as a product of mutation.

bool store ( FILE *  f) const

store the individual in a file

Parameters
f(FILE) the file to store in
Returns
(bool) return true if ok

Member Data Documentation

double m_fitness
protected

save the calculated fitness value

bool m_fitnessCalculated
protected

remember if the fitness value was calculated

std::vector<Gen*> m_gene
protected

the gens inside the individual

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


The documentation for this class was generated from the following files: