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

📄 geqo_recombination.c

📁 关系型数据库 Postgresql 6.5.2
💻 C
字号:
/*------------------------------------------------------------------------** geqo_recombination.c*	 misc recombination procedures** $Id: geqo_recombination.c,v 1.7.2.1 1999/08/02 05:57:06 scrappy Exp $**-------------------------------------------------------------------------*//* contributed by:   =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=   *  Martin Utesch				 * Institute of Automatic Control	   *   =							 = University of Mining and Technology =   *  utesch@aut.tu-freiberg.de  * Freiberg, Germany				   *   =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= *//* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */#include "postgres.h"#include "optimizer/geqo_random.h"#include "optimizer/geqo_recombination.h"/* * init_tour * *	 Randomly generates a legal "traveling salesman" tour *	 (i.e. where each point is visited only once.) *	 Essentially, this routine fills an array with all possible *	 points on the tour and randomly chooses the 'next' city from *	 this array.  When a city is chosen, the array is shortened *	 and the procedure repeated. * */voidinit_tour(Gene *tour, int num_gene){	Gene	   *tmp;	int			remainder;	int			next,				i;	tmp = (Gene *) palloc(num_gene * sizeof(Gene));	for (i = 0; i < num_gene; i++)	{		tmp[i] = (Gene) i + 1;	/* builds tours "1 - 2 - 3" etc. */	}	remainder = num_gene - 1;	for (i = 0; i < num_gene; i++)	{		next = (int) geqo_randint(remainder, 0);		/* choose city between 0														 * and remainder */		tour[i] = tmp[next];		tmp[next] = tmp[remainder];		remainder--;	}	pfree(tmp);}/* alloc_city_table * *	 allocate memory for city table * */City *alloc_city_table(int num_gene){	City	   *city_table;	/*	 * palloc one extra location so that nodes numbered 1..n can be	 * indexed directly; 0 will not be used	 */	city_table = (City *) palloc((num_gene + 1) * sizeof(City));	return city_table;}/* free_city_table * *	  deallocate memory of city table * */voidfree_city_table(City *city_table){	pfree(city_table);}

⌨️ 快捷键说明

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