GLMutatorCombined Class Reference

#include <GLMutatorCombined.h>

Inheritance diagram for GLMutatorCombined:

GLBaseMutator

List of all members.

Classes

struct  TParameters

Public Types

enum  TUsage { SEPARATE = 1, COMBINED = 2 }

Public Member Functions

 GLMutatorCombined (const vector< GLBaseMutator * > &mutators, const double &mutation_rate=0.1, const vector< double > &weights=vector< double >(0), TUsage apply_mutators=COMBINED)
 GLMutatorCombined (const double &mutation_rate, GLMutatorCombined::TParameters *parameters)
 GLMutatorCombined (const GLMutatorCombined &mutator)
virtual ~GLMutatorCombined ()
virtual GLBaseMutatorcopy () const
virtual bool mutateOrganism (GLBaseOrganism *organism)

Protected Member Functions

void checkAndInit ()
bool mutateCombined (GLBaseOrganism *organism)
bool mutateSeparately (GLBaseOrganism *organism)
void processWeights ()


Detailed Description

This class allows combining several mutator in one. It contains vector of mutators (which will be destroyed in destructor of this class) which can be used to mutate the organisms in two possible ways.

In SEPARATE mode organism can be mutated by one mutator only. The probability with which each mutator will be chosen is defined by the vector of weight coefficients.

In COMBINED mode all the mutators will be applyed to organism. The order, in which mutators are to be applied is the same as their order in the vector of mutators. In this the vector of weights is ignored.

Note, that each mutator has also its own mutation rate which will be 'superimposed' in each of the mutators. So the algorithm for mutation operator is this: 1) Use mutator_rate of THIS class to decide if the organism will be mutated. 2) Depending on apply_mutators status one mutator will be chosen or the loop through all the mutators will be entered. 3) Each (or single) mutator will decide, whether to mutate the organism using its own mutation rate. Therefore, if mutation rate for this class is set to 0.5 and mutation rates for all mutators in the vector are 0.2 the total chance of the organism being mutated is 0.1 in SEPARATE mode.

Definition at line 35 of file GLMutatorCombined.h.


Member Enumeration Documentation

Determines, how the mutators from the set will be applied to the organism.

Definition at line 42 of file GLMutatorCombined.h.


Constructor & Destructor Documentation

GLMutatorCombined::GLMutatorCombined ( const vector< GLBaseMutator * > &  mutators,
const double &  mutation_rate = 0.1,
const vector< double > &  weights = vector<double>(0),
TUsage  apply_mutators = COMBINED 
) [inline]

Constructor. Sets up all the necessary data. By default always tries to mutate the organism by applying to it all the 'submutators' one-by-one.

Parameters:
mutators vector with pointers to mutators which will be used in mutation operator. These mutators become 'property' of this class and will be destroyed in destructor.
mutation_rate chance that any of the mutators in the vector will try to mutate the organisms. Defaut value is 1.0, so some mutator always will be applied and the probability of the organism to mutate will be determined by the mutators in the vector.
weights probability with which particular mutator will be chosen to mutate the organism. This vector is used only when apply_mutator is equal to SEPARATE. The probability for i-th mutator to be chosen is weights[i]/sum(weights), so the impact of vectors {0.5, 0.5} and {1.0, 1.0} is equivalent. If apply_mutators == SEPARATE the size of vector 'weights' should be equal to size of 'mutators'.
apply_mutators flag which indicates how the mutators will be applied to the organism.

Definition at line 71 of file GLMutatorCombined.h.

GLMutatorCombined::GLMutatorCombined ( const double &  mutation_rate,
GLMutatorCombined::TParameters parameters 
) [inline]

Constructor. Sets up all the necessary data.

Parameters:
mutation_rate chance that any of the mutators in the vector will try to mutate the organisms. Defaut value is 1.0, so some mutator always will be applied and the probability of the organism to mutate will be determined by the mutators in the vector.
parameters pointer to structure which contains all the necessary information to create this mutator.

Definition at line 91 of file GLMutatorCombined.h.

GLMutatorCombined::GLMutatorCombined ( const GLMutatorCombined mutator  ) 

Copying constructor. Creates copies of submutators.

Parameters:
mutator source for copying.
Copying constructor.
Parameters:
mutator source for copying.

Definition at line 16 of file GLMutatorCombined.cpp.

GLMutatorCombined::~GLMutatorCombined (  )  [virtual]

Destructor. Destroys all the 'submutators'.

Definition at line 32 of file GLMutatorCombined.cpp.


Member Function Documentation

void GLMutatorCombined::checkAndInit (  )  [protected]

Checks that this class's parameters are set properly (e.g. if weights should be supplied, they are all positive etc.) and performs some initialisation. Should be called in the constructor.

Definition at line 44 of file GLMutatorCombined.cpp.

virtual GLBaseMutator* GLMutatorCombined::copy (  )  const [inline, virtual]

Creates copy of the current exemplar of the mutator. Should be overloaded in childrens.

Returns:
copy of the current exemplar of the mutator.

Implements GLBaseMutator.

Definition at line 115 of file GLMutatorCombined.h.

bool GLMutatorCombined::mutateCombined ( GLBaseOrganism organism  )  [protected]

Mutate the organism by applying all the mutators one-by-one.

Parameters:
organism organism to be mutated.
Returns:
true if organism was mutated and false otherwise.

Definition at line 102 of file GLMutatorCombined.cpp.

bool GLMutatorCombined::mutateOrganism ( GLBaseOrganism organism  )  [virtual]

Performs the mutation on the organism. If passed organism was changed (mutated) returns true, otherwise returns false.

Parameters:
organism organism to be mutated.
Returns:
true if organism was mutated and false otherwise.

Implements GLBaseMutator.

Definition at line 121 of file GLMutatorCombined.cpp.

bool GLMutatorCombined::mutateSeparately ( GLBaseOrganism organism  )  [protected]

Mutate the organism by choosing one of the mutators from the vector according to the weights and applying it to the organism.

Parameters:
organism organism to be mutated.
Returns:
true if organism was mutated and false otherwise.

Definition at line 150 of file GLMutatorCombined.cpp.

void GLMutatorCombined::processWeights (  )  [protected]

Fills vector of normalized cumulative weights (ncw) based on the vector of weights (w) -- last element of ncw is always 1.0. ncw[n] = sum(i=0..n, w[i])/sum(i = 0..size(w), w[i]).

Definition at line 176 of file GLMutatorCombined.cpp.


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

Generated on Sat Jun 13 13:58:10 2009 for GenLib by  doxygen 1.5.9