📄 solution.cpp
字号:
// Solution.cpp: implementation of the CSolution class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RTDMOEA.h"
#include "Solution.h"
#include "Random.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int CSolution::st_iGeneLength =1;
int CSolution::OBJectiveNum =2;
BOOL CSolution::ChangeTypePolicy = FALSE;
CSolution::CSolution()
{
// Init();
}
CSolution::CSolution(BOOL WillInit)
{
if (WillInit) Init();
}
CSolution::CSolution(CSolution & temp)
{
this->Init();
this->Copy(&temp);
}
void CSolution::Init()
{
Distance=0;
Objective= new float[OBJectiveNum+1];
//多申请一个,用于折中目标
memset(Objective,9999,sizeof(float)*(OBJectiveNum+1));
type = CRandom::Random(0,OBJectiveNum);
Gene = new float[st_iGeneLength];
memset(Gene,0,sizeof(float) * st_iGeneLength);
// Slope =9999;
}
CSolution::~CSolution()
{
//if (Gene!=NULL)
delete[] Gene;
//if (Objective!=NULL)
delete [] Objective;
}
void CSolution::SetGeneLength(int mLength)
{
CSolution::st_iGeneLength = mLength;
}
int CSolution::GetGeneLength()
{
return st_iGeneLength;
}
void CSolution::Copy(CSolution * p_Temp)
{
memcpy(this->Gene, p_Temp->Gene, sizeof(float) * CSolution::GetGeneLength());
memcpy(this->Objective,p_Temp->Objective,sizeof(float) * (CSolution::OBJectiveNum+1));
this->Distance = p_Temp->Distance ;
this->Slope = p_Temp->Slope;
if (ChangeTypePolicy) this->type = p_Temp->type;
memcpy(Key, p_Temp->Key ,sizeof(char) *128);
}
VOID CSolution::ResetFitness()
{
for (int i=0;i<OBJectiveNum+1;i++)
{
Objective[i]=9999;
}
Distance =0;
//memset(Objective,9999,sizeof(double)*(OBJectiveNum+1));
}
void CSolution::preDelete()
{
delete[] Gene;
delete [] Objective;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -