亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? smthga.c

?? 很程式化的標(biāo)準(zhǔn)遺傳算法程序
?? C
字號(hào):
/**************************************************************************/
/* This is a simple genetic algorithm implementation where the */
/* evaluation function takes positive values only and the      */
/* fitness of an individual is the same as the value of the    */
/* objective function                                          */
/**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
/* Change any of these parameters to match your needs */
#define POPSIZE 50               /* population size */
#define MAXGENS 1000             /* max. number of generations */
#define NVARS 2                  /* no. of problem variables */
#define PXOVER 0.7               /* probability of crossover */
#define PMUTATION 0.05           /* probability of mutation */
#define TRUE 1
#define M_PI 3.14159265358979323846

#define FALSE 0
int generation;                  /* current generation no. */
int cur_best;                    /* best individual */
FILE *galog;                     /* an output file */
struct genotype /* genotype (GT), a member of the population */
{
	double gene[NVARS];        /* a string of variables */
	double fitness;            /* GT's fitness */
	double upper[NVARS];       /* GT's variables upper bound */
	double lower[NVARS];       /* GT's variables lower bound */
	double rfitness;           /* relative fitness */
	double cfitness;           /* cumulative fitness */
};
struct genotype population[POPSIZE+1];    /* population */
struct genotype newpopulation[POPSIZE+1]; /* new population; */
                                          /* replaces the */
                                          /* old generation */
/* Declaration of procedures used by this genetic algorithm */
void initialize(void);
double randval(double, double);
void evaluate(void);
void keep_the_best(void);
void elitist(void);
void select(void);
void crossover(void);
void Xover(int,int);
void swap(double *, double *);
void mutate(void);
void report(void);
/***************************************************************/
/* Initialization function: Initializes the values of genes    */
/* within the variables bounds. It also initializes (to zero)  */
/* all fitness values for each member of the population. It    */
/* reads upper and lower bounds of each variable from the      */
/* input file `gadata.txt'. It randomly generates values       */
/* between these bounds for each gene of each genotype in the  */
/* population. The format of the input file `gadata.txt' is    */
/* var1_lower_bound var1_upper bound                           */
/* var2_lower_bound var2_upper bound ...                       */
/***************************************************************/
void initialize(void)
{
	FILE *infile;


	int i, j;
	double lbound, ubound;
	if ((infile = fopen("gadata.txt","r"))==NULL)
	{
		fprintf(galog,"\nCannot open input file!\n");
		exit(1);
	}
	/* initialize variables within the bounds */
	for (i = 0; i < NVARS; i++)
    {
		fscanf(infile, "%lf",&lbound);
		fscanf(infile, "%lf",&ubound);
	  

		for (j = 0; j < POPSIZE; j++)
		{
			population[j].fitness = 0;
			population[j].rfitness = 0;
			population[j].cfitness = 0;
			population[j].lower[i] = lbound;
			population[j].upper[i]= ubound;
			population[j].gene[i] = randval(population[j].lower[i],
				population[j].upper[i]);
		}

	}
	fclose(infile);
}

/***********************************************************/
/* Random value generator: Generates a value within bounds */
/***********************************************************/
double randval(double low, double high)
{
	double val;
	val = ((double)(rand()%1000)/1000.0)*(high - low) + low;
	//val = ((double)(rand()/RAND_MAX)*(high - low)) + low;
	return(val);
}

/*************************************************************/
/* Evaluation function: This takes a user defined function.  */
/* Each time this is changed, the code has to be recompiled. */
/*************************************************************/
void evaluate(void)
{
	int mem;
	int i;
	double x[NVARS+1];
	for (mem = 0; mem < POPSIZE; mem++) {
		for (i = 0; i < NVARS; i++)
			x[i+1] = population[mem].gene[i];
		/*adapt this according to your need*/
		population[mem].fitness = fabs(sin(M_PI*(x[1]-3))/(M_PI*(x[1]-3)))*fabs(sin(M_PI*(x[2]-3))/(M_PI*(x[2]-3)));
	}
}

/***************************************************************/
/* Keep_the_best function: This function keeps track of the    */
/* best member of the population. Note that the last entry in  */
/* the array Population holds a copy of the best individual    */
/***************************************************************/
void keep_the_best()
{
	int mem;
	int i;
	cur_best = 0; /* stores the index of the best individual */
	for (mem = 0; mem < POPSIZE; mem++)
    {
		if (population[mem].fitness > population[POPSIZE].fitness)
		{
			cur_best = mem;
			population[POPSIZE].fitness = population[mem].fitness;
		}
	}
	/* once the best member in the population is found, copy the genes */
	for (i = 0; i < NVARS; i++)
		population[POPSIZE].gene[i] = population[cur_best].gene[i];
}

