資源簡(jiǎn)介
不精確一維搜索wolfe算法。C++環(huán)境編譯
代碼片段和文件信息
#include
#include“math.h“
using?namespace?std;
#define MIU???0.1
#define?SIGMA?0.5
void?wolfe()
{
double?x1[2]={00};
double?x2[2]={00};
int????pk[2]={10};
double?a=0b=10000000000alpha=1j=0;
x2[0]=x1[0]+alpha*pk[0];
x2[1]=x1[1]+alpha*pk[1];
double?fg2[2]g1[2];
f=100*(x2[1]-x2[0]*x2[0])*(x2[1]-x2[0]*x2[0])+(1-x2[0])*(1-x2[0]);
g1[0]=-400*(x1[1]-x1[0]*x1[0])*x1[0]-2*(1-x1[0]);
g1[1]=200*(x1[1]-x1[0]*x1[0]);
g2[0]=-400*(x2[1]-x2[0]*x2[0])*x2[0]-2*(1-x2[0]);
g2[1]=200*(x2[1]-x2[0]*x2[0]);
double?g2pk=g2[0]*pk[0]+g2[1]*pk[1];
double?g1pk=g1[0]*pk[0]+g1[1]*pk[1];
bool?conditionA=100*(x1[1]-x1[0]*x1[0])*(x1[1]-x1[0]*x1[0])+(1-x1[0])*(1-x1[0])-f>=-MIU*alpha*g2pk?true:false;
bool?conditionB=g2pk>=SIGMA*g1pk?true:false;
???cout<<‘j‘<<‘\t‘<<“alpha“<<‘\t‘<<“Xk+1“<<‘t‘<<‘f‘<<‘\n‘;
while(!conditionA||!conditionB)
{
if(!conditionA)
{
j=j+1;
b=alpha;
alpha=(a+alpha)/2;
x1[0]=0x1[1]=0;
????????????x2[0]=x1[0]+alpha*pk[0];
????????x2[1]=x1[1]+alpha*pk[1];
f=100*(x2[1]-x2[0]*x2[0])*(x2[1]-x2[0]*x2[0])+(1-x2[0])*(1-x2[0]);
g1[0]=-400*(x1[1]-x1[0]*x1[0])*x1[0]-2*(1-x1[0]);
????????g1[1]=20
評(píng)論
共有 條評(píng)論