variablebottom[j])+variablebottom[j];
}
current.tness=0;
current.value=0;
population.InsertAfter(population.FindIndex(i),current);//除了初始化使用
insertafter 外,其他的用 setat 命令。
}
}
void CMVSOGA::generatenextpopulation()//第三步,生成下一代。
{
//srand( (unsigned)time( NULL ) );
selectionoperator();
crossoveroperator();
mutationoperator();
}
//void CMVSOGA::evaluatepopulation() //第二步,评价个体,求最佳个体
//{
//calculateobjectvalue();
//calculatetnessvalue();//在此步中因该按适应度值进行排序.链表的排序.
//ndbestandworstindividual();
//}
void CMVSOGA:: calculateobjectvalue() //计算函数值,应该由外部函数实现。主要
因为目标函数很复杂。
{
int i,j;
double x[variablenum];
for (i=0; i<popsize; i++)
{
current=population.GetAt(population.FindIndex(i));
current.value=0;
//使用外部函数进行,在此只做结果的传递。
for (j=0;j<variablenum;j++)
{
x[j]=current.chromosome[j];
current.value=current.value+(j+1)*pow(x[j],4);
}
////使用外部函数进行,在此只做结果的传递。
population.SetAt(population.FindIndex(i),current);
}
}
void CMVSOGA::mutationoperator()//对于浮点数编码,变异算子的选择具有决定意
义。
//需要 guass 正态分布函数,生成方差为 sigma,均值为浮点数编码值 c。