我正在尝试编写一种从我的种群中删除染色体的方法。我写的方法如下。运行代码时出现错误。总体用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);
}

最佳答案

你应该改变

if (population.get(i).getChromosomeFitness() < population.get(worst).getChromosomeFitness())




if (population.get(i).getChromosomeFitness() < worst)

关于java - 从种群中去除染色体?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10383956/

10-15 10:39