Individual Class Reference

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

#include <Individual.h>

Collaboration diagram for Individual:

Collaboration graph
[legend]
List of all members.

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.
GengetGen (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 IndividualgetParent1 (void) const
 returns parent 1 of the individual
const IndividualgetParent2 (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
Individualm_parent1
 parent 1
Individualm_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

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 ( int  x  ) 

remove a specified gen from the individual

Parameters:
x (the index of the gen, which should b removed.

void removeGen ( Gen gen  ) 

remove a specified gen from the individual

Parameters:
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

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:
Generated on Fri Oct 30 16:29:02 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7