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

📄 uofinfo.h

📁 遗传算法vc++语言版源程序,台湾大学编写。
💻 H
字号:
#ifndef _UOFINFO_
#define _UOFINFO_
#include "UOFId.h"

#include "UOFSolver.h"

//! Basic Info class
/*! Users should overrides this class if you define a new solver.
 This class is responsible for the information output of a solver. */
class UOFInfo : public UOFId
{
public:
	UOFIdentity("UOFID class",1);

	//! A constructor that generates a object with initialization.
	/*!
	  \param freq sets the m_updateFreq.
	  \param filename sets the m_fn.
	*/
	UOFInfo(size_t freq=1, string filename="Log.txt")
		:m_updateFreq(freq),m_fn(filename),m_itr(0){m_NosLog = 0;m_lastpn.clear();
		m_OutputResultFreq = false;m_ConvBehavior = false;m_ShowEvoOnline = false;m_ShowParamOnline = false;
		m_pn = "param.txt";m_cn = "conv.txt";}

	//! Enable the Show Optimization Result Online function
	/*! Once the Show Optimization Result Online function is enabled, 
	The optimization progress should shown periodically
	  \param seros sets the m_ShowEvoOnline.
	*/
	void	showEvoResultOnScreen(bool seros = true){m_ShowEvoOnline = seros;}

	//! Get the flag of Show Optimization Result Online function
	/*! This function returns is the Once the Show Optimization Result Online function is enabled or not.
	*/
	bool	showEvoResultOnScreen(){return m_ShowEvoOnline;}

	//! Enable the Show Parameters Online function
	/*! Once the Show Parameters Online function is enabled, 
	The optimized parameters during optimization process progress should shown periodically
	  \param sepos sets the m_ShowParamOnline.
	*/
	void	showEvoParamOnScreen(bool sepos = true){m_ShowParamOnline = sepos;}
	//! Get the flag of Show Parameters Online function
	/*! This function returns is the Once the Show Parameters Online function is enabled or not.
	*/
	bool	showEvoParamOnScreen(){return m_ShowParamOnline;}

	//! Set the frequency to display the optimization progress information
	/*! This function sets how frequently should the optimization progress information should be displayed.
	  \param freq sets the m_updateFreq.
	*/
	void	SetUpdateFreq(size_t freq){m_updateFreq = freq;}
	
	//! Get the frequency of displaying the optimization progress information
	/*! This function returns how frequently should the optimization progress information should be displayed.
	*/
	size_t	GetUpdateFreq(){return m_updateFreq;}

	//! Set the log file name
	/*! This function set the log file name, information during the optimization process will be outputed into this file.
	 \param freq sets the m_updateFreq.
	*/
	void	SetFilename(string filename){m_fn = filename;}
	
	//! Get the log file name
	/*! This function returns log file name.
	*/
	string	GetFilename(){return m_fn;}

	//! Enable the m_OutputResultFreq flag
	/*! Once the m_OutputResultFreq flag is on, 
	The current parameters of each information update will be output to a numbered file
	  \param oreu sets the m_OutputResultFreq.
	*/
	void	outputResultEveryUpdate(bool oreu = true){m_OutputResultFreq = oreu;}
	
	//! Get the m_OutputResultFreq flag
	/*! This function returns the m_OutputResultFreq flag.
	*/
	bool	outputResultEveryUpdate(){return m_OutputResultFreq;}

	//! Set the file name to output parameters.
	/*! This function set the m_pn. Once the m_OutputResultFreq flag is on, 
	The current parameters of each information update will be output to a numbered file with this file name.
	  \param filename sets the m_pn.
	*/
	void	paramFilename(string filename){m_pn = filename;}
	
	//! Get the file name to output parameters.
	/*! This function returns the file name to output parameters.
	*/
	string	paramFilename(){return m_pn;}

	//! Enable the m_ConvBehavior flag
	/*! Once the m_ConvBehavior flag is on, 
	The current result of each information update will be output to convergence hebavior file
	  \param oreu sets the m_ConvBehavior.
	*/
	void	outputConvergenceEveryUpdate(bool oreu = true){m_ConvBehavior = oreu;}
	
	//! Get the m_ConvBehavior flag
	/*! This function returns the m_ConvBehavior flag.
	*/
	bool	outputConvergenceEveryUpdate(){return m_ConvBehavior;}

	//! Set the file name to output convergence hebavior.
	/*! Once the m_ConvBehavior flag is on, 
	The current result of each information update will be output to convergence hebavior file
	  \param filename sets the m_cn.
	*/
	void	convergenceFilename(string filename){m_cn = filename;}
	
	//! Get the file name to output convergence hebavior.
	/*! This function returns the file name to output convergence hebavior.
	*/
	string	convergenceFilename(){return m_cn;}

	//! Update the information of optimization progress
	/*! This function is a abstract function, users should override this function to collect data from solver
	  \param src is pointer of the solver.
	*/
	virtual void	Update(UOFSolver *src) = 0;
	
	//! Output the summary optimization result
	/*! This function is a abstract function, users should override this function to output finished optimization status
	*/
	virtual void	PrintInfo() = 0;
	
	//! Get the number of iteration recorded in this class
	/*! This function returns the number of iteration recorded in this class.
	*/
	size_t	GetIter(){return m_itr;}
	
	//! Get the time cost til current moment recorded in this class
	/*! This function returns how long the solver has been run until now.
	*/
	time_t	GetTime(){return m_TimeElapsed;}
    
protected:
	size_t	m_updateFreq;		/**< the frequency to display the optimization progress information */
	bool	m_ShowEvoOnline;	/**< the flag to enable Show Optimization Result Online function */
	bool	m_ShowParamOnline;	/**< the flag to enable Show Parameters Online function */
	string	m_fn;				/**< the log file name */
	string	m_pn;				/**< the file name to output parameters */
	string	m_lastpn;			/**< the file name of last outputed parameters with enumerated format */
	bool	m_OutputResultFreq;	/**< the flag to output current parameters of each information update will be output to a numbered file */
	string	m_cn;				/**< the file name to output convergence hebavior */
	bool	m_ConvBehavior;		/**< the flag to output current result */
	size_t	m_itr;				/**< the iteration of solver when the last information update is performed*/
	int		m_NosLog;			/**< the number of information output has been performed */
	time_t	m_StartTime;		/**< the time stamp of start this optimization */
	time_t	m_TimeElapsed;		/**< the current time spent of this optimization */
};
#endif

⌨️ 快捷键说明

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