Commit bb696b4b authored by 刘乐's avatar 刘乐

1,遗传算法框架构建

parent 6da0e985
#include "genetic.h"
Genetic::Genetic()
{
}
Genetic::~Genetic()
{
}
void Genetic::initPop()
{
}
void Genetic::fitNess()
{
}
void Genetic::select()
{
}
void Genetic::coding()
{
}
void Genetic::decoding()
{
}
void Genetic::crossover()
{
}
void Genetic::variation()
{
}
void Genetic::update()
{
}
\ No newline at end of file
#pragma once
/**
遗传算法对象
*/
class Genetic
{
public:
Genetic();
~Genetic();
/**
*@brief 初始化种群
*/
void initPop();
/**
*@brief 计算种群自适应度
*/
void fitNess();
/**
*@brief 选择
*/
void select();
/**
*@brief 编码
*/
void coding();
/**
*@brief 解码
*/
void decoding();
/**
*@brief 交叉
*/
void crossover();
/**
*@brief 选择
*/
void variation();
/**
*@brief 更新种群
*/
void update();
void setNumPop(int numPop) { mNumPop = numPop; }
int numPop() const { return mNumPop; }
void rseRtangeL(int range) { mIrangeL = range; }
int rangeL() const { return mIrangeL; }
void setRangeR(int range) { mIrangeR = range; }
int rangeR() const { return mIrangeR; }
// 设置编码长度
void setLength(int len) { mLength = len; }
int length() const { return mLength; }
void setIteration(int iterator) { mIteration = iterator; }
int iteration() const { return mIteration; }
// 杂焦虑
double crossoverRate() const { return mCrossoverRate; }
double selectRate() const { return mSelectRate; }
double variationRate() const { return mVariationRate; }
private:
int mNumPop = 100; //初始种群大小
int mIrangeL = -1; // 问题解区间
int mIrangeR = 2;
int mLength = 22; // 二进制编码长度
int mIteration = 10000; // 迭代次数
double mCrossoverRate = 0.7; // 杂交率
double mSelectRate = 0.5; // 选择率
double mVariationRate = 0.001; //变异率
};
......@@ -144,6 +144,10 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="genetic.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="genetic.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -14,4 +14,14 @@
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="genetic.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="genetic.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment