📄 gaselection.h
字号:
#ifndef __GA_SELECTION_H__
#define __GA_SELECTION_H__
#include "..\CallConvention.h"
#include "..\Common\GaParameters.h"
#include "..\Common\GaOperation.h"
#include "..\Common\GaCatalogue.h"
#include "..\Chromosome\GaChromosome.h"
using namespace Common;
using namespace Chromosome;
using namespace Population;
namespace Population
{
class GaPopulation;
class GaSortedGroup;
// Base class of all parameters for selection operations.
class GaSelectionParams : public GaParameters
{
protected:
// Number of chromosomes to select from population
int _selectionSize;
public:
// Initialization of the parameters
DLL_EXPORT
GaSelectionParams(int selectionSize);
// Initialization of the parameters with default values
DLL_EXPORT
GaSelectionParams();
// Virtual copy constructor
DLL_EXPORT
virtual GaParameters* GACALL Clone() const;
// Returns number of chromosomes to select from population
DLL_EXPORT
int GACALL GetSelectionSize() const;
// Sets number of chromosomes to select from population
DLL_EXPORT
void GACALL SetSelectionSize(int size);
};// END CLASS DEFINITION GaSelectionParams
// Base class of all results for selection operations.
class GaSelectionResultSet
{
protected:
// Group of selected chromosomes
GaSortedGroup* _selectedGroup;
public:
// Initialization
DLL_EXPORT
GaSelectionResultSet(int selectionSize,
const GaPopulation* population);
// Releases aquired resources
DLL_EXPORT
virtual ~GaSelectionResultSet();
// Returns group of selected chromosomes
DLL_EXPORT
GaSortedGroup& GACALL SelectedGroup() const;
// Returns pointer to chromosome at given position in selection group.
DLL_EXPORT
GaChromosomePtr GACALL GetAt(int pos) const;
// Returns pointer to chromosome at given position in selection group.
DLL_EXPORT
GaChromosomePtr GACALL operator [](int pos) const;
};// END CLASS DEFINITION GaSelectionResultSet
// Interface for selection operations.
class GaSelectionOperation : public GaOperation
{
public:
// Selects chromosomes from the given population based on passed parameters
virtual void GACALL operator ()(const GaPopulation& population,
const GaSelectionParams& parameters,
GaSelectionResultSet* result) const=0;
// Allocate memory and make apropriate result set for the selection operation.
// Caller is responsible for allocated memory.
DLL_EXPORT
virtual GaSelectionResultSet* GACALL MakeResultSet(GaPopulation* population,
const GaSelectionParams& parameters) const;
};// END CLASS DEFINITION GaSelectionOperation
// Selection operation and its parameters
typedef GaOperationParametersPair<GaSelectionOperation, GaSelectionParams> GaSelectionPair;
// Catalogue of selection operations
typedef GaCatalogue<GaSelectionOperation> GaSelectionCatalogue;
} // Population
#endif // __GA_SELECTION_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -