Exemplo n.º 1
0
//按最佳适合度运行群粒算法
PARTICLE& PSO::Run(double fit)
{
	Initialize();
	double *opt_p=new double[Particle[0].Dim];//通讯用数组,最优点坐标
	double **opt_a=new double*[PNum];		  //通讯用数组,所有点坐标

	do
	{
		ParticleFly();
		if(Com)			//通讯函数存在,完成通讯
		{
			for(int k=0;k<Particle[0].Dim;k++)
			{
				opt_p[k]=Particle[GBestIndex].XBest[k];//拷贝最优点坐标
			}
			for(k=0;k<PNum;k++)
			{
				opt_a[k]=Particle[k].X;//指向所有点坐标
			}
			if(!Com(Particle[GBestIndex].FitBest,opt_p,opt_a,GBestIndex))
			{
				break;
			}
		}
	}while(Particle[GBestIndex].FitBest<fit);
	delete[] opt_p;
	delete[] opt_a;
	return Particle[GBestIndex];
}
Exemplo n.º 2
0
Expression *ComExp::optimize(int result)
{   Expression *e;

    e1 = e1->optimize(result);
    if (e1->isConst() == 1)
    {
	e = Com(type, e1);
    }
    else
	e = this;
    return e;
}