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

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

?? ga.c

?? 用C++實(shí)現(xiàn)的遺傳算法
?? C
字號(hào):
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <conio.h>
#include <dos.h>

#define NAME_MAX 80


void
ga(char *datFile)
{
	/* request autodetection */
	int gdriver=DETECT,gmode,errorcode;
	int prex,bprey,curx,bcury,mprey,mcury,
			wprey,wcury,vprey,vcury;
  //	int maxcolor,ystep;
	double temp;

	time_t	begin,finish;

	char    Msg[NAME_MAX];
	char    patternFile[NAME_MAX], weightFile[NAME_MAX],
			resultFile[NAME_MAX];
	int     **population;
	double  **pattern, **target;
	double *fit;
	int     M,N,H,iter,P,K;  /* K: each weight represented by K bits */
			/*  M: pattern no.;  N: input dim;  H: hidden No. */
			/* iter: generation number;  P: output dim */
	int  status, popsize,length,total,TOTAL;
		/* total: total pattern number */
	double c_rate, m_rate,criti; /* crossover and mutate rate */
	int i,j,te;    /* te: flag for termination (1) */
	int     ind;    /* index for the best fitness */
	double max,mean,worst;
	int	 m_t;
	int flag_m;     /* flag for mutatation, 1, variable, 0 cons */
	int flag_c;		/* 0: one, 1: uniform, 2: two */
	int fit_shift;  /* shift fitness, 1:yes, 0:no */
	int true;
	char condition;
	double *gau;    /* store gaussian function value */
	double vari;	/* variance value of fitness vector */
	double rm_rate;	/* real mutate probability */

	FILE *fp1;

	extern void initiali(int **,int,int);
	extern void fitness(int **,double *,int,int,double **,double **,
			int,int,int,int,int,int *, char *,char *,double,int,int);
	extern void selectio(int **,double *,int,int,int,int);
	extern void crossove(int **,int,int,double,int,int);
	extern void Bmutate(int *,double,int,int,int,double *);

	extern int maximum(double *,int);
	extern double average(double *,int);
	extern double minimial(double *,int);
	extern double gaussian(double);
	extern double variance(double *,double,int);

	
	int getParams(char *,char *,char *,char *, int *,
					int *,int *,int *,int *,int *,int *,int *,
					double *,double *,double *,int *,int *,int *,
					int *);
	void savePara(FILE *,char *,char *,char *,char *, int ,
					int,int,int,int,int,int,int ,int,
					double,double,double,int,int,int,
					int);
	int getPattern(char *,double **,double **,int *,int,int,int);
	/* get parameters from runFile */

	int c_break(void);


	begin=time(NULL);

	status=getParams(datFile,patternFile,weightFile,resultFile,
					&H,&iter,&K,&N,&P,&M,&total,&popsize,&c_rate,&m_rate,
					&criti,&flag_m,&fit_shift,&m_t,&flag_c);
	if (status!=1)
	{
		printf("something wrong with open %s\n",datFile);
		exit(1);
	}

	if (M>total)
	{
		printf("training patterns should be less than total patterns\n");
		exit(1);
	}

	length=((N+1)*H+(H+1)*P)*K;      /* length of indiviudal */

	savePara(stderr,datFile,patternFile,weightFile,resultFile,
					H,iter,K,N,P,M,total,popsize,length,c_rate,m_rate,
					criti,flag_m,fit_shift,m_t,flag_c);

	do
	{
		printf("check, then selection, c: continue; q:quit\n");
		scanf("%c",&condition);
		switch(condition)
		{
			case 'c': true=0;
				break;
			case 'C': true=0;
				break;
			case 'q': exit(1);
			case 'Q': exit(1);
			default: true=1;

		}
	}
	while (true==1);

	/* assign space to matrix and vector */

	pattern=(double **)calloc(total,sizeof(double *));
	for (i=0;i<total;i++)
		pattern[i]=(double *)calloc(N,sizeof(double));

	target=(double **)calloc(total,sizeof(double *));
	for (i=0;i<total;i++)
		target[i]=(double *)calloc(P,sizeof(double));

	population=(int **)calloc(popsize,sizeof(int *));
	for (i=0;i<popsize;i++)
		population[i]=(int *)calloc(length,sizeof(int));

	fit=(double *)calloc(popsize,sizeof(double));

	gau=(double *)calloc(K,sizeof(double));

	/* obtain training pattern pair from pattern file */
	status=getPattern(patternFile,pattern,target,&TOTAL,N,P,total);

	if (status!=1)
	{
		printf("something wrong with open %s\n",patternFile);
		exit(1);
	}

	/* begin generation  */

	/* itilialization of population */
	initiali(population,popsize,length);


	/* calculate Gaussian fun. as mutation probability */

	for (i=0;i<K;i++)
		gau[i]=gaussian(sqrt(i));

	/* initialize graphics and local variables */
	initgraph(&gdriver,&gmode,"");

	/* read result of initialization */
	errorcode=graphresult();
	if (errorcode !=grOk)
	{
		/* an error occurred */
		printf("Graphics error: %s\n",grapherrormsg(errorcode));
		exit(1);
	}

	ctrlbrk(c_break);
	/* draw x-y */
	line(50,80,50,400);
	line(50,400,500,400);
	prex=50;
	bprey=400;
	mprey=400;
	wprey=400;
	vprey=400;
	moveto(40,80);
	outtext("1");
	moveto(50,70);
	outtext("fitness");
	moveto(25,240);
	outtext("0.5");
	moveto(45,405);
	outtext("0");
	moveto(505,390);
	outtext("generation");
	moveto(500,405);
	sprintf(Msg,"%d",iter);
	outtext(Msg);
	moveto(275,405);
	sprintf(Msg,"%d",iter/2);
	outtext(Msg);
	moveto(500,80);
	setcolor(RED);
	sprintf(Msg,"Best    : ----");
	outtext(Msg);
	moveto(500,110);
	setcolor(YELLOW);
	sprintf(Msg,"Mean    : ----");
	outtext(Msg);
	moveto(500,140);
	setcolor(BLUE);
	sprintf(Msg,"Worst   : ----");
	outtext(Msg);
	moveto(500,170);
	setcolor(WHITE);
	sprintf(Msg,"Variance: ----");
	outtext(Msg);

/*	maxcolor=getmaxcolor();

	moveto(500,200);
	ystep=0;
	for (i=0;i<=maxcolor;i++)
	{
		if (getx()>630)
		{
			ystep++;
			moveto(500,(200+ystep*20));
		}
		setcolor(i);
		sprintf(Msg,"%d ",i);
		outtext(Msg);

	}
*/

	gotoxy(5,2);
	printf(" Index     Best      Mean       Worst     Variance ");

	te=0;
	for (i=0;i<=iter;i++)
	{
		fitness(population,fit,popsize,length,pattern,target,N,H,P,K,M,
				&te,weightFile,resultFile,criti,total,i);

		if ((te==1)||((i%10)==0))
		{
			ind=maximum(fit,popsize);
			max=fit[ind];
			mean=average(fit,popsize);
			worst=minimial(fit,popsize);
			vari=variance(fit,mean,popsize);
			temp=(450*1.0)/iter;
			temp *=i;
			curx =50+(int)temp;
			bcury=400-(int)((400-80)*max);
			mcury=400-(int)((400-80)*mean);
			wcury=400-(int)((400-80)*worst);
			vcury=400-(int)((400-80)*vari);
			gotoxy(5,3);
			printf(" %4.4d  %10.6f %10.6f %10.6f %10.6f  ",i,max,mean,worst,vari);
			if (i!=0)
			{
				setcolor(RED);
				line(prex,bprey,curx,bcury);
				setcolor(YELLOW);
				line(prex,mprey,curx,mcury);
				setcolor(BLUE);
				line(prex,wprey,curx,wcury);
				setcolor(WHITE);
				line(prex,vprey,curx,vcury);
			}
			prex=curx;
			bprey=bcury;
			mprey=mcury;
			wprey=wcury;
			vprey=vcury;
		}

		if ((te==1)||(i==iter))
		{
			gotoxy(5,4);
			printf(" completed\t");
			if ((fp1=fopen(resultFile,"a"))==NULL)
			{
				fprintf(stderr,"cannot open %s for writing\n",resultFile);
				exit(1);
			}
			savePara(fp1,datFile,patternFile,weightFile,resultFile,
					H,iter,K,N,P,M,total,popsize,length,c_rate,m_rate,
					criti,flag_m,fit_shift,m_t,flag_c);

			fprintf(fp1,"generation: %d\n",i);
			fprintf(fp1,"begin time at: %s\n",ctime(&begin));
			finish=time(NULL);
			fprintf(fp1,"finish time at: %s\n",ctime(&finish));
			fclose(fp1);


			printf(" Press any key to quit");
			getch();
			closegraph();
			exit(1);
		}

		selectio(population,fit,popsize,length,ind,fit_shift);

		crossove(population,length,popsize,c_rate,ind,flag_c);

		rm_rate=m_rate;
		if (m_t==1)
		{
			mean=average(fit,popsize);
			vari=variance(fit,mean,popsize);
			if (vari<0.05)
			{
				status=(int)((0.05-vari)*100) +1;
				rm_rate=status*m_rate;
			}
		}

		for (j=0;j<popsize;j++)
		{
			if (j!=ind)
				Bmutate(population[j],rm_rate,length,K,flag_m,gau);
		}
	}
	/* release the asigned space */
	for (i=0;i<total;i++)
	{
		free(pattern[i]);
		free(target[i]);
	}
	free(pattern);
	free(target);
	free(fit);
	for (i=0;i<popsize;i++)
		free(population[i]);
	free(population);
	free(gau);

	/* clean up */
	gotoxy(5,4);
	printf(" Press any key to quit");
	getch();
	closegraph();

}

