⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gacoupling.h

📁 遗传算法做的排课系统
💻 H
字号:

#ifndef __GA_COUPLING_H__
#define __GA_COUPLING_H__

#include "..\CallConvention.h"
#include "..\Common\GaParameters.h"
#include "..\Common\GaOperation.h"
#include "..\Common\GaCatalogue.h"
#include "..\Chromosome\GaChromosome.h"
#include "GaSelection.h"

using namespace Common;
using namespace Chromosome;
using namespace Population;

namespace Population
{
	class GaPopulation;

	// Parameters for parent coupling operation.
	class GaCouplingParams : public GaParameters
	{

	private:

		// Number of offsprings which will be produced by coupling operation
		int _numberOfOffsprings;

	public:

		// Initializtion of the parameters
		DLL_EXPORT
		GaCouplingParams(int numberOfOffsprings);

		// Initialization of the parameters with default values
		DLL_EXPORT
		GaCouplingParams();

		// Virtual copy constructor
		DLL_EXPORT
		virtual GaParameters* GACALL Clone() const;

		// Returns number of offsprings which will be produced by coupling operation
		DLL_EXPORT
		int GACALL GetNumberOfOffsprings() const;

		// Sets number of offsprings which will be produced by coupling operation
		DLL_EXPORT
		void GACALL SetNumberOfOffsprings(int number);

	};// END CLASS DEFINITION GaCouplingParams

	// Results of coupling operation
	class GaCouplingResultSet
	{

	private:

		// Offsprings
		GaChromosomePtr* _offsprings;

		// Parents' indecies of offsprings
		int* _parents;

		// Number of offsprings
		int _numberOfOffsprings;

		// Selection result
		GaSelectionResultSet* _selection;

	public:

		// Initialization of the result set
		DLL_EXPORT
		GaCouplingResultSet(int numberOfOffsprings,
					GaSelectionResultSet* selectionResults);

		// Frees aquired resources
		DLL_EXPORT
		virtual ~GaCouplingResultSet();

		// Returns offspring at given position and its parent
		DLL_EXPORT
		bool GACALL GetOffspringAt(int pos,
			GaChromosomePtr& offspring,
			int& parent) const;

		// Sets offspring at given position
		DLL_EXPORT
		bool GACALL SetOffspringAt(int pos,
			GaChromosomePtr offspring,
			int parent);

		// Returns number of offsprings
		DLL_EXPORT
		int GACALL GetNumberOfOffsprings() const;

		// Sets number of offsprings
		DLL_EXPORT
		void GACALL SetNumberOfOffsprings(int number);

		// Return pointer to array of offsprings
		DLL_EXPORT
		GaChromosomePtr* GACALL GetOffspringsBuffer() const;

		// Returns pointer to array of indicies of offspring's parents
		DLL_EXPORT
		int* GACALL GetParentsBuffer() const;

		// Returns selection result set which was used to produce offsprings
		DLL_EXPORT
		GaSelectionResultSet& GACALL GetSelectionResultSet() const;

	};// END CLASS DEFINITION GaCouplingResultSet

	// Interface for parent coupling operation
	class GaCouplingOperation : public GaOperation
	{

	public:

		// Couples selected chromosomes and produce offsprings based on passed parameters
		virtual void GACALL operator ()(const GaPopulation& population,
			GaCouplingResultSet& output,
			const GaCouplingParams& parameters,
			int workerId,
			int numberOfWorkers) const=0;

	};// END CLASS DEFINITION GaCouplingOperation

	// Coupling operation and its parameters
	typedef GaOperationParametersPair<GaCouplingOperation, GaCouplingParams> GaCouplingPair;

	// Catalogue of coupling operations
	typedef GaCatalogue<GaCouplingOperation> GaCouplingCatalogue;

} // Population

#endif // __GA_COUPLING_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -