}
}
// 防止种群退化 double temval;
int bestId = getOptimal(group, x, y, temval); if (temval < bestval) { } else { }
// 如果新种群的最优值变好,则更新最优值记录 bestC = group[bestId]; bestval = temval;
// 如果新种群的最优值变差,把较优的个体替换进新种群 group[bestId] = bestC;
// 获取最优值
getOptimal(group, x, y, val);
int main () { }
srand(time(0)); double x, y, maxval; GA(x, y, maxval);
cout << \函数在点(\ << fixed << setprecision(15) << x << \ << y << \system(\);
取得最大值:\ << maxval << endl;