Пример #1
0
/*
 * random_init_pool
 *		initialize genetic pool
 */
void
random_init_pool(planner_info_n *root, Pool *pool)
{
	Chromosome* chromo = (Chromosome *) pool->data;
	int i;

	for (i = 0; i < pool->size; i++) {
		init_tour(root, chromo[i].string, pool->string_length);
		pool->data[i].worth = geqo_eval(root, chromo[i].string, pool->string_length);
	}
}
Пример #2
0
/*
 * random_init_pool
 *		initialize genetic pool
 */
void
random_init_pool(PlannerInfo *root, Pool *pool)
{
	Chromosome *chromo = (Chromosome *) pool->data;
	int			i;
	int			bad = 0;

	/*
	 * We immediately discard any invalid individuals (those that geqo_eval
	 * returns DBL_MAX for), thereby not wasting pool space on them.
	 *
	 * If we fail to make any valid individuals after 10000 tries, give up;
	 * this probably means something is broken, and we shouldn't just let
	 * ourselves get stuck in an infinite loop.
	 */
	i = 0;
	while (i < pool->size)
	{
		init_tour(root, chromo[i].string, pool->string_length);
		pool->data[i].worth = geqo_eval(root, chromo[i].string,
										pool->string_length);
		if (pool->data[i].worth < DBL_MAX)
			i++;
		else
		{
			bad++;
			if (i == 0 && bad >= 10000)
				elog(ERROR, "geqo failed to make a valid plan");
		}
	}

#ifdef GEQO_DEBUG
	if (bad > 0)
		elog(DEBUG1, "%d invalid tours found while selecting %d pool entries",
			 bad, pool->size);
#endif
}