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

📄 rtcgpsfda5.cpp

📁 基于GPS的多目标优化及动态多目标优化源代码 里面 包含MOP, DMOP的程序
💻 CPP
字号:
// RTCGPSFDA5.cpp: implementation of the RTCGPSFDA5 class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "RTDMOEA.h"
#include "RTCGPSFDA5.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

RTCGPSFDA5::RTCGPSFDA5()
{

}

RTCGPSFDA5::~RTCGPSFDA5()
{

}


void RTCGPSFDA5::InitPop()
{
   CSolution t_temp;
   t_temp.Init();
   for (int i=0;i<PopSize;i++)
   {
	   /**  设置 FDA5 的初始化GENE   **/
	   for ( int j =0;j< CSolution::GetGeneLength() ;j++)
	   {
		   t_temp.Gene[j] =CRandom::Random(0.0,1.0);   
	   }      /***  增加个体 */
	   m_Pop[i].Init();
       m_Pop[i].Copy(&t_temp);
   }
      InitPopType();

}

void RTCGPSFDA5::ComputeFitness(CSolution &m_1)
{
     EvaluationNum++;

	   for ( int j =0;j< CSolution::GetGeneLength() ;j++)
	   {
	   		   if ((m_1.Gene[j]<0.0) ||(m_1.Gene[j]>1))
		   m_1.Gene[j] =CRandom::Random(0.0,1.0);   
	   }
	   
	   int nr=10;
	   int rt=ChangeGenerationNum;
	   double t= (1.0/(double)nr)*((int)CurrentGeneration/rt);

	   //计算Ft

	   double Ft=1+ 100*pow(sin(0.5*PI*t),4);
	   //计算gt
 	double gt=fabs(sin(0.5* PI * t));
       //计算 gx
	double gx=gt;
	for (int i=2;i<CSolution::GetGeneLength();i++)
	{
		gx+=(m_1.Gene[i] -gt) *(m_1.Gene[i] -gt);
	}
		//计算 f1
    double f1=1;
    f1*=cos(PI* pow(m_1.Gene[0],Ft) /2);
    f1*=cos(PI* pow(m_1.Gene[1],Ft) /2);
	m_1.Objective[0]=f1*(1+gx);
	//计算 f2
    double f2=1;
    f2*=cos(PI* pow(m_1.Gene[0],Ft) /2);
    f2*=sin(PI* pow(m_1.Gene[1],Ft) /2);
    m_1.Objective[1]=f2*(1+gx);
    //计算f3
	double f3=sin(PI* pow(m_1.Gene[0],Ft) /2);
    m_1.Objective[2]=f3*(1+gx);


}

void RTCGPSFDA5::RandomMutate(int Index)
{
	   /**  设置 FDA5 的初始化GENE   **/
	   for (int j =0;j< CSolution::GetGeneLength() ;j++)
		   m_Pop[Index].Gene[j] =CRandom::Random(0.0,1.0);   
}

⌨️ 快捷键说明

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