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

📄 goldensectionsearch.txt

📁 此代码为公司生产用的黄金搜索算法
💻 TXT
字号:
void branislav_gold(void)
{
	short	a,b,c,s;
	double 	fa,fb,fc,fs;

	a = bran_x[0];
	b = bran_x[1];
	c = bran_x[2];
	fa = bran_y[0];
	fb = bran_y[1];
	fc = bran_y[2];
	
	// it is assumed here that the case when yy(y) is % less than both yy(x) and yy(z) never happens. 
	// this is the case of an inverted triangle.

	if (fc > fb) 
	{	s = bround(c - (1-golden_section)*(c-b));
		fs = branislav_measure(s);
		bran_x[0]=b;
		bran_x[1]=s;
		bran_x[2]=c;
		bran_y[0]=fb;
		bran_y[1]=fs;
		bran_y[2]=fc;
	}
	else if (fa > fb)               
	{	s = bround(a + (1-golden_section)*(b-a));
		fs = branislav_measure(s);
		bran_x[0]=a;
		bran_x[1]=s;
		bran_x[2]=b;
		bran_y[0]=fa;
		bran_y[1]=fs;
		bran_y[2]=fb;
	}
	else if ((b-a) > (c-b))           	 
	{	s = bround(b - (1-golden_section)*(b-a));
		fs = branislav_measure(s);
	    if (fs >= fb)
		{	bran_x[0]=a;
			bran_x[1]=s;
			bran_x[2]=b;
			bran_y[0]=fa;
			bran_y[1]=fs;
			bran_y[2]=fb;
	    }
		else
		{	bran_x[0]=s;
			bran_x[1]=b;
			bran_x[2]=c;
		 	bran_y[0]=fs;
			bran_y[1]=fb;
			bran_y[2]=fc;
	    }
	 }
	else
	{	s = bround(b + (1-golden_section)*(c-b));
		fs = branislav_measure(s);
	    if (fs >= fb)
		{	bran_x[0]=b;
			bran_x[1]=s;
			bran_x[2]=c;
		 	bran_y[0]=fb;
			bran_y[1]=fs;
			bran_y[2]=fc;
	    }
	    else
		{	bran_x[0]=a;
			bran_x[1]=b;
			bran_x[2]=s;
		 	bran_y[0]=fa;
			bran_y[1]=fb;
			bran_y[2]=fs;
	    }
	}
}

⌨️ 快捷键说明

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