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

📄 main.cpp

📁 遗传算法实现旅行商问题:经典遗传算法解决旅行商问题
💻 CPP
字号:
#include "global.h"

void evolution();

int main()
{
	srand(unsigned(time(0)));
	clock_t start,finish;
	double totaltime;
	start=clock();
	evolution();
	finish=clock();
	totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
	cout<<"\n此程序运行时间为:"<<totaltime<<endl;
	return 0;
}
void evolution()
{
	ofstream groupout("group.txt");
	ofstream bestout("best.txt");
	if (!groupout||!bestout)
	{
		cout<<"no file!"<<endl;
	}
	
	int loop=0;
	int noevo=0;
	Group gp0;
//	ofstream test("test.txt");
//	gp0.printGroup(test);
	Group& parent=gp0;
	Group& next=parent.evolute();
	do 
	{
		loop++;
		next=parent.evolute();
		next.printBestIndividual(cout);
		next.printBestIndividual(bestout);
		next.printGroup(groupout);
		if (next==parent)
		{
			noevo++;
		}
		else
		{
			noevo=0;
		}
		if (noevo==NOEVOLUTE)
		{
			break;
		}
		parent=next;
	}while(loop<TOTALEVOLUTE);
	cout<<"见group.txt"<<endl;
}

⌨️ 快捷键说明

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