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

📄 gastatistics.h

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

#ifndef __GA_STATISTICS_H__
#define __GA_STATISTICS_H__

#include "..\ExportImport.h"
#include "..\CallConvention.h"

namespace Common
{
	// Statistical value types
	enum GaStatValueType
	{
		GSV_BEST_FITNESS, 
		GSV_BEST_FITNESS_SCALED, 
		GSV_AVG_FITNESS, 
		GSV_AVG_FITNESS_SCALED, 
		GSV_WORST_FITNESS, 
		GSV_WORST_FITNESS_SCALED, 
		GSV_TOTAL_FITNESS, 
		GSV_TOTAL_FITNESS_SCALED,
		GSV_POPULATION_SIZE
	};

	// Number of statistical value types
	const int GaNumberOfStatValueTypes = GSV_POPULATION_SIZE - GSV_BEST_FITNESS + 1;

	// Statistical value
	template <typename T>
	class GaStatValue
	{

	private:

		// Current value
		T _current;

		// Previous value
		T _previous;

	public:

		// Initialization of the values
		DLL_EXPORT
		GaStatValue(T current,
			T previous);

		// Initialization of the values with defaults
		DLL_EXPORT
		GaStatValue();

		// Returns current value
		DLL_EXPORT
		T GACALL GetCurrent() const;

		// Sets current value
		DLL_EXPORT
		void GACALL SetCurrent(T value);

		// Returns previous value
		DLL_EXPORT
		T GACALL GetPrevious() const;

		// Sets previous value
		DLL_EXPORT
		void GACALL SetPrevious(T value);

		// Returns TRUE if current value is changed 
		DLL_EXPORT
		bool GACALL Changed() const;

		// Combines two statistical values and returns result
		DLL_EXPORT
		GaStatValue<T> GACALL operator +(const GaStatValue<T>& rhs);

		// Combine statistical value with another
		DLL_EXPORT
		GaStatValue<T>& GACALL operator +=(const GaStatValue<T>& rhs);

	};// END CLASS DEFINITION GaStatValue

	// Floating point single precision statistical value
	typedef GaStatValue<float> GaFloatStatValue;

	// Tracks statistic and provides basic statistical information for one ore more populations.
	class GaStatistics
	{

	private:

		// Current generation
		int _currentGeneration;

		// Statistical values
		GaFloatStatValue _values[ GaNumberOfStatValueTypes ];

	public:

		// Initialize statistical information
		DLL_EXPORT
		GaStatistics();

		// Clears all values
		DLL_EXPORT
		void GACALL Clear();

		// The generation switch, updates statistical information for new and previous generation.
		DLL_EXPORT
		void GACALL NextGeneration();

		// Copies statistic values
		DLL_EXPORT
		void GACALL CopyFrom(const GaStatistics& stats,
			bool previous,
			bool current,
			bool currentGeneration);

		// Returns current generation
		DLL_EXPORT
		int GACALL GetCurrentGeneration() const;

		// Get progress of a value between this and previous generation
		DLL_EXPORT
		float GACALL GetValueProgress(GaStatValueType value,
			bool percent) const;

		// Change value
		DLL_EXPORT
		void GACALL ChangeValue(GaStatValueType type,
			float value,
			bool relative);

		// Returns statistical values
		DLL_EXPORT
		const GaFloatStatValue& GACALL GetValue(GaStatValueType value) const;

		// Combines information
		DLL_EXPORT
		GaStatistics GACALL operator +(const GaStatistics& rhs);

		// Combines information
		DLL_EXPORT
		GaStatistics& GACALL operator +=(const GaStatistics& rhs);

	};// END CLASS DEFINITION GaStatistics

} // Common

#endif //__GA_STATISTICS_H__

⌨️ 快捷键说明

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