资源简介
万有引力算法C++程序
代码片段和文件信息
#include “StdAfx.h“
#include “global.h“
#include “CGSA.h“
int INDIVIDUAL::Dim = 0;
bool INDIVIDUAL::operator > (const INDIVIDUAL &p) const
{
return Fitness > p.Fitness;
}
INDIVIDUAL::INDIVIDUAL(void)
{
X = NULL;
V = NULL;
Fitness = 0.0;
}
INDIVIDUAL::INDIVIDUAL(int N)
{
Dim = N;
X = new double[Dim];
memset(X 0 sizeof(double)*(Dim));
V = new double[Dim];
memset(V 0 sizeof(double)*(Dim));
Fitness = 0.0;
}
INDIVIDUAL::INDIVIDUAL(const INDIVIDUAL& p)
{
X = NULL;
if (NULL != X && Dim != p.Dim)
{
delete []X;
X = NULL;
}
V = NULL;
if (NULL != V && Dim != p.Dim)
{
delete []V;
V = NULL;
}
if (NULL == X)
{
Dim = p.Dim;
X = new double[Dim];
}
memcpy(X p.X sizeof(double)*(Dim));
if (NULL == V)
{
Dim = p.Dim;
V = new double[Dim];
}
memcpy(V p.V sizeof(double)*(Dim));
Fitness = p.Fitness;
}
INDIVIDUAL::~INDIVIDUAL(void)
{
if (NULL != X)
{
delete []X;
X = NULL;
}
if (NULL != V)
{
delete []V;
V = NULL;
}
}
INDIVIDUAL &INDIVIDUAL::operator = (const INDIVIDUAL &p)
{
if (this == &p)
{
return *this;
}
if (NULL != X && Dim != p.Dim)
{
delete []X;
X = NULL;
}
if (NULL == X)
{
Dim = p.Dim;
X = new double[Dim];
}
memcpy(X p.X sizeof(double)*(Dim));
if (NULL != V && Dim != p.Dim)
{
delete []V;
V = NULL;
}
if (NULL == V)
{
Dim = p.Dim;
V = new double[Dim];
}
memcpy(V p.V sizeof(double)*(Dim));
Fitness = p.Fitness;
return *this;
}
bool INDIVIDUAL::operator == (const INDIVIDUAL &p) const
{
if (p.Dim != Dim)
{
return false;
}
if (Fitness != p.Fitness)
{
return false;
}
return true;
}
CGSA::CGSA(int MaxFES int PopSize int Dim int Findex)
{
srand(timeGetTime());
m_MaxFES = MaxFES; // The Max generation
m_PopSize = PopSize; // The Popsize
m_Dim = Dim; // The dimension
INDIVIDUAL::Dim = m_Dim;
m_BestFit.BestIndi = new INDIVIDUAL(m_Dim); // Initialize the Best Individual
m_BestFit.BestIndi->Fitness = 1.0e+300;
SetProbleIndex(Findex);
m_Mass = new double[m_PopSize];
m_TemMass = new double[m_PopSize];
m_MIndex = new int[m_PopSize];
m_AC = new double*[m_PopSize];
for (int i=0; i {
m_AC[i] = new double [Dim];
}
m_KBest = m_PopSize;
m_G0 = 100;
m_FEs = 0; // The Number of evaluating
m_Gen = 0;
m_StratTime = timeGetTime();
}
/********************************************
*Initialize which problem to optimize
*
*********************************************/
void CGSA::SetProbleIndex(int FIndex)
{
m_FID = FIndex;
m_XLower = g_Boundary[FIndex-1][0]; // set the low and up boundary
m_XUpper = g_Boundary[FIndex-1][1];
if (FIndex == 19)
{
m_XLower = -m_Dim*m_Dim;
m_XUpper = m_Dim*m_Dim;
}
}
CGSA::~CGSA(void)
{
if (NULL !=
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9844 2016-12-06 18:08 MyGSA\CGSA.cpp
文件 2701 2016-12-06 18:03 MyGSA\CGSA.h
文件 1196 2016-12-06 16:52 MyGSA\global.cpp
文件 342 2016-12-06 16:51 MyGSA\global.h
文件 324 2016-12-06 16:55 MyGSA\MyGSA.cpp
文件 875 2014-11-12 20:47 MyGSA\MyGSA.sln
..A..H. 13824 2016-12-06 18:08 MyGSA\MyGSA.suo
文件 4460 2016-12-06 16:48 MyGSA\MyGSA.vcproj
文件 3181 2014-09-28 11:58 MyGSA\Random.cpp
文件 749 2014-05-24 18:40 MyGSA\Random.h
文件 208 2011-06-06 15:38 MyGSA\stdafx.cpp
文件 233 2011-06-06 15:38 MyGSA\stdafx.h
文件 498 2011-06-06 15:38 MyGSA\targetver.h
目录 0 2016-12-06 18:08 MyGSA
----------- --------- ---------- ----- ----
38435 14
相关资源
- 算法精解 的源代码
- C语言仿真的aloha算法
- 银行家算法源程序包含C语言+C++两种代
- 数据结构C语言版_迪杰斯特拉算法
- PBIL算法源代码C++
- 每输入i0=
- ICP算法源代码拿走不谢
- 多边形填充的扫描线c++算法
- c++实现决策树分类算法(内附测试数
- Retinex算法,C++,opencv
- 门限秘密分享算法C实现
- 基于DSP2812的SVPWM算法C语言编程
- QM算法进行布尔代数化简
- 操作系统抢占式短进程优先调度算法
- hmacSha256Test.rar
- CohenSutherland裁剪算法和中点分割裁剪
- 机器人学强化训练,适用动态避障,
- 公交线路最短路径查询
- 无优先级运算问题C语言
- DWA算法验证(matlab)
- 排序算法的实现与比较
- 几种常用的滤波算法C语言filter.c
- 画线算法C++的实现-鼠标交互
- 数据结构和算法案例-欢乐五子棋 C+
- mpu9250九轴算法-纯c语言
- MD5算法c++程序设计实现
- C语言实现的DES加密算法
- Cohen-Sutherland 算法线段裁剪
- 产生式系统反向推理算法的设计与实
- 基于二叉堆优化的A星算法
评论
共有 条评论