www.pudn.com > ga-tsp.rar > PopNode.cpp
// PopNode.cpp: implementation of the PopNode class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "China45.h"
#include "PopNode.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
PopNode::PopNode():cost(MAXCOST),fit(0)
{
chrom=new int[MAXCHROM];
path=new int[MAXCHROM];
for(int i=0;iCopyNode(&temp);
}
//交叉两条基因
void PopNode::CrossTwo(PopNode *pop, int nPos)
{
int tmpPath[MAXCHROM];
for(int i=1;ichrom[i]; pop->chrom[i]=temp;
}
tmpPath[0]=0;for(i=1;ichrom[i];
//临时路径置入当前城市i
while(tmpPath[m]!=MAXCHROM)
{
m=(m+1)%MAXCHROM; if(m==0) m=1;
}
tmpPath[m]=i;
}
for(i=1;ipath[i]=tmpPath[i]; pop->chrom[tmpPath[i]]=i;
}
//重新整理this基因城市位置和路径关系
tmpPath[0]=0;for(i=1;ichrom[i]; path[i]=pop->path[i];
}
cost=pop->cost; fit=pop->fit;
}