⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sga for testing.cpp

📁 在软件测试的单元测试中
💻 CPP
字号:
// 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 << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
		CString strHello;
		strHello.LoadString(IDS_HELLO);
		cout << (LPCTSTR)strHello << endl;

		///////////////////////////

		 individual* temp ;
		
		if((outfp=fopen("testing SGA Optimizer.txt","w"))==NULL)
		{
			fprintf(stderr,"Cannot open output file %s\n","基本GA运算");
			exit(-1);
		}
		
		cout<<"输入遗传算法执行次数(1-5):";
		cin>>cSGAlib.maxruns;
		for(cSGAlib.run=1;cSGAlib.run<=cSGAlib.maxruns;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;
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -