www.pudn.com > GA_VRPTW.rar > ga.cpp, change:2005-06-15,size:1730b


#include "ga.h" 
main() 
{    
    outfile.open("result.dat",ios::out); 
	InitializeIE();     //Import 
	outfile<<"\n ----------------------------------------------------- "; 
	outfile<<"\n The numbers of Import="<<ImportNum 
	       <<"\n The loading vehicle probility="<<VehicleRate 
	       <<"\n The VehicleLoad="<<VehicleLoad 
		   <<"\n The vehicle speed="<<speed 
		   <<"\n The max generation="<<maxgen 
		   <<"\n The early exit probility="<<probility<<endl; 
	outfile<<"\n ----------------------------------------------------- "; 
	InitializeData();   //parameter 
	InitializeReport(); //print parameter 
	InitializeMemory();  //ʼoldpop, 
	gen=0; 
	Initializepop(); 
	if (avgfitness/maxfitness<probility) 
		success=false; 
	else success=true; 
	while((gen<maxgen)&&(!success)&&(maxbest<80)) 
	{ 
		gen++; 
		select(); 
		generate(); 
		ComputeFitness(newpop); 
		Statistics(newpop); 
		Report(); 
		p1=oldpop; 
		oldpop=newpop; 
		newpop=p1; 
	}// end while Ŵ 
	outfile<<"\n ----------------THE BEST PATH IS----------------- "; 
	outfile<<"\n -----------------------------------------------------\n "; 
	for (int j=0;j<lchrom;j++) 
		outfile<<bestfit.chrom[j]<<" ";   
	outfile<<"\n ----------------------------------------------------- "; 
	outfile<<"\n ----------------------------------------------------- "; 
	for (j=0;j<popsize;j++) 
	{ 
		delete[] oldpop[j].chrom; 
		oldpop[j].chrom=0; 
		delete[] newpop[j].chrom; 
		newpop[j].chrom=0; 
		//delete[] p1[j].chrom; 
	//	p1[j].chrom=0; 
	} 
	delete[] bestfit.chrom; 
	bestfit.chrom=0; 
	delete[] oldpop; 
    oldpop=0; 
	delete[] newpop; 
    newpop=0; 
	p1=0; 
	delete[] dd; 
	dd=0; 
	delete[] ff; 
	ff=0; 
	delete[] PtrIP; 
	PtrIP=0; 
	return 0; 
}