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

📄 pso1.h

📁 C++编的pso程序。该程序可以用于优化各种系统
💻 H
字号:
// Pso1.h: interface for the CPso class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PSO1_H__6E9E2F87_8FD6_48A8_A9C3_2CDFF5FBCE79__INCLUDED_)
#define AFX_PSO1_H__6E9E2F87_8FD6_48A8_A9C3_2CDFF5FBCE79__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#define PATICAL_NUMBER		5000
#define MAX_GENERATION		5000
#define PATICAL_DIMENTION   3

class CPatical
{
public:
	CPatical(){	}
//	CPatical(float Xmin, float Xmax, float Vmax);
	virtual ~CPatical();
public:
	void  InitPatical(float Xmin, float Xmax, float Vmax);
	void  LocalBest();
	float GetLocalBest(){return mBestFitness;}
	void  SetLocalBest(float bestFitness){ mBestFitness = bestFitness;}
	void  ChangeSpeedAndPosition(float Xmin, float Xmax, float Vmax, float Gbest[], float c1, float c2, float r1, float r2)\
				{ Speed(Vmax, Gbest, c1, c2, r1, r2); Position(Xmin, Xmax);}
	float GetPaticalDemention(int i){return mLBestPosition[i];}
	virtual float Fitness();
protected:
	virtual void Speed(float Vmax,float Gbest[], float c1, float c2, float r1, float r2, float w = 1);
	virtual void Position(float Xmin, float Xmax);
private:
	float mPaticalPosition[PATICAL_DIMENTION];
	float mCurrentFitness;
	float mSpeed[PATICAL_DIMENTION];

	float mLBestPosition[PATICAL_DIMENTION];
	float mBestFitness;
};
class CPSO  
{
public:
	CPSO(float c1, float c2, float r1, float r2, float w, float Xmin, float Xmax, float Vmax);
	virtual ~CPSO();
	void Pso();
//	virtual float C1(float x){return 1.0;}
//	virtual float C2(float x){return 1.0;}
//	virtual float R1(float x){return 1.0;}
//	virtual float R2(float x){return 1.0;}
//	virtual float W(float x) {return 1.0;}
	void SetMaxGen(int maxGen){mMaxGen = maxGen;}
	void SetWuCha(float wucha){mWuCha = wucha;}
//	virtual float Fitness(float position[]);
	void GlobalBest();
	void Print();
private:
	float mGBestPosition[PATICAL_DIMENTION];
	float mGBestFitness;

	CPatical mPatical[PATICAL_NUMBER];
private:
	float mW;
	float mC1;
	float mC2;
	float mR1;
	float mR2;
private:
	int   mMaxGen;
	float mWuCha;
	float mXmax;
	float mXmin;
	float mVmax;
};

#endif // !defined(AFX_PSO1_H__6E9E2F87_8FD6_48A8_A9C3_2CDFF5FBCE79__INCLUDED_)

⌨️ 快捷键说明

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