?? gachromosome.h
字號:
// Returns index of chromosome in population
DLL_EXPORT
int GACALL GetIndex() const;
// Return's population to which this chromosome belongs
DLL_EXPORT
GaPopulation& GACALL GetPopulation() const;
// Returns pointer to chromosome
DLL_EXPORT
GACALL operator GaChromosomePtr() const;
// Returns scaled fitness value
DLL_EXPORT
GACALL operator float() const;
};// END CLASS DEFINITION GaScaledChromosome
class GaDefaultChromosome;
// Container for chromosome parameters
class GaChromosomeParamsBlock
{
friend class GaDefaultChromosome;
protected:
// Paremeters for execution of GA operations over chromosome
GaChromosomeParams* _parameters;
public:
// Initialize block
DLL_EXPORT
GaChromosomeParamsBlock(GaChromosomeParams* parameters);
// Copy constructor
DLL_EXPORT
GaChromosomeParamsBlock(const GaChromosomeParamsBlock& rhs);
// Initialize empty block
DLL_EXPORT
GaChromosomeParamsBlock();
// Returns referenct to parameters
DLL_EXPORT
const GaChromosomeParams& GACALL GetParameters() const;
// Sets pointer to chromosome's parameters
DLL_EXPORT
void GACALL SetParameters(GaChromosomeParams* params);
};// END CLASS DEFINITION GaChromosomeParamsBlock
// Implements some behavior concerning fitness value, parameters
// and preaparing chromosome for crossover and mutation operations.
class GaDefaultChromosome : public GaChromosome
{
protected:
// Fitness value
float _fitness;
// Configuration block of chromosome contains parameters, operations and others
GaChromosomeParamsBlock* _configBlock;
public:
// Initialization of chromosome values
DLL_EXPORT
GaDefaultChromosome(GaChromosomeParamsBlock* configBlock);
// Copy constructor
DLL_EXPORT
GaDefaultChromosome(const GaDefaultChromosome& c,
bool setupOnly);
// Mutation operation
DLL_EXPORT
virtual void GACALL Mutation();
// Performs crossover operation and make new chiled from this and another given chromosome,
DLL_EXPORT
virtual GaChromosomePtr GACALL Crossover(GaChromosomePtr secondParent) const;
// Returns fitness of the chromosome
DLL_EXPORT
virtual float GACALL GetFitness() const;
// Compares fitnesses of two chromosomes. Returns:
// a, -1 if the fitness value of this chromosome is lower then the value of the given chromosome
// b. 0 if the fitness values of both chromosomes are equal
// c. 1 if the fitness value of this chromosome is greater then the value of the given chromosome
DLL_EXPORT
virtual int GACALL CompareFitnesses(GaChromosomePtr c) const;
// Compares fitnesses of two chromosomes. Returns:
// a, -1 if the fitness value of this chromosome is lower then the given value
// b. 0 if the fitness values of both chromosomes are equal
// c. 1 if the fitness value of this chromosome is greater then the given value
DLL_EXPORT
virtual int GACALL CompareFitnesses(float c) const=0;
// Refresh fitness value of chromosome
DLL_EXPORT
virtual void GACALL RefreshFitness();
// Returns algorithm's parameters of chromosome
DLL_EXPORT
virtual const GaChromosomeParams& GACALL GetParameters() const;
// Sets algorithm's parameters of chromosome
DLL_EXPORT
virtual void GACALL SetParameters(GaChromosomeParams* p);
// Returns referenc to chromosome's configuration block
DLL_EXPORT
virtual const GaChromosomeParamsBlock& GACALL GetConfigBlock() const;
// Sets pointer to chromosome's configuration block
DLL_EXPORT
virtual void GACALL SetConfigBlock(GaChromosomeParamsBlock* block);
// Copy data and setup from given source chromosome
DLL_EXPORT
virtual GaChromosome& GACALL operator =(const GaChromosome& rhs);
protected:
// Executes mutation operation
virtual void GACALL PerformMutation()=0;
// Performs crossover operation and make new chiled from this and another given chromosome
virtual GaChromosomePtr GACALL PerformCrossover(GaChromosomePtr secondParent) const=0;
// Saves current chromosome's code before mutation
virtual void GACALL PreapareForMutation()=0;
// Accepts mutation and deletes backuped code
virtual void GACALL AcceptMutation()=0;
// Rejects mutation and restores backuped chromosome's code
virtual void GACALL RejectMutation()=0;
};// END CLASS DEFINITION GaDefaultChromosome
class GaCrossoverOperation;
class GaMutationOperation;
class GaFitnessOperation;
class GaDynamicOperationChromosome;
// Container for chromosome's operations and parameters
class GaChromosomeOperationsBlock : public GaChromosomeParamsBlock
{
friend class GaDynamicOperationChromosome;
protected:
// Current operation for calculation of fitness value
GaFitnessOperation* _fitnessOperation;
// Comparator of the fitness values
GaFitnessComparator* _fitnessComparator;
// Current mutation operation
GaMutationOperation* _mutationOperation;
// Current crossover operation
GaCrossoverOperation* _crossoverOperation;
public:
// Initialize chromosome's operations block
DLL_EXPORT
GaChromosomeOperationsBlock(GaCrossoverOperation* crossoverOperation,
GaMutationOperation* mutationOperation,
GaFitnessOperation* fitnessOperation,
GaFitnessComparator* fitnessComparator,
GaChromosomeParams* parameters);
// Copy constructor
DLL_EXPORT
GaChromosomeOperationsBlock(const GaChromosomeOperationsBlock& rhs);
// Initialize empty block
DLL_EXPORT
GaChromosomeOperationsBlock();
// Returns crossover operation
DLL_EXPORT
const GaCrossoverOperation& GACALL GetCrossoverOperation() const;
// Sets crossover operation
DLL_EXPORT
void GACALL SetCrossoverOperation(GaCrossoverOperation* operation);
// Returns mutation operation
DLL_EXPORT
const GaMutationOperation& GACALL GetMutationOperation() const;
// Sets mutation operation
DLL_EXPORT
void GACALL SetMutationOperation(GaMutationOperation* operation);
// Returns fitness operation
DLL_EXPORT
const GaFitnessOperation& GACALL GetFitnessOperation() const;
// Sets fitness operation
DLL_EXPORT
void GACALL SetFitnessOperation(GaFitnessOperation* operation);
// Returns fitness value comparator
DLL_EXPORT
const GaFitnessComparator& GACALL GetFitnessComparator() const;
// Sets fitness value comaprator
DLL_EXPORT
void GACALL SetFitnessComparator(GaFitnessComparator* comparator);
};// END CLASS DEFINITION GaChromosomeOperationsBlock
// Implements features needed to dynamically change GA operations on chromosome
class GaDynamicOperationChromosome : public GaDefaultChromosome
{
public:
// Initialize chromosome
DLL_EXPORT
GaDynamicOperationChromosome(GaChromosomeOperationsBlock* configBlock);
// Copy constructor
DLL_EXPORT
GaDynamicOperationChromosome(const GaDynamicOperationChromosome& c,
bool setupOnly);
// Compares fitnesses of two chromosomes. Returns:
// a, -1 if the fitness value of this chromosome is lower then the given value
// b. 0 if the fitness values of both chromosomes are equal
// c. 1 if the fitness value of this chromosome is greater then the given value
DLL_EXPORT
virtual int GACALL CompareFitnesses(float c) const;
protected:
// Performs crossover operation and make new chiled from this and another given chromosome,
DLL_EXPORT
virtual GaChromosomePtr GACALL PerformCrossover(GaChromosomePtr secondParent) const;
// Performs mutation operation
DLL_EXPORT
virtual void GACALL PerformMutation();
// Calculate the fitness of chromosome
DLL_EXPORT
virtual float GACALL CalculateFitness() const;
};// END CLASS DEFINITION GaDynamicOperationChromosome
} // Chromosome
#endif // __GA_CHROMOSOME_H__
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -