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

📄 drawbp.c

📁 C语言编写的遗传算法程序
💻 C
字号:
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#define xbase 580
#define ybase 350
#define xstep 8	/* half distance between adjacent nodes */
#define ystep 40


void
drawbp(double **w_ih,double **w_ho,int n,int h,int p)
{

	int i,j;
	int xstart,ystart[3];

	int xmax;
	int tem;	/* color */

	int *in;
	int *hid;
	int *out;

	in=(int *)calloc(n,sizeof(int));
	hid=(int *)calloc(h,sizeof(int));
	out=(int *)calloc(p,sizeof(int));

	xmax=getmaxx();

	setcolor(WHITE);
	/* draw input nodes  */
	xstart=xbase-(n+1)*xstep;
	ystart[0]=ybase;

	for (i=0;i<n;i++)
	{
		in[i]=xstart+i*xstep*2;
		if (in[i]>xmax)
		{
			fprintf(stderr,"drawing BP out of screen\n");
			closegraph();
			exit(1);
		}
		circle(in[i],ystart[0],2);
	}

	/* draw hidden node */
	xstart=xbase-(h+1)*xstep;
	ystart[1]=ybase-ystep;

	for (i=0;i<h;i++)
	{
		hid[i]=xstart+i*xstep*2;
		if (hid[i]>xmax)
		{
			fprintf(stderr,"drawing BP out of screen\n");
			closegraph();
			exit(1);
		}
		circle(hid[i],ystart[1],2);
	}

	/* draw output node */
	xstart=xbase-(p+1)*xstep;
	ystart[2]=ybase-2*ystep;

	for (i=0;i<p;i++)
	{
		out[i]=xstart+i*xstep*2;
		if (out[i]>xmax)
		{
			fprintf(stderr,"drawing BP out of screen\n");
			closegraph();
			exit(1);
		}
		circle(out[i],ystart[2],2);
	}

	/* draw connections from iuput to hidden */
	for (i=0;i<n;i++)
	{
		for (j=0;j<h;j++)
		{
			tem=(int)((w_ih[j][i]+10.0)*15.0/20.0);
			setcolor(tem);
			line(in[i],ystart[0],hid[j],ystart[1]);
		}
	}

	/* draw line from hidden node to output node */
	for (i=0;i<h;i++)
	{
		for (j=0;j<p;j++)
		{
			tem=(int)((w_ho[j][i]+10.0)*15.0/20.0);
			setcolor(tem);
			line(hid[i],ystart[1],out[j],ystart[2]);
		}
	}





	/* free memory */
	free(in);
	free(hid);
	free(out);
}

⌨️ 快捷键说明

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