资源简介
使用遗传算法(GA)来自动率定经典水文概念性模型———新安江模型的各个参数,供大家学习参考
VS2008 with SP1 平台下编写,打开即可编译运行!
代码片段和文件信息
#include
#include “Gene.h“
#include
#include
GeneEvolution::GeneEvolution()
{
Best_Index=0;
Worst_Index=0;
CrossOverRate=0;
MutationRate=0;
MaxGeneration=0;
}
GeneEvolution::~GeneEvolution()
{
Best_Index=0;
Worst_Index=0;
CrossOverRate=0;
Generation=0;
MutationRate=0;
MaxGeneration=0;
NewPopulation.RemoveAll();
Population.RemoveAll();
Cfitness.RemoveAll();
}
void GeneEvolution::InitialPopulation(std::ifstream& iflie)//初始化种群
{
iflie>>VariableNum>>PopSize>>MaxGeneration>>CrossOverRate>>MutationRate;
VariableTop.resize(VariableNum);
VariableBottom.resize(VariableNum);
Current.Chromosome.resize(VariableNum);
Current1.Chromosome.resize(VariableNum);
CurrentBest.Chromosome.resize(VariableNum);
for (int i=0;i {
iflie>>VariableBottom[i]>>VariableTop[i];
}
//随机生成一个种群
srand((unsigned int)time(0));
for(int i=0;i {
for(int j=0;j {
Current.Chromosome[j]=double(rand()%10000)/10000*(VariableTop[j]-VariableBottom[j])+VariableBottom[j];
}
Current.Fitness=0;
Current.Value=0;
Population.InsertAfter(Population.FindIndex(i)Current);
}
}
void GeneEvolution::CalculateobjectValue( XAJ m_XAJ)//计算种群的得分,使用外部的目标函数,(本程序用于新安江自动率参试验)
//或者说需要寻优的实际问题的参数好坏的评价函数对该参数序列做好坏评价
{
for (int i=0;i {
Current=Population.GetAt(Population.FindIndex(i));
m_XAJ.InitialPA(Current.Chromosome);
m_XAJ.MainCompute();
Current.Value=m_XAJ.ComputeValue();
Population.SetAt(Population.FindIndex(i)Current);
}
}
void GeneEvolution::CalculateFitnessValue()//计算适应分,种群进化的评价标准该函数的可变范围较大,要寻找一个合适的评分标准
{
for (int i=0;i {
Current=Population.GetAt(Population.FindIndex(i));
if (Generation>=MaxGeneration*7/8)
{
Current.Fitness=pow(Current.Value1.5);
MutationRate=0.08;
CrossOverRate=0.9;
}
else if(Generation<=MaxGeneration*7/8&&Generation>=MaxGeneration*5/8)
{
MutationRate=0.06;
CrossOverRate=0.85;
Current.Fitness=pow(Current.Value2.5);
}
else
{
Current.Fitness=pow(Current.Value3.5);
}
Population.SetAt(Population.FindIndex(i)Current);
}
}
void GeneEvolution::FindBestAndWorstIndividual()//寻找最好和最坏的种群
{
BestIndividual=Population.GetAt(Population.FindIndex(Best_Index));
WorstIndividual=Population.GetAt(Population.FindIndex(Worst_Index));
for (int i=0;i {
Current=Population.GetAt(Population.FindIndex(i));
if (Current.Fitness>=BestIndividual.Fitness)
{
BestIndividual=Current;
Best_Index=i;
}
else if (Current.Fitness {
WorstIndividual=Current;
Worst_Index=i;
}
}
Population.SetAt(Population.FindIndex(Worst_Index)Population.GetAt(Population.FindIndex(Best_Index)));
//用最好的代替最差的
if (MaxGeneration==0)
{
CurrentBest=BestIndividual;
}
else
{
if (CurrentBest.Fitness
- 上一篇:使用数字电流传感器进行功耗和能耗监控应用笔记
- 下一篇:HFSS15破解文件
相关资源
- FPGA实现PID.v
- 基于FPGA的sdi视频传输工程(k7_sdi_rx
- FPGA彩条显示
- Xilinx-FPGA-引脚功能详细介绍.doc
- 基于xilinx FPGA的PCIe设计实战
- 基于PCIe的FPGA动态配置设计与实现
- 为什么工程师要掌握FPGA开发知识?
- 数字频率合成dds正弦波基于FPGA的DDS产
- Verilog FPGA UART串口控制器
- gmsk调制在FPGA上实现
- 一个简单的verilog编写的DMA IP CORE,和
- FPGA在步进电机驱动上的应用实例及代
- QGA 量子遗传算法
- fpga实现频率测量
- MCGS与单片机通信
- FPGA开发-ChipScope教程
- 红外循迹小车VHDL程序
- atmega16硬件产生方波的程序
- Gamma函数的解法
- 基于Gabor滤波器的图像纹理特征提取
- 基于遗传算法的排课系统
- atmega64bootload
- 基于FPGA的USB接口设计
- DE2模拟的交通红绿灯
- planeGame飞机游戏
- 遗传算法的M文件
- 一种抗SEU存储器电路的FPGA设计
- Furan-BDOPV Donor-Acceptor Polymers with Plana
- Behaviors of fatigue crack propagation in fric
- Dibrugarh地区牛场土壤中潜在的益生菌
评论
共有 条评论