2017-11-09 3 views
0

나는 Jenetics 라이브러리를 사용하여 GA 문제를 해결하고 있습니다. 나는 다음과 같은 몇 가지 염색체를 사용하는 공식 예제를 확장하고있다 : 갖도록 eval 기능을Jenetics를 사용하여 하나의 염색체만으로 좋은 결과를 보여줍니다.

List<BitChromosome> arr = new ArrayList<>(); 
    arr.add(BitChromosome.of(16, 0.5)); 
    arr.add(BitChromosome.of(16, 0.5)); 
    arr.add(BitChromosome.of(16, 0.5)); 
    Factory<Genotype<BitGene>> gtf = Genotype.of(arr); 

을 변경 정확히 8 개 1과 8 0 :

private static int eval(Genotype<BitGene> gt) { 
    return 10 - Math.abs(gt.getChromosome() 
      .as(BitChromosome.class) 
      .bitCount()-8); 

다른 부분은 변경되지되었다 :

// 3.) Create the execution environment. 
    Engine<BitGene, Integer> engine = Engine 
      .builder(Test1::eval, gtf) 
      .build(); 

    // 4.) Start the execution (evolution) and 
    //  collect the result. 
    Genotype<BitGene> result = engine.stream() 
      .limit(100) 
      .collect(EvolutionResult.toBestGenotype()); 

나는이 평가 함수를 최대화하는 3 가지 염색체를 생산할 것으로 기대했지만 다음과 같이 나타납니다.

[01110010|00010111,01000000|00000100,10011101|01110110] 

여기서 알 수 있듯이 첫 번째 결과 만 조건을 충족합니다. 모든 염색체가 평가 함수를 최대화 할 수 있도록 어떻게이 예제를 확장 할 수 있습니까?

답변

1

정확하게 이것은 피트니스 기능을 살펴본 다음에 기대했던 것입니다. 피트니스를 계산하는 데 첫 번째 염색체 만 사용하고 있습니다. Genotype.getChromosome() 메서드는 첫 번째 염색체를 반환합니다. 그것은 Genotype.getChromosome(0)의 지름길입니다. 다른 두 염색체는 당신의 피트니스 기능에서 고려되지 않습니다.