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

📄 model.hh

📁 COOOL:CWP面向对象最优化库(CWP Object Oriented Optimization Library) COOOL是C++类的一个集合
💻 HH
📖 第 1 页 / 共 2 页
字号:
//============================================================// COOOL           version 1.1           ---     Nov,  1995//   Center for Wave Phenomena, Colorado School of Mines//============================================================////   This code is part of a preliminary release of COOOL (CWP// Object-Oriented Optimization Library) and associated class // libraries. //// The COOOL library is a free software. You can do anything you want// with it including make a fortune.  However, neither the authors,// the Center for Wave Phenomena, nor anyone else you can think of// makes any guarantees about anything in this package or any aspect// of its functionality.//// Since you've got the source code you can also modify the// library to suit your own purposes. We would appreciate it // if the headers that identify the authors are kept in the // source code.#ifndef MODEL_HH#define MODEL_HH#ifdef __GNUC__#pragma interface#endif#include <iostream.h>#include "Vector.hh"// .NAME Model - a simple class for model parameters// .INCLUDE c++/Model.hh// .FILE Model.cc// .SECTION Description// .B Model//=================// H. Lydia Deng,  02/17/94//============================//@Man://@Memo: a simple class for a model space/*@Doc: This is a class for a model space and models in this space. It should have been a derived class of Vector<Type>, but it is standalone because of historical reasons (I didn't know about inheritence back then. :). There are several choices for the Model Space. You could construct a n-D infinite space $R^n$, n-D hypercube (continuous with lower and upper bound at each directions), n-D lattice (discrete Model space), or n-D spacewith irregular boundary (tested by the user-provide function, $cstraints(Vector\&)$. After the model space is constructed, it will take care of the updating of thenew models that guarentees all models belong to the model space.*/   template <class Type>class Model {private:	int	ndim;	Type	deltmod;	int     (*tp)(Vector<Type> &);		Vector<Type>*	mp;	Vector<Type>*	maxParam;	Vector<Type>*	minParam;	public:	//@ManMemo: the default constructor	Model();	//@ManMemo: construct a model space with dimension n	Model(int n);	//@ManMemo: construct a discrete model space with boundary and initial values	Model(/// upper boundary of the model space	      const Vector<Type>& maxp, 	      /// lower boundary of the model space	      const Vector<Type>& minp, 	      /// initial values of the model parameters	      const Vector<Type>& ini_mod, 	      /// discrete step size in the model space	      Type delta);	//@ManMemo: construct a discrete model space with boundary and constraints	Model(/// upper boundary of the model space	      const Vector<Type>& maxp, 	      /// lower boundary of the model space	      const Vector<Type>& minp, 	      /// point to the function which tests if the constraints are statisfied	      int (*cstraints)(Vector<Type>&));	//@ManMemo: construct a continuous model space with boundary and initial values	Model(const Vector<Type>& maxp, const Vector<Type>& minp, const Vector<Type>& ini_mod);	//@ManMemo: construct a continuous model space with boundary	Model(const Vector<Type>& maxp, const Vector<Type>& minp);	//@ManMemo: construct a continuous model space with initial values 	Model(const Vector<Type>& ini_mod);	//@ManMemo: construct an n-D models space with constraints	Model(const int n, int (*cstraints)(Vector<Type>&));	//@ManMemo: construct a model space identical to that of Model m	Model(const Model<Type>& m);	~Model();	//@ManMemo: 	int modSize() const;	//@ManMemo: 	Type oneMax(int i) const;	//@ManMemo: 	Type oneMin(int i) const;	//@ManMemo: 	Type operator[](int) const;	//@ManMemo: 	Vector<Type> modMax() const;	//@ManMemo:     	Vector<Type> modMin() const;	//@ManMemo:     	void setModMax(const Vector<Type>& v);	//@ManMemo:     	void setModMin(const Vector<Type>& v);	//@ManMemo: 	Vector<Type>  modParam() const;	//@ManMemo: 	Type&	grid();	//@ManMemo: 	Type norm(int );	//@ManMemo: 	Model<Type> normalize();	//@ManMemo: 	Type	range(int);	//@ManMemo: 	Type& operator[](int);	//@ManMemo: 	Model<Type> update(Type, Type, const Vector<Type>&) const; 	operator Model<int>() const	{	   Vector<int> mm(mp[0]);	   Model<int> m(mm);	   if (maxParam != NULL || minParam != NULL) {		 Vector<int> maxBound(maxParam[0]);		 Vector<int> minBound(minParam[0]);		 Model<int> m1(maxBound,minBound,mm,(int)deltmod);		 return m1;	      }	   return m;	}	operator Model<long>() const	{	   Vector<long> mm(mp[0]);	   Model<long> m(mm);	   	   if (maxParam != NULL || minParam != NULL) {		 Vector<long> maxBound(maxParam[0]);		 Vector<long> minBound(minParam[0]);		 Model<long> m1(maxBound,minBound,mm, (long)deltmod);		 return m1;	      }	   return m;	}	operator Model<float>() const	{	   Vector<float> mm(mp[0]);	   Model<float> m(mm);	   if (maxParam != NULL || minParam != NULL) {		 Vector<float> maxBound(maxParam[0]);		 Vector<float> minBound(minParam[0]);		 Model<float> m1(maxBound,minBound,mm, (float)deltmod);		 return m1;	      }	   return m;	}	operator Model<double>() const	{	   Vector<double> mm(mp[0]);	   Model<double> m(mm);	   if (maxParam != NULL || minParam != NULL) {		 Vector<double> maxBound(maxParam[0]);		 Vector<double> minBound(minParam[0]);		 Model<double> m1(maxBound,minBound,mm, (double)deltmod);		 return m1;	      }	   return m;	}	//@ManMemo: 	Model<Type>& 	operator=(const Vector<Type>&);	//@ManMemo: 	Model<Type>& 	operator=(const Model<Type>&);	//@ManMemo: 	Model<Type>& 	operator=(Type);	//@ManMemo: 	Model<Type>& 	operator*=( Type);	//@ManMemo: 	Model<Type>& 	operator/=( Type);	//@ManMemo: 	Model<Type>& 	operator+=(const  Vector<Type>&);	//@ManMemo: 	Model<Type>& 	operator-=(const  Vector<Type>&);	//@ManMemo: 	Model<Type>& 	operator+=(const  Model<Type>&);	//@ManMemo: 	Model<Type>& 	operator-=(const  Model<Type>&);	//@ManMemo: 	Model<Type>&	chaSize(int);	//@ManMemo: binary read from which ifp points to	size_t bfread(FILE *ifp);	//@ManMemo: binary write to which ofp points to	size_t bfwrite(FILE *ofp);		//@ManMemo:     friend ostream& operator<<(ostream&, const Model<Type>&);	//@ManMemo:     friend istream& operator>>(istream&, Model<Type>&);	//@ManMemo:     friend Model<Type> operator/(const Model<Type>&, Type);	//@ManMemo:     friend Model<Type> operator*(const Model<Type>&, Type);    //@ManMemo:     friend Model<Type> operator*(Type,  const Model<Type>&);    //@ManMemo:     friend Model<Type> operator+(const Model<Type>&, const Model<Type>&);    //@ManMemo:     friend Model<Type> operator+(const Model<Type>&, const Vector<Type>&);    //@ManMemo:     friend Model<Type> operator+(const Vector<Type>&, const Model<Type>&);    //@ManMemo:     friend Model<Type> operator-(const Model<Type>&,const  Model<Type>&);    //@ManMemo:     friend Model<Type> operator-(const Model<Type>&, const Vector<Type>&);    //@ManMemo:     friend Model<Type> operator-(const Vector<Type>&, const Model<Type>&);    //@ManMemo: comparing two Models, ==    friend int operator==(const Model<Type>& m1, const Model<Type>& m2);    //@ManMemo: comparing two Models, !=    friend int operator!=(const Model<Type>& m1, const Model<Type>& m2);};#ifdef __GNUC__#pragma implementation#endif template<class Type>int Model<Type>::modSize() const { return ndim;} template<class Type>Type Model<Type>::operator[](int i) const{ return (*mp)[i];} template<class Type>Vector<Type> Model<Type>::modMax() const { if (maxParam != NULL) return maxParam[0];   else return -999; } template<class Type>Vector<Type> Model<Type>::modMin() const { if (minParam != NULL) return minParam[0];   else return -999; } template<class Type>void Model<Type>::setModMax(const Vector<Type>& v) { maxParam[0] = v;} template<class Type>void Model<Type>::setModMin(const Vector<Type>& v) { minParam[0] = v;} template<class Type>Vector<Type>  Model<Type>::modParam() const { return *mp;} template<class Type>Type&	Model<Type>::grid() {   return deltmod;} template<class Type>Type	Model<Type>::norm(int p){   return mp->norm(p);} template<class Type>Model<Type> Model<Type>::normalize(){       Model<Type> m(*this);       m.mp[0] = (m.mp)->normalize();       return m;} template<class Type>Type& Model<Type>::operator[](int i){ return (*mp)[i];}	// binary I/Otemplate<class Type>size_t Model<Type>::bfread(FILE *ifp){       return mp->bfread(ifp);}	 template<class Type>size_t Model<Type>::bfwrite(FILE *ofp){       return mp->bfwrite(ofp);}	 template<class Type>Model<Type>& Model<Type>::operator=(const Vector<Type>& v) {       mp[0] = v;       return *this;} template<class Type>Model<Type>& Model<Type>::chaSize(int m) {         ndim	=	m;         mp->chaSize(m);         maxParam->chaSize(m);         minParam->chaSize(m);         return *this;}     template<class Type>Model<Type>& Model<Type>::operator=(Type c) {  	mp[0] = c; 	return *this;} template<class Type>Model<Type>& Model<Type>::operator*=(Type c) {  	mp[0] *= c; 	return *this;} template<class Type>Model<Type>& Model<Type>::operator/=(Type c) {              if (c==0)       {	 cerr<<"WARNING: divided by a zero. \n";	 return *this;      }                   mp[0] /= c;             return *this;} template<class Type>Model<Type>& Model<Type>::operator+=(const Vector<Type>& v){ 	mp[0] += v; 	return *this;} template<class Type>Model<Type>& Model<Type>::operator+=(const Model<Type>& m){ 	mp[0] += m.mp[0]; 	return *this;} template<class Type>Model<Type>& Model<Type>::operator-=(const Vector<Type>& v){ 	mp[0] -= v; 	return *this;} template<class Type>Model<Type>& Model<Type>::operator-=(const Model<Type>& m){ 	mp[0] -= m.mp[0]; 	return *this;} template<class Type>Model<Type> operator+(const Model<Type>& m, const Vector<Type>& v){ 	Model<Type> m1(m); 	m1 += v; 	return m1;} template<class Type>Model<Type> operator+(const Vector<Type>& v, const Model<Type>& m){ 

⌨️ 快捷键说明

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