/****************************************************************/
/* Elitist function: The best member of the previous generation */
/* is stored as the last in the array. If the best member of    */
/* the current generation is worse then the best member of the  */
/* previous generation, the latter one would replace the worst  */
/* member of the current population                             */
/****************************************************************/
void elitist()
{
	int i;
	double best, worst;             /* best and worst fitness values */
	int best_mem, worst_mem;		/* indexes of the best and worst member */

	best = population[0].fitness;
	worst = population[0].fitness;
	for (i = 0; i < POPSIZE - 1; ++i) {
		if(population[i].fitness > population[i+1].fitness) {
            if (population[i].fitness >= best) {
				best = population[i].fitness;
				best_mem = i;
			}
            if (population[i+1].fitness <= worst) {
				worst = population[i+1].fitness;
				worst_mem = i + 1;
			}
		} else {
			if (population[i].fitness <= worst) {
				worst = population[i].fitness;
				worst_mem = i;
			}
			if (population[i+1].fitness >= best) {
				best = population[i+1].fitness;
				best_mem = i + 1;
			}
		}
	}
	/* if best individual from the new population is better than */
	/* the best individual from the previous population, then    */
	/* copy the best from the new population; else replace the   */
	/* worst individual from the current population with the     */
	/* best one from the previous generation                     */
	if (best >= population[POPSIZE].fitness) {
		for (i = 0; i < NVARS; i++)
			population[POPSIZE].gene[i] = population[best_mem].gene[i];
		population[POPSIZE].fitness = population[best_mem].fitness;
    } else {
		for (i = 0; i < NVARS; i++)
			population[worst_mem].gene[i] = population[POPSIZE].gene[i];
		population[worst_mem].fitness = population[POPSIZE].fitness;
	}
}


/**************************************************************/
/* Selection function: Standard proportional selection for    */
/* maximization problems incorporating elitist model - makes  */
/* sure that the best member survives                         */
/**************************************************************/
void select(void)
{
	int mem, i, j;
	double sum = 0;
	double p;
	/* find total fitness of the population */
	for (mem = 0; mem < POPSIZE; mem++) {
		sum += population[mem].fitness;
	}
	/* calculate relative fitness */
	for (mem = 0; mem < POPSIZE; mem++) {
		population[mem].rfitness =  population[mem].fitness/sum;
	}
	population[0].cfitness = population[0].rfitness;
	/* calculate cumulative fitness */
	for (mem = 1; mem < POPSIZE; mem++) {
		population[mem].cfitness =  population[mem-1].cfitness + population[mem].rfitness;
	}
	/* finally select survivors using cumulative fitness. */
	for (i = 0; i < POPSIZE; i++) {
		p = rand()%1000/1000.0;
		//p = (double)rand()/RAND_MAX;
		if (p < population[0].cfitness)
			newpopulation[i] = population[0];
		else {
			for (j = 0; j < POPSIZE;j++)
				if (p >= population[j].cfitness && p<population[j+1].cfitness)
					newpopulation[i] = population[j+1];
		}
	}
	/* once a new population is created, copy it back */
	for (i = 0; i < POPSIZE; i++)
		population[i] = newpopulation[i];
}

/***************************************************************/
/* Crossover selection: selects two parents that take part in  */
/* the crossover. Implements a single point crossover          */
/***************************************************************/
void crossover(void)
{
	int  mem, one;
	int first  =  0; /* count of the number of members chosen */
	double x;
	for (mem = 0; mem < POPSIZE; ++mem) {
		x = rand()%1000/1000.0;
		//x = rand()/RAND_MAX;
		if (x < PXOVER) {
			++first;
			if (first % 2 == 0)
				Xover(one, mem);
			else
				one = mem;
		}
	}
}

/**************************************************************/
/* Crossover: performs crossover of the two selected parents. */
/**************************************************************/
void Xover(int one, int two)
{
	int i;
	int point; /* crossover point */
	/* select crossover point */
	if(NVARS > 1) {
		if(NVARS == 2)
			point = 1;
		else
			point = (rand() % (NVARS - 1)) + 1;
		for (i = 0; i < point; i++)
			swap(&population[one].gene[i], &population[two].gene[i]);
	}
}

