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

📄 tsgenepool__define.bak

📁 该程序应用了遗传算法解决了旅行售货问题。并模拟该过程。
💻 BAK
字号:
FUNCTION TsGenePool::CreateRandomChromosome
	;function randomly sorts the gene and Returns the new order
	index = Sort(Randomu(seed,self.numGenes))
	xPos = (*self.x)[index]
	yPos = (*self.y)[index]
	names = (*self.names)[index]
	;create the new chromosome from the reorderd positions
	randomChromosome = Obj_New('tsChromosome',
								numGenes=self.numGenes, $
								xPos=xPos,
								yPos=yPos,
								names=names
								)

	Return,randomChromosome
END

;{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|

FUNCTION TsGenePool::Init, numGenes
	;create the gene pool with a set of random positions
	;After they are created the positions never change, just the traversal order.
	self.numGenes = numGenes
	self.x = Ptr_New(Randomu(s,numGenes)*100.)
	self.y = Ptr_New(Randomu(s,numGenes)*100.)
	;when mating two chromosomes we need to be able to identIFy each gene.
	;The next line creates random 10 character strings as the "city names"
	self.names = Ptr_New(String(Byte(Randomu(seed,10,numGenes)*26 + 97.0)))

	Return,1
END
;{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|

PRO TsGenePool::cleanup
	;free the pointers
	IF Ptr_Valid(self.x) 	 THEN Ptr_Free,self.x
	IF Ptr_Valid(self.y) 	 THEN Ptr_Free,self.y
	IF Ptr_Valid(self.names) THEN Ptr_Free,self.names

	Return
END

;{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|

PRO TsGenePool__Define

	void = { TsGenePool				,$
	         numGenes 	: 0L		,$ ;number of genes
	         x 			: Ptr_New()	,$ ;x position
	         y 			: Ptr_New()	,$ ;y position
	         names 		: Ptr_New() } ;unique name for identification
	Return
END

⌨️ 快捷键说明

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