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

📄 alg.h

📁 该算法是张青复与周爱民的基于RM-MEDA算法的程序
💻 H
字号:
//
//Please find details of the method from
//
//	Q. Zhang, A. Zhou and Y. Jin, "RM-MEDA: A Regularity Model Based Multiobjective Estimation of Distribution Algorithm", IEEE Trans. Evolutionary Computation, Vol. 12, no. 1, pp41-63, 2008.
//
//The source codes are free for reserach work. If you have any problem with the source codes, please contact with 
//	Qingfu Zhang, 
//		Department of Computing and Electronic Systems,
//		University of Essex,
//		Colchester, CO4 3SQ, UK
//		http://cswww.essex.ac.uk/staff/zhang
//		Email: qzhang@essex.ac.uk
//    Aimin Zhou
//		Department of Computing and Electronic Systems,
//		University of Essex,
//		Colchester, CO4 3SQ, UK
//		http://privatewww.essex.ac.uk/~azhou/
//		Email: azhou@essex.ac.uk or amzhou@gmail.com 
//Programmer:		
//		Aimin Zhou
//Last Update:
//		Feb. 21, 2008
//
//Alg.h : Framwork for MOEA
//

#ifndef	AZ_ALGORITHM_H
#define	AZ_ALGORITHM_H

#include <ctime>
#include "Parameter.h"
#include "PopulationMO.h"

//!\brief	az namespace, the top namespace
namespace az
{

//!\brief	mea namespace, the multiobjective evolutionary algorithm namespace
namespace mea
{
	//!\brief	EA framework
	//!\param	COG	offspring generator
	//!\param	CES environmental selection
	template<class COG, class CES>
		class CEA : public COG, public CES
	{
	protected:
		unsigned int
			mPopSize,	//!< population size
			mStep	,	//!< current step
			mStepMax,	//!< maximum steps
			mEvas	;	//!< the calculation number of the objectives
		double 
			mTM,		//!< time used to model
			mTS;		//!< time used to selection
		CPopulationMO	mPop;	//!< population
		CParameter*	pPar;	//!< pointer to the parameter object
	public:
		//!\brief	constractor
		//!\param	stepmax maximum steps
		//!\param	par parameter object
		//!\param	pop initial population
		//!\return	void
		CEA	(
			unsigned int	stepmax	,
			CParameter&		par		,
			CPopulationMO&	pop		)
			: mPop(pop)
		{
			mStepMax 	= stepmax;
			pPar		= &par;
			mStep		= 0;
			mEvas		= 0;
			mPopSize 	= mPop.Size();
			mTM			= mTS	= 0.0;
		}

		//!\brief	destructor
		//!\return	void
		~CEA() {}

		//!\brief	get the pointer to the parameter object
		//!\return	pointer to the parameter object
		inline CParameter& P() {return *pPar;}

		//!\brief	get the population
		//1\return	reference to population
		inline CPopulationMO& Population() {return mPop;}

		//!\brief	get the objective evaluation times
		//!\return	objective evaluation times
		inline unsigned int& EvaTimes() {return mEvas;}

		//!\brief	check to see whether the terminate condition is satified
		//!\return	true if terminate
		inline bool IsTerminate() {return mStep >= mStepMax;}
		
		//!\brief	get the maximal step
		//!\return	maximal step
		inline unsigned int MaxStep() {return mStepMax;}

		//!\brief	get the current step
		//!\return	current step
		inline unsigned int CurStep() {return mStep;}

		//!\brief	get the run time
		//!\return	void
		inline void Time(double& tm, double& ts) {tm = mTM/CLOCKS_PER_SEC; ts = mTS/CLOCKS_PER_SEC;}

		//!\brief	one step 
		//!\return	current step
		unsigned int Step()
		{
			clock_t t1,t2,t3;
			CPopulationMO popnew(P());

			t1 = clock();
			//sample new solutions
			COG::Generate(popnew, Population());
			
			//check the range of new solutions
			Check(popnew);

			//remove these repeated solutions
			Check(popnew, Population());

			//evaluate new solutions	
			popnew.Evaluate();
			mEvas += popnew.Size();	

			//popnew.Write("new.txt");

			t2 = clock();

			//environmental select 
			Population().Combine(popnew);
			CES::Select(Population(), mPopSize);
			
			t3 = clock();

			mTM += double(t2-t1);
			mTS += double(t3-t2);

			return ++mStep;
		}
	protected:
		//!\brief	make all new solutions in feasible region
		//!\param	pop offspring population
		//!\return	void
		void Check(CPopulationMO& pop)
		{
			for(unsigned int i=0; i<pop.Size(); i++)
				pop[i].Check();
		}

		//!\brief	make all new solutions are different from old solutions
		//!\param	popnew offspring population
		//!\param	pop old population
		//!\return	void
		void Check(CPopulationMO& popnew, CPopulationMO& pop)
		{
			CPopulationMO tmp(P());
			for(unsigned int i=0; i<popnew.Size(); i++)
				if(!pop.IsContain(popnew[i])) tmp.Combine(popnew.At(i));
			popnew.Clear();
			popnew.Combine(tmp);
		}
	}; //class CEA

} //namespace mea

} //namespace az

#endif //AZ_ALGORITHM_H

⌨️ 快捷键说明

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