elitist.c

来自「gaotv5,一个著名的遗传算法工具箱.安装在任意目录」· C语言 代码 · 共 53 行

C
53
字号

/*
 *  GENESIS  Copyright (c) 1986, 1990 by John J. Grefenstette
 *  This program may be freely copied for educational
 *  and research purposes.  All other rights reserved.
 *
 *  file:	elitist.c
 *
 *  purpose:	The elitist policy stipulates that the best individual
 *		always survives into the new generation.  The elite
 *		individual is placed in the last position in New pop,
 *		and is not changed through crossover or mutation.
 *
 *  modified:	24 mar 86
 */

#include "extern.h"

Elitist()
{
	register int i;		/* loop control variables */
	register int k;
	register int found;	/* set if elite one is present */


	Trace("Elitist entered");

	/* is any element in the current population		*/
	/* identical to the Best guy in the last Generation?	*/
	for (i=0, found=0; i<Popsize && (!found); i++)
		for (k=0, found=1; (k<Bytes) && (found); k++)
			found = (New[i].Gene[k] 
			    == Old[Best_guy].Gene[k]);

	if (!found)	/* elite one was not present */
	{
		/* replace last guy with the elite one */
		for (k=0; k<Bytes; k++)
			New[Popsize-1].Gene[k] = Old[Best_guy].Gene[k];
		New[Popsize-1].Perf = Old[Best_guy].Perf;
		New[Popsize-1].Needs_evaluation = 0;
		if (Traceflag)
		{
			printf("perf: %e\n", New[Popsize-1].Perf);
		}
	}

	Trace("Elitist completed");
}


/*** end of file ***/

⌨️ 快捷键说明

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