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

📄 binarychromosome.h

📁 遗传算法做图像的模式匹配
💻 H
📖 第 1 页 / 共 2 页
字号:
			/// chromosome's data and CCB is copied.</param>
			GAL_API
			GaBinaryChromosome(const GaBinaryChromosome& c,
				bool setupOnly);

			/// <summary>Destructor frees memory used by chromosome's code and backup code.</summary>
			GAL_API
			virtual ~GaBinaryChromosome();

			/// <summary>More details are given in specification of <see cref="GaChromosome::MakeCopy" /> method.
			///
			/// This method is not thread-safe.</summary>
			GAL_API
			virtual GaChromosomePtr GACALL MakeCopy(bool setupOnly) const { return new GaBinaryChromosome( *this, setupOnly ); }

			/// <summary>This method uses <see cref="MakeCopy" /> method to create chromosome's object, so if additional steps are not needed
			/// for creating chromosome from prototype, classes which inherits this class don't have to override this method.
			/// 
			/// More details are given in specification of <see cref="GaChromosome::MakeNewFromPrototype" /> method.</summary>
			GAL_API
			virtual GaChromosomePtr GACALL MakeNewFromPrototype() const;

			/// <summary>This method is not thread-safe.</summary>
			/// <returns>Method returns number of bits in chromosome's code.</returns>
			virtual int GACALL GetCodeSize() const { return _codeSize; }

			/// <summary><c>SetBitState</c> method sets state of bit at specified position.
			///
			/// This method is not thread safe.</summary>
			/// <param name="bit">position of bit.</param>
			/// <param name="state">new state of the bit.</param>
			GAL_API
			void GACALL SetBitState(int bit,
				bool state);

			/// <summary><c>GetBit</c> method returns state of specified bit.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="bit">position of bit which state is queried.</param>
			/// <returns>Method returns state of specified bit.</returns>
			GAL_API
			bool GACALL GetBit(int bit);

			/// <summary>This method is not thread-safe.</summary>
			/// <returns>Method returns pointer to array of booleans which represent binary code of chromosome.</returns>
			inline bool* GACALL GetCode() { return _bits; }

			/// <summary>More details are given in specification of <see cref="GaChromosome::operator =" />.
			///
			/// This method is not thread-safe.</summary>
			GAL_API
			virtual GaChromosome& GACALL operator =(const GaChromosome& rhs);

			/// <summary>More details are given in specification of <see cref="GaChromosome::operator ==" />.
			///
			/// This method is not thread-safe.</summary>
			GAL_API
			virtual float GACALL operator ==(const GaChromosome& c) const;

			/// <summary><c>GetChar</c> method use <c>sizeof(char)*8</c> number of bits from <c>pos</c> position of chromosome's code to create <c>char</c> value. 
			///
			/// This method is not thread-safe.</summary>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <returns>Methods returns created value from array of bits.</returns>
			GAL_API
			char GACALL GetChar(int pos = 0) const;

			/// <summary><c>GetChar</c> method fills array of <c>char</c> values by extracting them from chromosome's code.
			/// If output array is bigger then chromosome's code, remaining values in output are set to 0. 
			///
			/// This method is not thread-safe.</summary>
			/// <param name="output">output array of values.</param>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <param name="size">number of values which should be extracted.</param>
			GAL_API
			void GACALL GetChar(char* output,
				int pos = 0,
				int size = 0) const;

			/// <summary><c>GetShort</c> method use <c>sizeof(short)*8</c> number of bits from <c>pos</c> position of chromosome's code
			/// to create <c>short</c> value.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <returns>Methods returns created value from array of bits.</returns>
			GAL_API
			short GACALL GetShort(int pos = 0) const;

			/// <summary><c>GetShort</c> method fills array of <c>short</c> values by extracting them from chromosome's code.
			/// If output array is bigger then chromosome's code, remaining values in output are set to 0. 
			///
			/// This method is not thread-safe.</summary>
			/// <param name="output">output array of values.</param>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <param name="size">number of values which should be extracted.</param>
			GAL_API
			void GACALL GetShort(short* output,
				int pos = 0,
				int size = 0) const;

			/// <summary><c>GetInt</c> method use <c>sizeof(int)*8</c> number of bits from <c>pos</c> position of chromosome's code
			/// to create <c>int</c> value.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <returns>Methods returns created value from array of bits.</returns>
			GAL_API
			int GACALL GetInt(int pos = 0) const;

			/// <summary><c>GetInt</c> method fills array of int values by extracting them from chromosome's code.
			/// If output array is bigger then chromosome's code, remaining values in output are set to 0. 
			///
			/// This method is not thread-safe.</summary>
			/// <param name="output">output array of values.</param>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <param name="size">number of values which should be extracted.</param>
			GAL_API
			void GACALL GetInt(int* output,
				int pos = 0,
				int size = 0) const;

			/// <summary><c>GetFloat</c> method use <c>sizeof(float)*8</c> number of bits from <c>pos</c> position of chromosome's code
			/// to create <c>float</c> value.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <returns>Methods returns created value from array of bits.</returns>
			GAL_API
			float GACALL GetFloat(int pos = 0) const;

			/// <summary><c>GetFloat</c> method fills array of float values by extracting them from chromosome's code.
			/// If output array is bigger then chromosome's code, remaining values in output are set to 0. 
			///
			/// This method is not thread-safe.</summary>
			/// <param name="output">output array of values.</param>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <param name="size">number of values which should be extracted.</param>
			GAL_API
			void GACALL GetFloat(float* output,
				int pos = 0,
				int size = 0) const;

			/// <summary><c>GetDouble</c> method use <c>sizeof(double)*8</c> number of bits from <c>pos</c> position of chromosome's code
			/// to create <c>double</c> value.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <returns>Methods returns created value from array of bits.</returns>
			GAL_API
			double GACALL GetDouble(int pos = 0) const;

			/// <summary><c>GetDouble</c> method fills array of double values by extracting them from chromosome's code.
			/// If output array is bigger then chromosome's code, remaining values in output are set to 0. 
			///
			/// This method is not thread-safe.</summary>
			/// <param name="output">output array of values.</param>
			/// <param name="pos">starting position in chromosome's code array of bits.</param>
			/// <param name="size">number of values which should be extracted.</param>
			GAL_API
			void GACALL GetDouble(double* output,
				int pos = 0,
				int size = 0) const;

			/// <summary><c>FromChar</c> method creates array of booleans which is equal to binary representation of array of input values of <c>char</c> type.
			/// Produced array can be used as chromosome's code of binary chromosome. Caller is responsible for memory allocated by this method for output array. 
			///
			/// This method is not thread-safe.</summary>
			/// <param name="input">pointer to array of input values.</param>
			/// <param name="size">number of values in input array.</param>
			/// <returns>Method returns pointer to output array. Size of output array is <c>sizeof(char)*8</c>.</returns>
			GAL_API
			static bool* GACALL FromChar(char* input,
				int size);

			/// <summary><c>FromShort</c> method creates array of booleans which is equal to binary representation of array of input values of <c>short</c> type.
			/// Produced array can be used as chromosome's code of binary chromosome. Caller is responsible for memory allocated by this method for output array.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="input">pointer to array of input values.</param>
			/// <param name="size">number of values in input array.</param>
			/// <returns>Method returns pointer to output array. Size of output array is <c>sizeof(short)*8</c>.</returns>
			GAL_API
			static bool* GACALL FromShort(short* input,
				int size);

			/// <summary><c>FromInt</c> method creates array of booleans which is equal to binary representation of array of input values of <c>int</c> type.
			/// Produced array can be used as chromosome's code of binary chromosome. Caller is responsible for memory allocated by this method for output array.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="input">pointer to array of input values.</param>
			/// <param name="size">number of values in input array.</param>
			/// <returns>Method returns pointer to output array. Size of output array is <c>sizeof(int)*8</c>.</returns>
			GAL_API
			static bool* GACALL FromInt(int* input,
				int size);

			/// <summary><c>FromFloat</c> method creates array of booleans which is equal to binary representation of array of input values of <c>float</c> type.
			/// Produced array can be used as chromosome's code of binary chromosome. Caller is responsible for memory allocated by this method for output array.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="input">pointer to array of input values.</param>
			/// <param name="size">number of values in input array.</param>
			/// <returns>Method returns pointer to output array. Size of output array is <c>sizeof(float)*8</c>.</returns>
			GAL_API
			static bool* GACALL FromFloat(float* input,
				int size);

			/// <summary><c>FromDouble</c> method creates array of booleans which is equal to binary representation of array of input values of <c>double</c> type.
			/// Produced array can be used as chromosome's code of binary chromosome. Caller is responsible for memory allocated by this method for output array.
			///
			/// This method is not thread-safe.</summary>
			/// <param name="input">pointer to array of input values.</param>
			/// <param name="size">number of values in input array.</param>
			/// <returns>Method returns pointer to output array. Size of output array is <c>sizeof(double)*8</c>.</returns>
			GAL_API
			static bool* GACALL FromDouble(double* input,
				int size);

		protected:

			/// <summary><c>PreapareForMutation</c> method creates backup of current code and saves its size.
			///
			/// This method is not thread-safe.</summary>
			GAL_API
			virtual void GACALL PreapareForMutation();

			/// <summary>This method only deletes backup copy.
			///
			/// This method is not thread-safe.</summary>
			GAL_API
			virtual void GACALL AcceptMutation();

			/// <summary><c>RejectMutation</c> method deletes current chromosome's code and restores it from backup copy.
			///
			/// This method is not thread-safe.</summary>
			GAL_API
			virtual void GACALL RejectMutation();

		};// END CLASS DEFINITION GaBinaryChromosome

	} // Representation
} // Chromosome

#endif // __GA_BINARY_CHROMOSOME_H__

⌨️ 快捷键说明

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