
Classes | |
class | nObjectiveGreaterThanComparator |
Utility class for generating a function for comparing genotype of an objective. More... | |
Public Member Functions | |
Genotype (unsigned int size=0) | |
Construct a un-initialized Genotype. | |
Genotype (QString, bool compressed=false) | |
Read the values from QString and set the size accordlying to length of QString. | |
Genotype (const Genotype &genotype) | |
Copy-Constructor (generate a clone of the genoma) | |
virtual | ~Genotype () |
Destructor. | |
void | assign (const Genotype *genotype) |
Assign method (it call operator=) | |
bool | bit (unsigned int i) const |
Return the i-th bit. | |
virtual unsigned int | bitToGeneIndex (unsigned int bit) const |
Convert the index of the given bit to the index of the gene that this bit is part of. | |
virtual Genotype * | clone () const |
Create an exact copy of this Genotype. | |
virtual void | configure (ConfigurationParameters ¶ms, QString prefix) |
Configure the object using the ConfigurationParameters specified. | |
bool | dominatedBy (const Genotype *genotype) |
Return True if this Genotype is dominated by the Genotype specified by param. | |
unsigned int | extractUInt (unsigned int startPos, unsigned int stopPos) |
Utility function for extracting an integer value. | |
double | fitness () const |
Return the fitness of this Genotype. | |
bool | fromCompressedString (QString str) |
Read from compressed data with toCompressedString() | |
void | fromString (QString) |
Configure the bits accordlying to its string representation passed. | |
virtual unsigned int | geneToBitIndex (unsigned int gene) const |
Convert the index of the given gene to the index of the start of the bit(s) that encode this gene. | |
int | hammingDistance (const Genotype *) |
Calculate the Hamming distance from the Genotype. | |
void | insertUInt (unsigned int value, unsigned int startPos, unsigned int stopPos) |
Utility function for settings an integer value into Genotype. | |
QString | notes () const |
Return the notes of this Genotype. | |
int | numOfObjectives () const |
Return the number of Objectives setted The number of objectives is automatically configured by setObjective method. | |
double | objective (int i) const |
Return the value of the i-th objective of the fitness. | |
virtual Genotype & | operator= (const Genotype &genotype) |
Assign operator (performs same operation of Copy-constructor) Due to virtual attribute, Subclasses can customize the behaviour of this operator=, for an easy way to copy Genotype data the protected method copyDataFrom is provided and it behaves like this implementation of operator=. | |
virtual void | randomize () |
Randomize the value contained (attention, this method destroys previous data) | |
double | rank () const |
Return the rank of this Genotype. | |
virtual void | save (ConfigurationParameters ¶ms, QString prefix) |
Save the actual status of parameters into the ConfigurationParameters object passed. | |
void | set (unsigned int i) |
Set to One the i-th bit. | |
void | setFitness (double value) |
Set the fitness value of this Genotype. | |
void | setNotes (QString notes) |
Set the notes of this Genotype. | |
void | setObjective (int i, double value) |
Set the i-th objective value of the (multi-objective) fitness. | |
void | setRank (double rank) |
Set the rank of the genotype. | |
unsigned int | size () const |
Return the size of Genotype. | |
QString | toCompressedString () const |
Compress the data; It return a printable String. | |
void | toggle (unsigned int i) |
toggle the i-th bit | |
QString | toString () const |
Return a QString representing this Genotype. | |
void | unset (unsigned int i) |
set to zero the i-th bit | |
![]() | |
void | addObserver (RuntimeParameterObserver *obs) |
T | getRuntimeParameter (QString paramName) |
virtual ParameterSettableUI * | getUIManager () |
ParameterSettable () | |
virtual void | postConfigureInitialization () |
void | removeObserver (RuntimeParameterObserver *obs) |
void | setRuntimeParameter (QString paramName, T newvalue) |
QString | typeName () const |
![]() | |
void | addObserver (RuntimeParameterObserver *obs) |
T | getRuntimeParameter (QString paramName) |
void | removeObserver (RuntimeParameterObserver *obs) |
void | setRuntimeParameter (QString paramName, T newvalue) |
QString | typeName () const |
Static Public Member Functions | |
static void | describe (QString type) |
Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups. | |
static bool | rankGreaterThanComparator (const Genotype *g1, const Genotype *g2) |
Utility function comparing two genotype pointers on their rank. | |
![]() | |
static void | describe (QString type) |
static QString | fullParameterDescriptionPath (QString type, QString param) |
static QString | fullSubgroupDescriptionPath (QString type, QString sub) |
![]() | |
static void | describe (QString type) |
static QString | fullParameterDescriptionPath (QString type, QString param) |
static QString | fullSubgroupDescriptionPath (QString type, QString sub) |
Protected Member Functions | |
void | copyDataFrom (Genotype *source) |
Utility method for copying data among Genotype. | |
void | resize (unsigned int newsize) |
Resize the Genotype. | |
![]() | |
void | notifyChangesToParam (QString paramName) |
![]() | |
void | notifyChangesToParam (QString paramName) |
Protected Attributes | |
unsigned int | allocated |
Allocated memory. | |
unsigned char * | data |
Data represented as a char vector allocated in memory. | |
QVector< double > | fitnessv |
Objective values of the Fitness. | |
QString | notesv |
Notes about this Genotype. | |
double | rankv |
Rank. | |
unsigned int | sizev |
Size. | |
Additional Inherited Members | |
![]() | |
enum | Property |
![]() | |
AllowMultiple | |
Default | |
IsList | |
IsMandatory | |
![]() | |
static const double | Infinity |
static const int | MaxInteger |
static const int | MinInteger |
![]() | |
static Descriptor | addTypeDescription (QString type, QString shortHelp, QString longHelp=QString("")) |
static void | setGraphicalEditor (QString type) |
Detailed Description
Genotype class.
- Description
- Represent a bit-string
- Warnings
Definition at line 38 of file genotype.h.
Constructor & Destructor Documentation
Genotype | ( | unsigned int | size = 0 | ) |
Construct a un-initialized Genotype.
- Warning
- you must explicity call randomize() to get a randomized Genotype
Definition at line 28 of file genotype.cpp.
References Genotype::allocated, Genotype::data, Genotype::fitnessv, Genotype::notesv, Genotype::rankv, Genotype::size(), and Genotype::sizev.
Referenced by Genotype::clone().
|
virtual |
Genotype | ( | QString | str, |
bool | compressed = false |
||
) |
Read the values from QString and set the size accordlying to length of QString.
Definition at line 43 of file genotype.cpp.
References Genotype::allocated, Genotype::data, Genotype::fitnessv, Genotype::notesv, Genotype::rankv, Genotype::sizev, and Genotype::unset().
Copy-Constructor (generate a clone of the genoma)
Definition at line 77 of file genotype.cpp.
References Genotype::allocated, Genotype::data, Genotype::fitnessv, Genotype::notesv, Genotype::rankv, and Genotype::sizev.
Member Function Documentation
void assign | ( | const Genotype * | genotype | ) |
Assign method (it call operator=)
Definition at line 144 of file genotype.cpp.
bool bit | ( | unsigned int | i | ) | const |
Return the i-th bit.
Definition at line 213 of file genotype.cpp.
References Genotype::data.
Referenced by SignedRangeGenotype::at(), Genotype::bitToGeneIndex(), OnePoint::crossover(), Genotype::extractUInt(), Genotype::hammingDistance(), Genotype::toCompressedString(), and Genotype::toString().
|
virtual |
Convert the index of the given bit to the index of the gene that this bit is part of.
Reimplemented in DoubleGenotype.
Definition at line 359 of file genotype.cpp.
References Genotype::bit().
|
virtual |
Create an exact copy of this Genotype.
Reimplemented in RealGenotype, and SignedRangeGenotype.
Definition at line 149 of file genotype.cpp.
References Genotype::Genotype().
Referenced by Genome::append(), Genome::configure(), StefanoSteadyStateGA::gaStep(), Genome::Genome(), Genome::operator=(), and Genome::set().
|
virtual |
Configure the object using the ConfigurationParameters specified.
- Parameters
-
params the object with configuration parameters prefix the group in which parameters are expected to be (this is terminated by a separator character). We expect to receive as prefix the group with genotype parameters
Implements ParameterSettableWithConfigureFunction.
Reimplemented in RealGenotype, and SignedRangeGenotype.
Definition at line 100 of file genotype.cpp.
References Genotype::fitnessv, Genotype::fromCompressedString(), ConfigurationParameters::getValue(), Genotype::notesv, Genotype::rankv, and Genotype::resize().
|
protected |
Utility method for copying data among Genotype.
Definition at line 363 of file genotype.cpp.
References Genotype::allocated, Genotype::data, Genotype::fitnessv, Genotype::notesv, Genotype::rankv, and Genotype::sizev.
Referenced by RealGenotype::operator=(), and SignedRangeGenotype::operator=().
|
static |
Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups.
Definition at line 136 of file genotype.cpp.
References ParameterSettableWithConfigureFunction::addTypeDescription(), ParameterSettable::IntDescriptor::def(), ParameterSettable::Descriptor::describeInt(), ParameterSettable::Descriptor::describeReal(), ParameterSettable::Descriptor::describeString(), ParameterSettable::StringDescriptor::help(), ParameterSettable::RealDescriptor::help(), ParameterSettable::IntDescriptor::help(), ParameterSettableWithConfigureFunction::IsList, ParameterSettableWithConfigureFunction::IsMandatory, ParameterSettable::IntDescriptor::limits(), ParameterSettable::RealDescriptor::props(), and ParameterSettable::IntDescriptor::props().
bool dominatedBy | ( | const Genotype * | genotype | ) |
Return True if this Genotype is dominated by the Genotype specified by param.
- Warning
- the two Genotypes should have the same number of objectives; if this constraint is not meet then the number of objectives compared will be the minimum between the two genotypes
- Note
- Definition of Domination: a Genotype A is dominated by Genotype B iff all objective values of A are less-equal of corresponding objective values of B and for at least one objective the value of A is strictly less that value in B
Definition at line 190 of file genotype.cpp.
References Genotype::fitnessv.
unsigned int extractUInt | ( | unsigned int | startPos, |
unsigned int | stopPos | ||
) |
Utility function for extracting an integer value.
- Parameters
-
startPos is the index of starting position of the bits to decode stopPos is the index of end position of the bits to decode +----------------------------+ | 0 1 0 0 1 0 1 1 0 1 0 1 0 | +----------------------------+
if startPos is 4 and stopPos is 8 the bits 1011 is decode and this methods will returns 11
if stopPos is beyond the length of Genotype, ad example startPos 9 and stopPos 15 then the bits 1010 will be decoded and this methods will return 10.
Definition at line 325 of file genotype.cpp.
References Genotype::bit(), and Genotype::sizev.
Referenced by SignedRangeGenotype::at().
double fitness | ( | ) | const |
Return the fitness of this Genotype.
- Note
- it is the same of objective(0);
Definition at line 173 of file genotype.cpp.
References Genotype::objective().
Referenced by StefanoSteadyStateGA::gaStep().
bool fromCompressedString | ( | QString | str | ) |
Read from compressed data with toCompressedString()
- Returns
- true on successfull decompression, false otherwise
Definition at line 308 of file genotype.cpp.
References Genotype::sizev, and Genotype::unset().
Referenced by RealGenotype::configure(), SignedRangeGenotype::configure(), and Genotype::configure().
void fromString | ( | QString | str | ) |
Configure the bits accordlying to its string representation passed.
Definition at line 287 of file genotype.cpp.
References Genotype::sizev, and Genotype::unset().
|
virtual |
Convert the index of the given gene to the index of the start of the bit(s) that encode this gene.
Reimplemented in DoubleGenotype.
Definition at line 355 of file genotype.cpp.
int hammingDistance | ( | const Genotype * | other | ) |
Calculate the Hamming distance from the Genotype.
Definition at line 260 of file genotype.cpp.
References Genotype::bit(), and Genotype::sizev.
void insertUInt | ( | unsigned int | value, |
unsigned int | startPos, | ||
unsigned int | stopPos | ||
) |
Utility function for settings an integer value into Genotype.
- Parameters
-
value is the value to be converted and inserted into genotype startPos is the index of starting position of the bits to decode stopPos is the index of end position of the bits to decode The parameters has the same meanings of extractUInt, and the behaviour is exactly the opposite.
Definition at line 340 of file genotype.cpp.
References Genotype::sizev, and Genotype::unset().
Referenced by SignedRangeGenotype::set().
QString notes | ( | ) | const |
Return the notes of this Genotype.
Definition at line 252 of file genotype.cpp.
References Genotype::notesv.
Referenced by Genotype::setNotes().
int numOfObjectives | ( | ) | const |
Return the number of Objectives setted The number of objectives is automatically configured by setObjective method.
Definition at line 186 of file genotype.cpp.
References Genotype::fitnessv.
Referenced by GeneticAlgo::updateStats().
double objective | ( | int | i | ) | const |
Return the value of the i-th objective of the fitness.
- Note
- fitness() return the same value of objective(0)
Definition at line 182 of file genotype.cpp.
References Genotype::fitnessv.
Referenced by Genotype::fitness(), Genotype::nObjectiveGreaterThanComparator::operator()(), and GeneticAlgo::updateStats().
Assign operator (performs same operation of Copy-constructor)
Due to virtual attribute, Subclasses can customize the behaviour of this operator=, for an easy way to copy Genotype data the protected method copyDataFrom is provided and it behaves like this implementation of operator=.
Reimplemented in SignedRangeGenotype, and RealGenotype.
Definition at line 87 of file genotype.cpp.
References Genotype::allocated, Genotype::data, Genotype::fitnessv, Genotype::notesv, Genotype::rankv, and Genotype::sizev.
|
virtual |
Randomize the value contained (attention, this method destroys previous data)
Reimplemented in RealGenotype.
Definition at line 268 of file genotype.cpp.
References globalRNG, Genotype::sizev, and Genotype::unset().
double rank | ( | ) | const |
Return the rank of this Genotype.
Definition at line 209 of file genotype.cpp.
References Genotype::rankv.
Referenced by StefanoSteadyStateGA::gaStep(), Genotype::rankGreaterThanComparator(), and RouletteWheelSelection::setGenome().
Utility function comparing two genotype pointers on their rank.
Definition at line 182 of file genotype.h.
References Genotype::rank().
Referenced by StefanoSteadyStateGA::finalize(), SimpleGA::gaStep(), ParallelGA::gaStep(), and LaralGA::gaStep().
|
protected |
Resize the Genotype.
- Parameters
-
newsize is the number of bits after resizing
- Warning
- if the new dimension is shorter than the old one, some data will be discarded
- The data pointer will be changed after this method execution
Definition at line 157 of file genotype.cpp.
References Genotype::allocated, Genotype::data, and Genotype::sizev.
Referenced by RealGenotype::configure(), SignedRangeGenotype::configure(), and Genotype::configure().
|
virtual |
Save the actual status of parameters into the ConfigurationParameters object passed.
- Parameters
-
params the configuration parameters object on which save actual parameters prefix the prefix to use to access the object configuration parameters.
Implements ParameterSettableWithConfigureFunction.
Reimplemented in RealGenotype, and SignedRangeGenotype.
Definition at line 123 of file genotype.cpp.
References ConfigurationParameters::createParameter(), Genotype::fitnessv, Genotype::notesv, Genotype::rankv, Genotype::sizev, and Genotype::toCompressedString().
Referenced by Genome::save().
void set | ( | unsigned int | i | ) |
Set to One the i-th bit.
Definition at line 222 of file genotype.cpp.
References Genotype::data.
Referenced by RandomBit::mutate(), and SignedRangeGenotype::set().
void setFitness | ( | double | value | ) |
Set the fitness value of this Genotype.
- Note
- it is the same of setObjective( 0, value );
Definition at line 169 of file genotype.cpp.
References Genotype::setObjective().
void setNotes | ( | QString | notes | ) |
Set the notes of this Genotype.
Definition at line 256 of file genotype.cpp.
References Genotype::notes(), and Genotype::notesv.
void setObjective | ( | int | i, |
double | value | ||
) |
Set the i-th objective value of the (multi-objective) fitness.
- Note
- multi-objective fitness are used only with the GeneticAlgo that support them
- setFitness( aValue ) correspond to setObjectiveValue( 0, value );
- in a single objective fitness, the setObjectiveValue could be used to print out some intermediate values used for calculating the total fitness
Definition at line 177 of file genotype.cpp.
References Genotype::fitnessv.
Referenced by Genotype::setFitness().
void setRank | ( | double | rank | ) |
Set the rank of the genotype.
- Note
- the rank is a general single value used to order the genotypes inside the genome; it is different from fitness and it is GA-dependent. In simple cases, like SimpleGA, where the GA is driven by only one objective, then tipically the rank correspond to the fitness. But in multi-objective GAs (MOGA), like NSGA2, the rank depends on how the MOGA orders the genotypes
- better genotype will have higher rank value
Definition at line 205 of file genotype.cpp.
References Genotype::rankv.
Referenced by StefanoSteadyStateGA::gaStep().
unsigned int size | ( | ) | const |
Return the size of Genotype.
Definition at line 153 of file genotype.cpp.
References Genotype::sizev.
Referenced by RealGenotype::at(), SignedRangeGenotype::at(), OnePoint::crossover(), Genotype::Genotype(), FlipBit::mutate(), RandomBit::mutate(), RealGenotype::set(), and SignedRangeGenotype::set().
QString toCompressedString | ( | ) | const |
Compress the data; It return a printable String.
Definition at line 298 of file genotype.cpp.
References Genotype::bit(), and Genotype::sizev.
Referenced by RealGenotype::save(), SignedRangeGenotype::save(), and Genotype::save().
void toggle | ( | unsigned int | i | ) |
toggle the i-th bit
Definition at line 242 of file genotype.cpp.
References Genotype::data.
Referenced by OnePoint::crossover(), and FlipBit::mutate().
QString toString | ( | ) | const |
Return a QString representing this Genotype.
Definition at line 278 of file genotype.cpp.
References Genotype::bit(), and Genotype::sizev.
void unset | ( | unsigned int | i | ) |
set to zero the i-th bit
Definition at line 232 of file genotype.cpp.
References Genotype::data.
Referenced by Genotype::fromCompressedString(), Genotype::fromString(), Genotype::Genotype(), Genotype::insertUInt(), RandomBit::mutate(), Genotype::randomize(), and SignedRangeGenotype::set().
Member Data Documentation
|
protected |
Allocated memory.
Definition at line 203 of file genotype.h.
Referenced by Genotype::copyDataFrom(), Genotype::Genotype(), Genotype::operator=(), and Genotype::resize().
|
protected |
Data represented as a char vector allocated in memory.
Definition at line 199 of file genotype.h.
Referenced by Genotype::bit(), RealGenotype::configure(), Genotype::copyDataFrom(), Genotype::Genotype(), RealGenotype::operator=(), Genotype::operator=(), RealGenotype::RealGenotype(), Genotype::resize(), Genotype::set(), Genotype::toggle(), Genotype::unset(), and Genotype::~Genotype().
|
protected |
Objective values of the Fitness.
Definition at line 205 of file genotype.h.
Referenced by RealGenotype::configure(), SignedRangeGenotype::configure(), Genotype::configure(), Genotype::copyDataFrom(), Genotype::dominatedBy(), Genotype::Genotype(), Genotype::numOfObjectives(), Genotype::objective(), Genotype::operator=(), SignedRangeGenotype::save(), RealGenotype::save(), Genotype::save(), and Genotype::setObjective().
|
protected |
Notes about this Genotype.
Usage is left open.
Definition at line 209 of file genotype.h.
Referenced by RealGenotype::configure(), SignedRangeGenotype::configure(), Genotype::configure(), Genotype::copyDataFrom(), Genotype::Genotype(), Genotype::notes(), Genotype::operator=(), SignedRangeGenotype::save(), RealGenotype::save(), Genotype::save(), and Genotype::setNotes().
|
protected |
Rank.
Definition at line 207 of file genotype.h.
Referenced by RealGenotype::configure(), SignedRangeGenotype::configure(), Genotype::configure(), Genotype::copyDataFrom(), Genotype::Genotype(), Genotype::operator=(), Genotype::rank(), SignedRangeGenotype::save(), RealGenotype::save(), Genotype::save(), and Genotype::setRank().
|
protected |
Size.
Definition at line 201 of file genotype.h.
Referenced by Genotype::copyDataFrom(), Genotype::extractUInt(), Genotype::fromCompressedString(), Genotype::fromString(), Genotype::Genotype(), Genotype::hammingDistance(), Genotype::insertUInt(), Genotype::operator=(), Genotype::randomize(), Genotype::resize(), Genotype::save(), Genotype::size(), Genotype::toCompressedString(), and Genotype::toString().
The documentation for this class was generated from the following files:
- ga/include/core/genotype.h
- ga/src/core/genotype.cpp