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

📄 getw.c

📁 基于遗传算法的无功优化matlab实现方法软件包
💻 C
字号:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

void
getWeight(int *indi,int leng,int kk,int nn,int hh,int pp,
		double **w_ih,double **w_ho)
{

	int i,j,s;
	int tem;
	double max;

	/* check the individual vector has the correct dim */
	tem=((nn+1)*hh+(hh+1)*pp)*kk;
	if (tem!=leng)
	{
		printf("something wrong with the length in getW.c \n");
		exit(1);
	}

	/* get the maximum value KK bits can represent */
	max=0.0;
	for (i=0;i<kk;i++)
		max +=pow(2.0,i);

	/* calculate weight_ih */
	tem=0;
	for (i=0;i<hh;i++)
	{
		for (j=0;j<(nn+1);j++)
		{
			w_ih[i][j]=0.0;
			for (s=0;s<kk;s++)
			{
				w_ih[i][j]+=(pow(2.0,s))*indi[tem];
				tem++;
			}
			w_ih[i][j]=(((2*w_ih[i][j])/max)-1.0)*10.0;
			/* w_ih[i][j]=((2*w_ih[i][j])/max)-1.0; */
		}
	}

	/* calculate weight_ho */

	for (i=0;i<pp;i++)
	{
		for (j=0;j<(hh+1);j++)
		{
			w_ho[i][j]=0.0;
			for (s=0;s<kk;s++)
			{
				w_ho[i][j]+=(pow(2.0,s))*indi[tem];
				tem++;
			}
			w_ho[i][j]=((2*w_ho[i][j])/max-1)*10.0;
			
		}
	}
}


⌨️ 快捷键说明

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