int
getParams(char *fileName,char *pFileName,char *wFileName,char *eFileName,
				 int *h,int *cycle,int *k,int *n,int *p,
				 int *m,int *total,int *p_size, double *c_rate,
				 double *m_rate,double *cri,int *f_m,
				 int *f_s,int *m_t,int *flag_c)
/* char *fileName;
char *pFileName;
char *wFileName;
char *eFileName;
int  *h;
int     *cycle;
int     *k;
int     *n;
int     *p;
int     *m;
int     *p_size;
double *c_rate;
double *m_rate;
double *cri; */
{
	FILE    *fp;

	if ((fp=fopen(fileName,"rt"))==NULL)
	{
		fprintf(stderr,"cannot open %s file \n",fileName);
		return 0;
	}


	if (fscanf(fp,"%s",pFileName)==NULL)
	{
		fprintf(stderr,"Error reading patternFileName in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%s",wFileName)==NULL)
	{
		fprintf(stderr,"Error reading weightFileName in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%s",eFileName)==NULL)
	{
		fprintf(stderr,"Error reading errorFileName in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",h)==NULL)
	{
		fprintf(stderr,"Error reading H in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",cycle)==NULL)
	{
		fprintf(stderr,"Error reading Iteration in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",k)==NULL)
	{
		fprintf(stderr,"Error reading K in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",n)==NULL)
	{
		fprintf(stderr,"Error reading N in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",p)==NULL)
	{
		fprintf(stderr,"Error reading P in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",m)==NULL)
	{
		fprintf(stderr,"Error reading M in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",total)==NULL)
	{
		fprintf(stderr,"Error reading total in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",p_size)==NULL)
	{
		fprintf(stderr,"Error reading popsize in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%lf",c_rate)==NULL)
	{
		fprintf(stderr,"Error reading c_rate in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%lf",m_rate)==NULL)
	{
		fprintf(stderr,"Error reading m_rate in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%lf",cri)==NULL)
	{
		fprintf(stderr,"Error reading crition in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",f_m)==NULL)
	{
		fprintf(stderr,"Error reading flag_m in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",f_s)==NULL)
	{
		fprintf(stderr,"Error reading fit_shift in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",m_t)==NULL)
	{
		fprintf(stderr,"Error reading m_t in file %s\n",fileName);
		return 0;
	}

	if (fscanf(fp,"%d",flag_c)==NULL)
	{
		fprintf(stderr,"Error reading flag_c in file %s\n",fileName);
		return 0;
	}
	fclose(fp);

	return 1;
}

