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

📄 gaoperation.h

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

#ifndef __GA_OPERATION_H__
#define __GA_OPERATION_H__

#include "..\CallConvention.h"
#include "GaParameters.h"

using namespace Common;

namespace Common
{
	// Interface for all genetic operations
	class GaOperation
	{

	public:

		// Allocate memory and make instance of parameters.
		// Caller is responsible for allocated memory.
		virtual GaParameters* GACALL MakeParameters() const=0;

		// Check passed parameters. Returns TRUE if everything correct.
		virtual bool GACALL CheckParameters(const GaParameters& parameters) const=0;

	};// END CLASS DEFINITION GaOperation

	// Manages genetic operations and theirs parameters
	template <typename OTYPE, typename PTYPE>
	class GaOperationParametersPair
	{

	private:

		// Pointer to genetic operation
		OTYPE* _operation;

		// Pointer to parameters for genetic operation
		PTYPE* _parameters;

	public:

		// Initialization of the pair
		GaOperationParametersPair(OTYPE& operation,
						 PTYPE& parameters)
		{
			_operation = &operation;
			_parameters = &parameters ? (PTYPE*)parameters.Clone() : NULL;
		};

		// Initialization of the pair with default values
		GaOperationParametersPair() : _operation( NULL ),
									_parameters( NULL ){ };

		// Free memory used by parameters
		~GaOperationParametersPair()
		{
			if( _parameters )
				delete _parameters;
		}

		// Returns reference to the operation
		OTYPE& GACALL GetOperation() const
		{
			return *_operation;
		};

		// Sets pointer to an operation
		void GACALL SetOperation(OTYPE& operation, PTYPE& parameters)
		{
			_operation = &operation;

			SetParameters( parameters );
		};

		// Returns reference to the parameters of the operation
		PTYPE& GACALL GetParameters() const
		{
			return *_parameters;
		};

		// Sets pointer to a parameters for the operation
		void GACALL SetParameters(PTYPE& parameters)
		{
			if( _parameters )
				delete _parameters;

			_parameters = &parameters ? (PTYPE*)parameters.Clone() : NULL;
		};

		// Returns TRUE if the operation is defined
		bool GACALL HasOperation() const
		{
			return _operation != NULL;
		}

		// Returns TRUE if parameters asre defined
		bool GACALL HasParameters() const
		{
			return _parameters != NULL;
		}

	};// END CLASS DEFINITION GaOperationParametersPair

} // Common

#endif //__GA_OPERATION_H__

⌨️ 快捷键说明

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