📄 uofproblem.h
字号:
#ifndef _UOFPROBLEM_#define _UOFPROBLEM_#include <float.h>#include "UOFId.h"#include "UOFConstraint.h"
//! Basic Problem class
/*! Users should overrides this class if you define a new problem*/class UOFProblem : public UOFId{public: UOFIdentity("UOFProblem class",1);public:
//! Returns the emulation result to the callee.
/*! This is an abstract function, User must override this function to work. This is the major function of UOFProblem, this function should emulate a value for the feeded parameters. */ virtual double GetResult(void*) = 0;
//! Returns the emulation results to the callee.
/*! This is an abstract function, User must override this function to work. This function should be called if the callee needs more than single value as result. */ virtual void GetResult(void*, void*) = 0;
//! Returns the emulation results to the callee.
/*! This is an abstract function, User must override this function to work. This function should be called if the callee needs the derivatives of the result. */ virtual void GetJacobianResult(void*,void*) = 0;
//! Returns the specific data to the callee.
/*! This is an abstract function, User must override this function to work. This function should be called if the callee needs the more data than just result. */ virtual void GetExternalData(void*) = 0;
//! Performs the post process once the optimization procedure is finished.
/*! This is an abstract function, User must override this function to work. This function should be called once the optimization procedure is finished. */ virtual void PostProcess(void*) = 0; //!Gets the dimension of this problem /*This function returns the dimension of this problem, which is the number of parameters to be optimized. */ size_t GetProblemDim(){return m_problemDim;} vector<UOFConstraint> m_Const; /**< the constraint of each parameter */
//! This function sets the constraint of each parameter
/*! This is an abstract function, User must override this function to work. This function should set the constraint of each parameter. */ virtual void SetConstraint(void*) = 0; //!Gets the constraint of a parameter /*This function returns the constraint of a parameter \param i is the index of the parameter */ UOFConstraint constraint(int i){return m_Const[i];} //!Gets a random value under the constraint of a parameter. /*This function returns a random value under the constraint of a parameter. \param i is the index of the parameter */ double GetRandom(int i){return m_Const[i].GetRandom(0.0);} //!Remove the parameters in list from the parameters to be optimized. /*This function remove the parameters in list from the parameters to be optimized. This function could be used if there are some parameters users like to exclude from this optimization. This function is helpful if there are a few parameters need to be excluded. \param list is a array of the index of the parameters users like to exclude from this optimization. */ void SetFixParam(vector<int> list) { m_Const = m_DefConst; vector<bool> dele; dele.resize(m_DefConst.size(), false); for(size_t i=0;i<list.size();i++) dele[list[i]] = true; int count = 0; while(count<(int)m_Const.size()) { if(dele[count]) { dele.erase(dele.begin()+count); m_Const.erase(m_Const.begin()+count); } else count++; } } //!Remove the parameters in list from the parameters to be optimized. /*This function remove the parameters in list from the parameters to be optimized. This function could be used if there are some parameters users like to exclude from this optimization. This function is helpful if there are a few parameters need to be excluded. \param list is a array of the name of the parameters users like to exclude from this optimization. */ void SetFixParam(vector<string> list) { m_Const = m_DefConst; for(size_t i=0;i<list.size();i++) { size_t j=0; while(j<m_Const.size()) { if(_stricmp(m_Const[j].m_Name.c_str(), list[i].c_str())==0) { m_Const.erase(m_Const.begin()+j); break; } else j++; } } } //!Set only the parameters in list will be optimized. /*This function remove the all parameters excepts those in input list from the parameters to be optimized. This function could be used if there are only a few parameters need to be optimized. \param list is a array of the index of the parameters users allow to be optimized. */ void SetExtrParam(vector<int> list) { m_Const.clear(); for(size_t i=0;i<list.size();i++) m_Const.push_back(m_DefConst[list[i]]); } //!Set only the parameters in list will be optimized. /*This function remove the all parameters excepts those in input list from the parameters to be optimized. This function could be used if there are only a few parameters need to be optimized. \param list is a array of the name of the parameters users allow to be optimized. */ void SetExtrParam(vector<string> list) { m_Const.clear(); for(size_t i=0;i<list.size();i++) m_Const.push_back(FindConstraint(list[i], m_DefConst)); }protected: size_t m_problemDim;/**< the dimension of this problem */ vector<UOFConstraint> m_DefConst;/**< the default constraint of this problem */ //!Find the constraint from a pool /*This function search a constraint pool and find the constraint which the name is matched. If the constraint is found, returns the constraint, else return a constraint without name and the type is set to -1. \param name the name of constraint to be found. \cons the constraint pool to be searched. */ UOFConstraint FindConstraint(string name, vector<UOFConstraint> cons) { for(size_t i=0;i<cons.size();i++) if(_stricmp(name.c_str(), cons[i].m_Name.c_str())==0) return cons[i]; UOFConstraint a("", -1, DBL_MAX, DBL_MIN, DBL_MAX); return a; }};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -