📄 locationtsplocation.cpp
字号:
// LocationTSPLocation.cpp: implementation of the LocationTSPLocation class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "LocationTSPLocation.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
LocationTSPLocation::LocationTSPLocation(int d,Adaptability * a,FILE * f1,FILE * f2):LocationTSP(d,a,f1,f2)
{
}
void LocationTSPLocation::NewLocation(ParticleTSP * * sworm,int i)
{
double * location=sworm[i]->GetLocation();
int * * speed=sworm[i]->GetSpeed();
int length=sworm[i]->GetSL();
int * n_s_location=new int[dimension]; //新速度中有哪些城市
for(int j=0;j<dimension;j++)
n_s_location[j]=0;
for(j=0;j<length;j++)
{
n_s_location[speed[j][0]]=1;
//找出速度中的片断在编码中的位置
int p1=0;
while(location[p1]!=speed[j][0])
p1++;
int p2=0;
while(location[p2]!=speed[j][1])
p2++;
n_s_location[speed[j][1]]=1;
if(p1>p2)
{
int temp=p1;
p1=p2;
p2=temp;
}
for(int i=0;i<(p2-p1)/2;i++) //翻转
{
int temp=location[p1+i+1];
location[p1+i+1]=location[p2-i];
location[p2-i]=temp;
}
}
for(j=0;j<dimension;j++)
{
fprintf(file1,"%f ",location[j]);
}
fprintf(file1,"\n");
sworm[i]->SetLocation(location);
double n=adapt->adaption(location);
sworm[i]->SetSolution(n);
fprintf(file2,"%f\n",n);
delete[] n_s_location;
delete[] location;
for(j=0;j<length;j++)
delete[] speed[j];
delete[] speed;
}
LocationTSPLocation::~LocationTSPLocation()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -