我正在制作一个函数,允许我返回一个在整个人群中具有最佳适应度的向量,知道适应度是一个double
值,我的函数并不总是返回具有最大适应度向量的正确向量!
private Vector globalbest(Vector allpop){
allpop = allPopulation;
Vector global =null;
for(int i=0;i<allPopulation.size()-1;i++)
{
double m1 =(fitness((Vector) allpop.get(i+1)));
double m2 =(fitness((Vector) allpop.get(i)));
int i1 = Double.compare(m1,m2); // if i1 is positive then the first is greater
if( i1 > 0 ){
global = null;
global = (Vector) allpop.get(i+1);
}
}
return global;
}
希望你能找到错误!因为它真的让我很不自在,Thanx