这是一个遗传算法
源代码在线查看: sga for testing.cpp
软件大小: |
1022 K |
上传用户: |
liyusheng1983 |
|
|
关键词: |
算法
|
下载地址: |
免注册下载 普通下载
|
|
// SGA for testing.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "SGA for testing.h"
#include "SGAlib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
extern FILE* outfp;
extern individual* oldpop;
extern individual* newpop;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
SGAlib cSGAlib;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString strHello;
strHello.LoadString(IDS_HELLO);
cout
///////////////////////////
individual* temp ;
if((outfp=fopen("testing SGA Optimizer.txt","w"))==NULL)
{
fprintf(stderr,"Cannot open output file %s\n","基本GA运算");
exit(-1);
}
cout cin>>cSGAlib.maxruns;
for(cSGAlib.run=1;cSGAlib.run {
cSGAlib.gen=0;
cSGAlib.initialize();
do {
fprintf(outfp,"\n第%d/%d次运行:当前代为%d,共%d代\n",cSGAlib.run,cSGAlib.maxruns,cSGAlib.gen,cSGAlib.maxgen);
cSGAlib.generation();
cSGAlib.statistics(newpop);
//cSGAlib.report();
temp=oldpop;
oldpop=newpop;
newpop=temp;
cSGAlib.gen++;
} while(cSGAlib.evaluate(oldpop)==false);
fprintf(outfp,"\n当前代%d已经找到全面覆盖分支的种群!分支覆盖表为:\n",cSGAlib.gen);
cSGAlib.printpathvalue();
cSGAlib.freeall();
}
nRetCode = 0;
}
return nRetCode;
}