我实现了jenes库提供的 Java 示例(教程 5:ObjectChromosome</a>)。我发现人群中的个体都是相同的(即没有发生随机化);
我在 OCProblem 类之后添加了以下代码ga.evolve();
来打印人口中的每个人:
ga.evolve();
Population pop= ga.getCurrentPopulation();
ArrayList population_test= pop.getIndividuals();
for(int n=0; n < population_test.size(); n++){
Individual<ObjectChromosome> individual=(Individual<ObjectChromosome>) population_test.get(n);
ObjectChromosome chrom = individual.getChromosome();
int i1 = (Integer)chrom.getValue(0);
int i2 = (Integer)chrom.getValue(1);
double i3= (double)chrom.getValue(2);
boolean i4= (boolean)chrom.getValue(3);
Color i5= (Color)chrom.getValue(4);
System.out.println("[ "+ i1+" , "+ i2+" , "+ i3+" , "+ i4+" , "+ i5+" ] ");
}
输出是令人震惊的个人是重复的!这是之前代码的输出
教程 5:找到最接近目标的颜色序列。[6,20,0.5623470035526044,false,(红色)] [6,20,0.5623470035526044,false,false,(红色)] [6,20,0.56234700355526044 )] [6,20,0.5623470035526044,false,(红色)] [6,20,0.5623470035526044,false,false,(red)] [6,20,0.5623470035526044 (红色) ] [ 6 ,20 , 0.5623470035526044 , 假 , (红色) ] [ 6 , 20 ,0.5623470035526044 , 假 , (红色) ]