帮忙注释一段C++程序,谢谢你
#include "ga.h"
main()
{
outfile.open("result.txt",ios::out);
InitializeIE();
//Import
outfile<<"\
----------------------------------------------------- ";
outfile<<"\
The numbers of Import="<<ImportNum
<<"\
The loading vehicle probility="<<VehicleRate
<<"\
The VehicleLoad="<<VehicleLoad
<<"\
The vehicle speed="<<speed
<<"\
The max generation="<<maxgen
<<"\
The early exit probility="<<probility<<endl;
outfile<<"\
----------------------------------------------------- ";
InitializeData();
//parameter
InitializeReport(); //print parameter
InitializeMemory(); //初始oldpop,
gen=0;
Initializepop();
if (avgfitness/maxfitness<probility)
success=false;
else success=true;
while((gen<maxgen)&&(!success)&&(maxbest<80))
{
gen++;
select();
generate();
ComputeFitness(newpop);
Statistics(newpop);
Report();
p1=oldpop;
oldpop=newpop;
newpop=p1;
}// end while 结束遗传操作
outfile<<"\
----------------THE BEST PATH IS----------------- ";
outfile<<"\
-----------------------------------------------------\
";
for (int j=0;j<lchrom;j++)
outfile<<bestfit.chrom[j]<<" ";
outfile<<"\
----------------------------------------------------- ";
outfile<<"\
----------------------------------------------------- ";
for (j=0;j<popsize;j++)
{
delete[] oldpop[j].chrom;
oldpop[j].chrom=0;
delete[] newpop[j].chrom;
newpop[j].chrom=0;
//delete[] p1[j].chrom;
// p1[j].chrom=0;
}
delete[] bestfit.chrom;
bestfit.chrom=0;
delete[] oldpop;
oldpop=0;
delete[] newpop;
newpop=0;
p1=0;
delete[] dd;
dd=0;
delete[] ff;
ff=0;
delete[] PtrIP;
PtrIP=0;
return 0;
}
我C++刚学 但是老师给了作业 希望您能帮助我谢谢啦
答案:#include "ga.h"
main()
{
outfile.open("result.txt",ios::out); //打开结果文件
InitializeIE();
//Import //初始化被感染群落定义
outfile<<"\
----------------------------------------------------- ";
outfile<<"\
The numbers of Import="<<ImportNum //被感染数量
<<"\
The loading vehicle probility="<<VehicleRate //载媒数量
<<"\
The VehicleLoad="<<VehicleLoad //载媒负荷
<<"\
The vehicle speed="<<speed //传播速度
<<"\
The max generation="<<maxgen //最多繁衍代数
<<"\
The early exit probility="<<probility<<endl; //最早退出概率
outfile<<"\
----------------------------------------------------- ";
InitializeData();
//parameter //初始化参数
InitializeReport(); //print parameter //初始化报表
InitializeMemory(); //初始oldpop, //初始化各群落内存
gen=0; //将初始繁衍代数置为0,即第一代
Initializepop(); //初始化各群落
if (avgfitness/maxfitness<probility) //如果平均最佳生存适应性除以最大最佳生存适应性比概率小
success=false; //认为感染失败(无法生存)
else success=true; //否则感染成功(当地繁殖得以生存)
//本人认为上面的语句可以改写为 success = avgfitness/maxfitness>=probility
//如果繁衍代数小于最大代数,并且不成功,并且最佳生存小于80的情况下,持续仿真循环
while((gen<maxgen)&&(!success)&&(maxbest<80))
{
gen++; //进入下一代
select(); //适者生存
generate(); //繁衍
ComputeFitness(newpop); //计算新一代种群存活率
Statistics(newpop); //统计新群落存活率
Report(); //打印报表
p1=oldpop; //将旧群落存入p1临时群落变量
oldpop=newpop; //旧群落被新群落取代
newpop=p1; //新旧群落交换存储
}// end while 结束遗传操作
//打印最佳路径
outfile<<"\
----------------THE BEST PATH IS----------------- ";
outfile<<"\
-----------------------------------------------------\
";
for (int j=0;j<lchrom;j++)
outfile<<bestfit.chrom[j]<<" ";
//打印染色体
outfile<<"\
----------------------------------------------------- ";
outfile<<"\
----------------------------------------------------- ";
for (j=0;j<popsize;j++) //清除临时分配的存储空间,释放内存(以下内容均是清除内存操作)
{
delete[] oldpop[j].chrom;
oldpop[j].chrom=0;
delete[] newpop[j].chrom;
newpop[j].chrom=0;
//delete[] p1[j].chrom;
// p1[j].chrom=0;
}
delete[] bestfit.chrom;
bestfit.chrom=0;
delete[] oldpop;
oldpop=0;
delete[] newpop;
newpop=0;
p1=0;
delete[] dd;
dd=0;
delete[] ff;
ff=0;
delete[] PtrIP;
PtrIP=0;
return 0;
}百度一下
上一个:关于C++ TCP/IP通信的问题
下一个:推荐学习C++的一本书