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

📄 anttsp.cpp

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

#include "stdafx.h"
#include "AntTsp.h"
#include "Assistant.h"

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

AntTsp::AntTsp(Adaptability * a,int d):Ant(a,d)
{
	route=new int[dimension];
}

double * AntTsp::GetRoute()
{
	double * temp=new double[dimension];
	for(int i=0;i<dimension;i++)
		temp[i]=route[i];
	return temp;
}

void AntTsp::SetRoute(double * r)
{
	for(int i=0;i<dimension;i++)
		route[i]=(int)r[i];
	adaptation=adapt->adaption(r);
}

void AntTsp::Store(FILE * file1,FILE * file2)
{
	for(int i=0;i<dimension;i++)
		fprintf(file1,"%d    ",route[i]);
	fprintf(file1,"\n");
	fprintf(file2,"%f\n",adaptation);
}

AntTsp::~AntTsp()
{
	delete[] route;
}

⌨️ 快捷键说明

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