📄 rtcgpsfda4.cpp
字号:
// RTCGPSFDA4.cpp: implementation of the RTCGPSFDA4 class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RTDMOEA.h"
#include "RTCGPSFDA4.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
RTCGPSFDA4::RTCGPSFDA4()
{
}
RTCGPSFDA4::~RTCGPSFDA4()
{
}
void RTCGPSFDA4::InitPop()
{
CSolution t_temp;
t_temp.Init();
for (int i=0;i<PopSize;i++)
{
/** 设置 FDA4 的初始化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 RTCGPSFDA4::ComputeFitness(CSolution &m_1)
{
EvaluationNum++;
for ( int j =0;j< CSolution::GetGeneLength() ;j++)
{
if (m_1.Gene[j]<0.0 )
m_1.Gene[j] =(double)CRandom::Random(0,1);
if (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);
//计算gt
double gt=fabs(sin(0.5* PI * t));
//计算gx
double gx=0;
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* m_1.Gene[0] /2);
f1*=cos(PI* m_1.Gene[1] /2);
m_1.Objective[0]=f1*(1+gx);
//计算 f2
double f2=1;
f2*=cos(PI* m_1.Gene[0] /2);
f2*=sin(PI* m_1.Gene[1] /2);
m_1.Objective[1]=f2*(1+gx);
//计算f3
double f3=sin(PI* m_1.Gene[0] /2);
m_1.Objective[2]=f3*(1+gx);
}
void RTCGPSFDA4::RandomMutate(int Index)
{
/** 设置 FDA4 的初始化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 + -