void
savePara(FILE * ff,char *fileName,char *pFileName,char *wFileName,char *eFileName,
				 int h,int cycle,int k,int n,int p,
				 int m,int total,int p_size,int len, double c_rate,
				 double m_rate,double cri,int f_m,
				 int f_s,int m_t,int flag_c)
{
	fprintf(ff,"\tdataFile ...................%s\n",fileName);
	fprintf(ff,"\tpatternFile ................%s\n",pFileName);
	fprintf(ff,"\tweightFile .................%s\n",wFileName);
	fprintf(ff,"\tresultFile .................%s\n",eFileName);
	fprintf(ff,"\tH (number of hidden) .......%d\n",h);
	fprintf(ff,"\titer (generation) ..........%d\n",cycle);
	fprintf(ff,"\tK (K bits for eachPara).....%d\n",k);
	fprintf(ff,"\tN (input dim) ..............%d\n",n);
	fprintf(ff,"\tP (output dim) .............%d\n",p);
	fprintf(ff,"\tM (total training pats) ....%d\n",m);
	fprintf(ff,"\ttotal (total pats) .........%d\n",total);
	fprintf(ff,"\tpopsize ....................%d\n",p_size);
	fprintf(ff,"\tlength .....................%d\n",len);
	fprintf(ff,"\tc_rate (crossover) .........%f\n",c_rate);
	fprintf(ff,"\tm_rate (mutation) ..........%f\n",m_rate);
	fprintf(ff,"\tcriti (mean square) ........%f\n",cri);
	fprintf(ff,"\tflag_m (1:var;0:cons) ......%d\n",f_m);
	fprintf(ff,"\tfit_shift (1:yes,0:no) .....%d\n",f_s);
	fprintf(ff,"\tm_t (m_rate(t), 1:y,0:n) ...%d\n",m_t);
	fprintf(ff,"\tflag_c (0:one,1:unif,2:two).%d\n",flag_c);

}


