我正在尝试编写一种方法来从我的人群中移除一条染色体。我写的方法如下。运行代码时出现越界错误。人口由ArrayList
. 该getChromosomeFitness
方法返回一个int
值分数。有人能发现我的错误吗?
void removeWorst()
{
int worst = population.get(0).getChromosomeFitness();
int temp = 0;
for(int i = 1; i < population.size(); i++)
{
if (population.get(i).getChromosomeFitness() < population.get(worst).getChromosomeFitness())
{
worst = population.get(i).getChromosomeFitness();
temp = i;
}
}
Chromosome x = population.get(temp);
population.remove(x);
}