/*************************************************************/
/* Swap: A swap procedure that helps in swapping 2 variables */
/*************************************************************/
void swap(double *x, double *y)
{
	double temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

/**************************************************************/
/* Mutation: Random uniform mutation. A variable selected for */
/* mutation is replaced by a random value between lower and   */
/* upper bounds of this variable                              */
/**************************************************************/
void mutate(void)
{
	int i, j;
	double lbound, hbound;
	double x;
	for (i = 0; i < POPSIZE; i++) {
		for (j = 0; j < NVARS; j++) {
			x = rand()%1000/1000.0;
			//x = (double)rand()/RAND_MAX;
			if (x < PMUTATION) {
				/* find the bounds on the variable to be mutated */
				lbound = population[i].lower[j];
				hbound = population[i].upper[j];
				population[i].gene[j] = randval(lbound, hbound);
			}
		}
	}
}

/***************************************************************/
/* Report function: Reports progress of the simulation. Data   */
/* dumped into the  output file are separated by commas        */
/***************************************************************/
void report(void)
{
	int i;
	double best_val;            /* best population fitness */
	double avg;                 /* avg population fitness */
	double stddev;              /* std. deviation of population fitness */
	double sum_square;          /* sum of square for std. calc */
	double square_sum;          /* square of sum for std. calc */
	double sum;                 /* total population fitness */
	
	sum = 0.0;
	sum_square = 0.0;
	for (i = 0; i < POPSIZE; i++) {
		sum += population[i].fitness;
		sum_square += population[i].fitness * population[i].fitness;
	}
	avg = sum/(double)POPSIZE;
	square_sum = avg * avg * POPSIZE;
	stddev = sqrt((sum_square - square_sum)/(POPSIZE - 1));
	best_val = population[POPSIZE].fitness;
	fprintf(galog, "\n%5d,      %6.3f, %6.3f, %6.3f \n\n", 
		generation, best_val, avg, stddev);
}

/**************************************************************/
/* Main function: Each generation involves selecting the best */
/* members, performing crossover & mutation and then          */
/* evaluating the resulting population, until the terminating */
/* condition is satisfied                                     */
/**************************************************************/
int main(void)
{
	int i;
	if ((galog = fopen("galog.txt","w"))==NULL) {
		exit(1);
	}
	srand(time(NULL));
	generation = 0;
	fprintf(galog, "\n generation  best  average  standard \n");
	fprintf(galog, " number      value fitness  deviation \n");
	initialize();
	evaluate();
	keep_the_best();
	while(generation<MAXGENS) {
		generation++;
		select();
		crossover();
		mutate();
		report();
		evaluate();
		elitist();
	}
	fprintf(galog,"\n\n Simulation completed\n");
	fprintf(galog,"\n Best member: \n");
	for (i = 0; i < NVARS; i++) {
		fprintf (stdout,"\n var(%d) = %f",i,population[POPSIZE].gene[i]);
		fprintf (galog,"\n var(%d) = %f",i,population[POPSIZE].gene[i]);
	}
	fprintf(stdout,"\n\n Best fitness = %f",population[POPSIZE].fitness);
	fprintf(galog,"\n\n Best fitness = %f",population[POPSIZE].fitness);
	fclose(galog);
	printf("\n Success\n");
	return 0;
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲自拍偷拍图区| a级精品国产片在线观看| 舔着乳尖日韩一区| 亚洲成人资源网| 亚洲一区二区中文在线| 亚洲激情中文1区| 夜夜夜精品看看| 婷婷国产在线综合| 免播放器亚洲一区| 九九国产精品视频| 国产精品影视网| 成人少妇影院yyyy| 色综合天天综合狠狠| 欧美亚洲国产bt| 欧美日韩www| 欧美zozozo| 国产欧美日产一区| 亚洲欧美日韩国产手机在线| 一区二区日韩电影| 男人的天堂亚洲一区| 国产一区久久久| 成人av在线电影| 欧美中文字幕一二三区视频| 91精品在线麻豆| 欧美精品一区二区不卡| 欧美激情中文不卡| 亚洲伦理在线免费看| 午夜精品久久久久久久| 精品一区二区久久| 99久久综合狠狠综合久久| 欧美亚洲一区二区在线观看| 日韩亚洲欧美成人一区| 国产拍欧美日韩视频二区| 亚洲免费观看高清完整版在线观看熊| 亚洲自拍偷拍图区| 国产麻豆午夜三级精品| 色老汉av一区二区三区| 欧美一区二区久久久| 欧美国产丝袜视频| 亚洲高清不卡在线| 国产乱对白刺激视频不卡 | 欧美撒尿777hd撒尿| 日韩区在线观看| 亚洲欧洲日本在线| 毛片av一区二区| 不卡视频一二三| 欧美一区二区三区四区视频| 国产精品高潮呻吟久久| 日本美女一区二区三区| 国产91色综合久久免费分享| 欧美精品一二三区| 国产精品欧美综合在线| 日韩黄色免费电影| 99久久精品国产导航| 91精品国产91综合久久蜜臀| 国产精品嫩草99a| 日韩av网站免费在线| 99热在这里有精品免费| 精品久久久久久久久久久久包黑料 | 欧美精品欧美精品系列| 国产精品二三区| 理论片日本一区| 欧美自拍丝袜亚洲| 17c精品麻豆一区二区免费| 精品一区二区三区不卡| 欧美美女喷水视频| 综合久久国产九一剧情麻豆| 国产一区91精品张津瑜| 欧美久久久影院| 亚洲欧美日韩电影| 成人黄色小视频| 精品国产乱码久久久久久蜜臀 | 精品亚洲免费视频| 精品视频在线看| 亚洲人成在线播放网站岛国| 国产黄色精品网站| 日韩一区二区免费视频| 亚洲第一福利一区| 色94色欧美sute亚洲线路二| 国产精品灌醉下药二区| 国产成人一区二区精品非洲| 日韩女优视频免费观看| 日韩电影网1区2区| 欧美精品日韩精品| 午夜久久久久久久久久一区二区| 色94色欧美sute亚洲线路二 | 国产福利视频一区二区三区| 日韩三级电影网址| 麻豆精品视频在线观看| 69p69国产精品| 天天色图综合网| 欧美日韩视频在线一区二区| 亚洲福利一区二区三区| 欧美丝袜第三区| 亚洲一区二区三区四区在线免费观看 | 日韩精品资源二区在线| 日韩高清不卡一区二区| 欧美另类久久久品| 日韩国产成人精品| 日韩欧美另类在线| 狠狠久久亚洲欧美| 亚洲精品一线二线三线| 九九热在线视频观看这里只有精品| 欧美一区二区大片| 久久国产尿小便嘘嘘尿| 精品理论电影在线| 激情欧美一区二区| 国产农村妇女毛片精品久久麻豆| 国产精品一区二区免费不卡| 国产三级欧美三级日产三级99 | 这里只有精品电影| 日韩国产欧美一区二区三区| 日韩美女在线视频 | 欧美日韩视频专区在线播放| 午夜不卡av在线| 日韩区在线观看| 国产一区美女在线| 亚洲欧美在线观看| 欧美最新大片在线看| 丝袜脚交一区二区| 欧美精品一区二区三区在线| 国产精品 日产精品 欧美精品| 国产精品日日摸夜夜摸av| 91在线你懂得| 亚洲成av人片在www色猫咪| 日韩欧美一二三四区| 国产精品一区二区三区网站| 亚洲色图20p| 91精品国模一区二区三区| 狠狠色综合播放一区二区| 中文字幕一区二区三区精华液| 欧美在线观看一二区| 日本网站在线观看一区二区三区 | 久久99精品国产91久久来源| 国产欧美日韩精品一区| 在线欧美一区二区| 蜜臀久久99精品久久久画质超高清 | 精品日韩欧美一区二区| 99久久国产免费看| 午夜久久久久久久久| 久久久久国产精品麻豆ai换脸| 一本大道久久a久久综合婷婷| 午夜精品一区二区三区电影天堂 | 日韩欧美一级二级三级| 成人av片在线观看| 免费观看在线色综合| 亚洲国产精华液网站w | 亚洲精品国产a| 精品国产一区二区三区四区四| 91亚洲男人天堂| 久草中文综合在线| 中文字幕综合网| 精品成人a区在线观看| 欧美午夜片在线看| 成人性视频免费网站| 日韩av一区二| 亚洲精品欧美专区| 久久久美女毛片| 在线成人免费观看| 99久久久国产精品免费蜜臀| 精品亚洲免费视频| 五月开心婷婷久久| 国产精品家庭影院| 337p日本欧洲亚洲大胆精品| 欧美日韩小视频| 成人h版在线观看| 午夜国产不卡在线观看视频| 中日韩av电影| 精品乱人伦小说| 欧美性大战xxxxx久久久| 不卡的av在线播放| 激情综合色播五月| 日韩综合小视频| 亚洲精品乱码久久久久久| 日本一区二区免费在线| 日韩一区二区三区视频在线| 欧美在线观看视频一区二区| 国产一区二区视频在线| 日韩vs国产vs欧美| 亚洲综合在线五月| 亚洲人一二三区| 国产午夜精品久久久久久免费视 | 99免费精品在线观看| 国产精品一区二区视频| 久久99这里只有精品| 亚洲成人福利片| 亚洲精品免费在线观看| 亚洲欧洲一区二区在线播放| 久久精品视频在线看| 欧美va亚洲va| 欧美不卡在线视频| 日韩欧美卡一卡二| 日韩一级完整毛片| 91超碰这里只有精品国产| 日本道免费精品一区二区三区| 成人午夜碰碰视频| 成人av影院在线| a4yy欧美一区二区三区| 粉嫩一区二区三区性色av| 国产高清一区日本|