int getPattern(char *fileName,double **in,double **out,int *TOTAL,int n,int p,int total)
/* char *fileName;
double  **in;
double  **out;
int     *TOTAL;
int     n;
int     p;
int     total; */
{

	FILE *fp;

	int i,j;

	if ((fp=fopen(fileName,"rt"))==NULL)
	{
		fprintf(stderr,"Error opening %s\n",fileName);
		return 0;
	}

	fscanf(fp,"%d",TOTAL);

	if(total !=(*TOTAL))
	{
		fprintf(stderr,"total patterns in %s file not match\n",fileName);
		return 0;
	}



	for (i=0;i<total;i++)
	{
		for (j=0;j<n;j++)
			fscanf(fp,"%lf",&(in[i][j]));
		for (j=0;j<p;j++)
			fscanf(fp,"%lf",&(out[i][j]));
	}
	fclose(fp);

	return 1;
}

int c_break(void)
{
	closegraph();
	return 0;
}






?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美在线高清| 亚洲国产一区二区三区| 日本久久精品电影| 精品一区免费av| 亚洲免费资源在线播放| 久久中文字幕电影| 欧美精品在线一区二区| jlzzjlzz亚洲女人18| 久久精品国产亚洲aⅴ| 一区二区三区鲁丝不卡| 国产欧美视频一区二区三区| 欧美情侣在线播放| 日本高清成人免费播放| 成人自拍视频在线观看| 麻豆成人av在线| 亚洲大片在线观看| 亚洲乱码日产精品bd| 国产午夜精品理论片a级大结局| 91精品一区二区三区久久久久久| 色综合久久久久久久久久久| 国产福利电影一区二区三区| 捆绑紧缚一区二区三区视频| 视频一区二区不卡| 亚洲一二三专区| 亚洲三级免费观看| 国产精品麻豆视频| 国产日韩欧美不卡在线| 精品国产乱码久久久久久图片| 69p69国产精品| 欧美日韩日本视频| 欧美日韩亚洲丝袜制服| 欧洲视频一区二区| 色丁香久综合在线久综合在线观看| 成人av免费网站| 粉嫩在线一区二区三区视频| 国产精品中文有码| 国产成人av一区| 国产黄人亚洲片| 国产91精品露脸国语对白| 国产麻豆视频一区二区| 黄页视频在线91| 国产伦精品一区二区三区免费| 久久超级碰视频| 国产在线视频一区二区| 国产一区二区三区视频在线播放| 精品无人区卡一卡二卡三乱码免费卡| 久久国产视频网| 精品在线播放免费| 国内精品不卡在线| 国产传媒久久文化传媒| 国产99久久久国产精品| 成人h精品动漫一区二区三区| 91丨porny丨国产入口| 色婷婷综合久久久久中文 | 久久99久久99| 狠狠色狠狠色合久久伊人| 国产一区二区三区四区五区美女| 国产精品一区二区在线播放| 成人伦理片在线| 在线一区二区三区做爰视频网站| 欧美日韩一区二区在线观看视频 | 男人操女人的视频在线观看欧美| 欧美aa在线视频| 国产精品自在在线| 99久久国产综合色|国产精品| 在线观看一区二区视频| 欧美一区二区三区免费| 久久这里只有精品首页| 中文字幕电影一区| 亚洲国产日日夜夜| 精品一区二区综合| 91丨九色丨尤物| 在线成人高清不卡| 国产欧美日韩精品a在线观看| 亚洲女女做受ⅹxx高潮| 午夜不卡av免费| 国产成人av电影在线| 在线观看亚洲a| 日韩精品影音先锋| 日韩美女精品在线| 免费高清成人在线| 日韩视频在线永久播放| 久久九九国产精品| 亚洲一区在线观看视频| 国产一区美女在线| 一本色道久久综合精品竹菊| 日韩欧美亚洲一区二区| 亚洲同性同志一二三专区| 日本欧美在线观看| 91亚洲精品久久久蜜桃网站 | 日韩一区二区在线免费观看| 国产精品日韩精品欧美在线| 石原莉奈在线亚洲三区| 成人av电影在线播放| 欧美一区二区三区婷婷月色| 国产精品久久久久9999吃药| 免费欧美在线视频| 色婷婷激情综合| 国产亚洲成年网址在线观看| 亚洲bdsm女犯bdsm网站| 99久久精品免费| 精品国产一区二区三区久久影院 | 国产成人在线视频免费播放| 欧美视频在线一区二区三区 | 日韩视频中午一区| 洋洋成人永久网站入口| 国产91精品一区二区麻豆亚洲| 91精品国产91久久久久久一区二区 | 美女精品自拍一二三四| 欧美亚洲国产一区二区三区va| 国产精品色呦呦| 国产综合色精品一区二区三区| 欧美亚洲一区二区在线| 一区免费观看视频| 国产精品911| 日韩欧美综合在线| 亚洲18影院在线观看| 色噜噜久久综合| 国产精品国产自产拍高清av| 精品一区二区三区在线视频| 91麻豆精品国产91久久久资源速度 | 亚洲国产精品一区二区www| 成人午夜视频在线| 国产视频不卡一区| 国产精品影视在线| 精品少妇一区二区三区免费观看| 日韩**一区毛片| 欧美猛男超大videosgay| 亚洲韩国一区二区三区| 色94色欧美sute亚洲线路二| 亚洲精品videosex极品| 色婷婷av一区二区| 一区二区三区在线视频观看58 | 国产麻豆精品在线| 精品久久久久一区| 激情综合网天天干| 久久综合资源网| 国产成人av电影在线观看| 久久欧美中文字幕| 国产乱人伦偷精品视频免下载 | 欧美一区午夜视频在线观看 | 97久久精品人人做人人爽| 欧美极品美女视频| www.一区二区| 一区二区三区在线免费观看| 色婷婷精品大视频在线蜜桃视频 | 亚洲一区二区美女| 欧美午夜精品一区| 日韩电影免费在线| 精品久久国产老人久久综合| 国产成人在线网站| 亚洲视频在线一区二区| 欧美伊人久久大香线蕉综合69 | av电影一区二区| 亚洲欧美日韩久久| 欧美日韩一区二区不卡| 免费欧美日韩国产三级电影| 久久综合成人精品亚洲另类欧美 | 欧美精品国产精品| 麻豆国产欧美日韩综合精品二区| 国产校园另类小说区| 波多野结衣一区二区三区| 亚洲精品一二三| 91精品国产日韩91久久久久久| 精品一区二区三区欧美| 国产精品免费免费| 欧美色图12p| 狠狠色伊人亚洲综合成人| 中文字幕+乱码+中文字幕一区| 91久久一区二区| 另类小说色综合网站| 国产精品国产三级国产三级人妇| 欧洲激情一区二区| 久久成人综合网| 亚洲欧美二区三区| 欧美成人vps| 93久久精品日日躁夜夜躁欧美| 丝袜美腿成人在线| 国产精品视频一二三区| 欧美男人的天堂一二区| 成人免费看片app下载| 午夜久久福利影院| 国产亚洲人成网站| 欧美视频中文一区二区三区在线观看| 国产老肥熟一区二区三区| 亚洲综合图片区| 久久久久久99久久久精品网站| 欧美视频一区在线观看| 国产一区激情在线| 亚欧色一区w666天堂| 欧美国产一区二区| 日韩一区二区在线观看视频| 一本久久a久久精品亚洲| 久久成人羞羞网站| 亚洲成人免费视| 亚洲视频你懂的| 久久久久久电影| 日韩视频免费观看高清完整版在线观看 | 国产一区欧美二区| 午夜精品久久久久影视|