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

📄 interfacetsp.cpp

📁 c++语言实现的遗传算法的例子,需要的快下啊
💻 CPP
字号:
// InterfaceTSP.cpp: implementation of the InterfaceTSP class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TSP.h"

#include "AdaptabilityTSP.h"
#include "Arithmatic.h"
#include "GA.h"
#include "SA.h"
#include "ACTsp.h"
#include "PSOTSP.h"
#include "stdio.h"
#include "time.h"
#include "Assistant.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

TSP_API HWND hWndMain;
int hour;
int minute;
int second;
int millisecond;
int nowround;
clock_t avetime;
double * gb;

#pragma comment(lib,"Parameter.lib")
#pragma comment(lib,"Interface.lib")
#pragma comment(lib,"Assistant.lib")

InterfaceTSP::InterfaceTSP()
{

}

void InterfaceTSP::Run(Parameter * param)
{
	Adaptability * adapt;
	Arithmatic * temp;
	double avegb=0;
	avetime=0;
//	char szTitle[128];
//	PAINTSTRUCT ps;
//	HDC hdc;
	int round=(int)param->CharToInt(param->GetCombo(0));
	gb=new double[round];
	FILE * file=fopen("time.zn","w");
	for(nowround=0;nowround<round;nowround++)
	{
		adapt=new AdaptabilityTSP(param);
		if(strcmp(param->GetCombo(16),"AC")==0)
			temp=new ACTsp(adapt,param);
		if(strcmp(param->GetCombo(16),"PSO")==0)
			temp=new PSOTSP(adapt,param);
		if(strcmp(param->GetCombo(16),"GA")==0)
			temp=new GA(adapt,param);
		if(strcmp(param->GetCombo(16),"SA")==0)
			temp=new SA(adapt,param);
/*	hour=new int[round];
	minute=new int[round];
	second=new int[round];
	millisecond=new int[round];*/
		temp->Run();
		avegb+=gb[nowround];
//		hdc=BeginPaint(hWndMain,&ps);
//		wsprintf(szTitle,"最优解:%f  运行时间:%d%d:%d%d:%d%d.%d%d",gb,hour/10,hour%10,minute/10,minute%10,second/10,second%10,millisecond/10,millisecond%10);
//		TextOut(hdc,10,30+20*nowround,szTitle,lstrlen(szTitle));
//		EndPaint(hWndMain,&ps);
		fprintf(file,"最优解:%f  运行时间:%d%d:%d%d:%d%d.%d%d\n",gb[nowround],hour/10,hour%10,minute/10,minute%10,second/10,second%10,millisecond/10,millisecond%10);
		delete temp;
		delete adapt;
	}
	double time=(double)avetime/round/CLOCKS_PER_SEC;
	millisecond=((int)(time*100))%100;
	second=((int)time)%60;
	minute=((int)time-second)/60%60;
	hour=(((int)time-second)/60-minute)/60;
	fprintf(file,"平均解:%f  运行时间:%d%d:%d%d:%d%d.%d%d\n",avegb/round,hour/10,hour%10,minute/10,minute%10,second/10,second%10,millisecond/10,millisecond%10);
	fclose(file);
	delete[] gb;
}

InterfaceTSP::~InterfaceTSP()
{

}

⌨️ 快捷键说明

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